From dc780cc32d7c2397e76704514e27a7585a1dd8d3 Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Sun, 3 Nov 2024 17:43:21 +0000 Subject: [PATCH 1/7] Add publish workflow --- .github/workflows/publish.yml | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..62b337675 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,65 @@ +name: Publish release images to Github Registry + +on: + release: + types: [released] + +env: + app-name: carrot + repo-owner: ${{ github.repository_owner }} + registry: ghcr.io + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + - name: Docker Login + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.registry }} + username: ${{github.actor}} + password: ${{secrets.GITHUB_TOKEN}} + + - name: Build and push frontend image + uses: docker/build-push-action@v2 + with: + context: .app/next-client-app + file: ./app/next-client-app/Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend:${{ github.event.release.tag_name }} + ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend:${{ github.sha }} + + - name: Build and push backend image + uses: docker/build-push-action@v2 + with: + context: ./app + file: ./app/Dockerfile.deploy + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend:${{ github.event.release.tag_name }} + ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend:${{ github.sha }} + + - name: Build and push workers image + uses: docker/build-push-action@v2 + with: + context: .app/workers + file: ./app/workers/Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/workers:${{ github.event.release.tag_name }} + ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/workers:${{ github.sha }} From fd65c452ae7c0c8146fabfba6a94219add42e80a Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Sun, 3 Nov 2024 17:52:19 +0000 Subject: [PATCH 2/7] Test publish --- .github/workflows/publish.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 62b337675..c761b7cc1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,8 +1,13 @@ name: Publish release images to Github Registry +# on: +# release: +# types: [released] on: - release: - types: [released] + push: + branches: + - feat/863/add-release-workflow + env: app-name: carrot @@ -39,7 +44,6 @@ jobs: push: true platforms: linux/amd64,linux/arm64 tags: | - ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend:${{ github.event.release.tag_name }} ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend:${{ github.sha }} - name: Build and push backend image @@ -50,7 +54,6 @@ jobs: push: true platforms: linux/amd64,linux/arm64 tags: | - ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend:${{ github.event.release.tag_name }} ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend:${{ github.sha }} - name: Build and push workers image @@ -61,5 +64,4 @@ jobs: push: true platforms: linux/amd64,linux/arm64 tags: | - ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/workers:${{ github.event.release.tag_name }} ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/workers:${{ github.sha }} From 6dd56da4700649833b402436dc8bdcec4af211c0 Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Sun, 3 Nov 2024 18:23:04 +0000 Subject: [PATCH 3/7] Fix lowercase image bug --- .github/workflows/publish.yml | 44 ++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c761b7cc1..5ad7d4363 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,35 +33,53 @@ jobs: uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 with: registry: ${{ env.registry }} - username: ${{github.actor}} - password: ${{secrets.GITHUB_TOKEN}} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Tag and build frontend + - name: Extract frontend Docker metadata + id: frontend_meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend - name: Build and push frontend image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5.3.0 with: - context: .app/next-client-app + context: ./app/next-client-app file: ./app/next-client-app/Dockerfile push: true platforms: linux/amd64,linux/arm64 - tags: | - ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend:${{ github.sha }} + tags: ${{ steps.frontend_meta.outputs.tags }} + + # Tag and for backend + - name: Extract backend Docker metadata + id: backend_meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend - name: Build and push backend image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5.3.0 with: context: ./app file: ./app/Dockerfile.deploy push: true platforms: linux/amd64,linux/arm64 - tags: | - ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend:${{ github.sha }} + tags: ${{ steps.backend_meta.outputs.tags }} + + # Tag and for workers + - name: Extract workers Docker metadata + id: workers_meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/workers - name: Build and push workers image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5.3.0 with: - context: .app/workers + context: ./app/workers file: ./app/workers/Dockerfile push: true platforms: linux/amd64,linux/arm64 - tags: | - ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/workers:${{ github.sha }} + tags: ${{ steps.workers_meta.outputs.tags }} From 404284c8b8e7fe98d3bc9f0ff08ac92b58da4346 Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Sun, 3 Nov 2024 18:39:51 +0000 Subject: [PATCH 4/7] Fix: Remove context --- .github/workflows/publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5ad7d4363..636ee7a65 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -62,7 +62,6 @@ jobs: - name: Build and push backend image uses: docker/build-push-action@v5.3.0 with: - context: ./app file: ./app/Dockerfile.deploy push: true platforms: linux/amd64,linux/arm64 From 0cd8f9187fa4aaa903bc5d4ba0564bef837ae05a Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Sun, 3 Nov 2024 19:05:34 +0000 Subject: [PATCH 5/7] Test workers build/push --- .github/workflows/publish.yml | 55 +++++++++++++++++------------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 636ee7a65..7c10d89a7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -36,36 +36,36 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # Tag and build frontend - - name: Extract frontend Docker metadata - id: frontend_meta - uses: docker/metadata-action@v5.5.1 - with: - images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend + # # Tag and build frontend + # - name: Extract frontend Docker metadata + # id: frontend_meta + # uses: docker/metadata-action@v5.5.1 + # with: + # images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend - - name: Build and push frontend image - uses: docker/build-push-action@v5.3.0 - with: - context: ./app/next-client-app - file: ./app/next-client-app/Dockerfile - push: true - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.frontend_meta.outputs.tags }} + # - name: Build and push frontend image + # uses: docker/build-push-action@v5.3.0 + # with: + # context: ./app/next-client-app + # file: ./app/next-client-app/Dockerfile + # push: true + # platforms: linux/amd64,linux/arm64 + # tags: ${{ steps.frontend_meta.outputs.tags }} - # Tag and for backend - - name: Extract backend Docker metadata - id: backend_meta - uses: docker/metadata-action@v5.5.1 - with: - images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend + # # Tag and for backend + # - name: Extract backend Docker metadata + # id: backend_meta + # uses: docker/metadata-action@v5.5.1 + # with: + # images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend - - name: Build and push backend image - uses: docker/build-push-action@v5.3.0 - with: - file: ./app/Dockerfile.deploy - push: true - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.backend_meta.outputs.tags }} + # - name: Build and push backend image + # uses: docker/build-push-action@v5.3.0 + # with: + # file: ./app/Dockerfile.deploy + # push: true + # platforms: linux/amd64,linux/arm64 + # tags: ${{ steps.backend_meta.outputs.tags }} # Tag and for workers - name: Extract workers Docker metadata @@ -77,7 +77,6 @@ jobs: - name: Build and push workers image uses: docker/build-push-action@v5.3.0 with: - context: ./app/workers file: ./app/workers/Dockerfile push: true platforms: linux/amd64,linux/arm64 From ed16e56e39180ccbdaec503242dcfa6eea9caa3b Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Sun, 3 Nov 2024 19:07:32 +0000 Subject: [PATCH 6/7] fix: Context update --- .github/workflows/publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7c10d89a7..3ac4ae634 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -77,6 +77,7 @@ jobs: - name: Build and push workers image uses: docker/build-push-action@v5.3.0 with: + context: ./app file: ./app/workers/Dockerfile push: true platforms: linux/amd64,linux/arm64 From 3576e0101fe7e70c75911b9b513f07d672f8960c Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Sun, 3 Nov 2024 19:13:48 +0000 Subject: [PATCH 7/7] Readd release tags --- .github/workflows/publish.yml | 78 ++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3ac4ae634..544e77ada 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,13 +1,8 @@ name: Publish release images to Github Registry -# on: -# release: -# types: [released] on: - push: - branches: - - feat/863/add-release-workflow - + release: + types: [released] env: app-name: carrot @@ -36,36 +31,47 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # # Tag and build frontend - # - name: Extract frontend Docker metadata - # id: frontend_meta - # uses: docker/metadata-action@v5.5.1 - # with: - # images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend + - name: Set timestamp env var + run: echo "RUN_TIMESTAMP=$(TZ="Etc/UTC" date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + + # Tag and build frontend + - name: Extract frontend Docker metadata + id: frontend_meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/frontend + tags: | + ${{ github.event.release.tag_name }} + ${{ github.sha }} + ${{ env.RUN_TIMESTAMP }} - # - name: Build and push frontend image - # uses: docker/build-push-action@v5.3.0 - # with: - # context: ./app/next-client-app - # file: ./app/next-client-app/Dockerfile - # push: true - # platforms: linux/amd64,linux/arm64 - # tags: ${{ steps.frontend_meta.outputs.tags }} + - name: Build and push frontend image + uses: docker/build-push-action@v5.3.0 + with: + context: ./app/next-client-app + file: ./app/next-client-app/Dockerfile + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.frontend_meta.outputs.tags }} - # # Tag and for backend - # - name: Extract backend Docker metadata - # id: backend_meta - # uses: docker/metadata-action@v5.5.1 - # with: - # images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend + # Tag and for backend + - name: Extract backend Docker metadata + id: backend_meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/backend + tags: | + ${{ github.event.release.tag_name }} + ${{ github.sha }} + ${{ env.RUN_TIMESTAMP }} - # - name: Build and push backend image - # uses: docker/build-push-action@v5.3.0 - # with: - # file: ./app/Dockerfile.deploy - # push: true - # platforms: linux/amd64,linux/arm64 - # tags: ${{ steps.backend_meta.outputs.tags }} + - name: Build and push backend image + uses: docker/build-push-action@v5.3.0 + with: + file: ./app/Dockerfile.deploy + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.backend_meta.outputs.tags }} # Tag and for workers - name: Extract workers Docker metadata @@ -73,6 +79,10 @@ jobs: uses: docker/metadata-action@v5.5.1 with: images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.app-name }}/workers + tags: | + ${{ github.event.release.tag_name }} + ${{ github.sha }} + ${{ env.RUN_TIMESTAMP }} - name: Build and push workers image uses: docker/build-push-action@v5.3.0