Skip to content

Commit

Permalink
ci: build images with caching with docker buildx
Browse files Browse the repository at this point in the history
Caching should work for this for GitHub Actions. Also, we're only
building the images for projects that have actually changed (with the
help of `nx`).

https://docs.docker.com/build/cache/backends/gha/

Related to #83
  • Loading branch information
JoosepAlviste committed Jan 6, 2024
1 parent 14d1a27 commit 4d08478
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3

- name: Setup
run: |
cp .env.example .env
- name: Build containers
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
sed -i.bak -e "s/VITE_API_HOST=.*/VITE_API_HOST=api.serieslist.joosep.xyz/" .env
sed -i.bak -e "s/VITE_API_URL=.*/VITE_API_URL=https:\/\/\$VITE_API_HOST/" .env
docker compose -f docker-compose.production.yml pull webapp api || true
docker compose -f docker-compose.production.yml build webapp api
docker compose -f docker-compose.production.yml push
sed -i.bak -e "s/VITE_API_URL=.*/VITE_API_URL=https:\/\/api.serieslist.joosep.xyz/" .env
pnpm exec nx affected -t build:docker
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
Expand Down
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"scripts": {
"build": "NODE_ENV=production rimraf dist && tsx bin/build.ts",
"build:docker": "(cd ../.. && docker buildx build --push --cache-to type=gha,mode=max,scope=webapp --cache-from type=gha,scope=webapp -t ghcr.io/joosepalviste/serieslist-api:latest -f apps/api/Dockerfile --target production .)",
"clear-test-db": "dotenv -e ../../.env.test tsx bin/clearDatabase.ts",
"codegen": "DOTENV_CONFIG_PATH='../../.env' graphql-codegen-esm -r dotenv/config",
"codegen:db": "tsx bin/kyselyCodegen.ts && eslint --fix src/generated/db.ts",
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"scripts": {
"build": "rimraf dist && vite build && pnpm build:server",
"build:docker": "(cd ../.. && docker buildx build --push --cache-to type=gha,mode=max,scope=webapp --cache-from type=gha,scope=webapp -t ghcr.io/joosepalviste/serieslist-webapp:latest -f apps/webapp/Dockerfile --target production --build-arg=\"VITE_APP_PORT=$VITE_APP_PORT\" --build-arg=\"VITE_API_URL=$VITE_API_URL\" --build-arg=\"VITE_API_INTERNAL_URL=$VITE_API_INTERNAL_URL\" .)",
"build:server": "tsx bin/build.ts && resolve-tspaths --out dist/prodServer",
"codegen": "graphql-codegen",
"lint": "eslint src && madge --circular --extensions ts,tsx ./src",
Expand Down
4 changes: 4 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"cache": true,
"inputs": ["production", "^production"]
},
"build:docker": {
"cache": true,
"defaultConfiguration": "docker"
},
"tsc": {
"cache": true
},
Expand Down

0 comments on commit 4d08478

Please sign in to comment.