From 3fb975d17d28e025ad703aaf936c0299508d6638 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 15 Oct 2024 13:56:57 +0200 Subject: [PATCH] Add Github workflow to push to github packages for docker --- .github/workflows/deploy.yml | 19 ++++++++++++++----- .github/workflows/release.yml | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 763fe0c9..5f47db18 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,11 +23,11 @@ jobs: restore-keys: | ${{ runner.os }}-buildx- - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push + - name: Build and push uses: docker/build-push-action@v2 with: context: . @@ -36,7 +36,16 @@ jobs: tags: ${{ github.repository }}:latest cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache - + - name: Push to GitHub Packages + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository }}:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + deploy: needs: [test, build] runs-on: ubuntu-latest @@ -54,7 +63,7 @@ jobs: echo "::set-output name=TAG::$(git tag --points-at HEAD)" echo "::set-output name=GIT_SHA::$(git rev-parse HEAD)" echo "::set-output name=GIT_SHA_SHORT::$(git rev-parse --short HEAD)" - echo "::set-output name=MESSAGE::$(git log --format=%B -n 1 ${{ github.event.after }})" + echo "::set-output name=MESSAGE::$(git log --format=%B -n 1 ${{ github.event.after }})" id: extract_variables - name: Checkout terraform config repo @@ -73,7 +82,7 @@ jobs: tar -xzvf dockerize-linux-amd64-v0.6.0.tar.gz rm dockerize-linux-amd64-v0.6.0.tar.gz ./dockerize -template stage/services/profiles/_volpino.auto.tfvars.tmpl:stage/services/profiles/_volpino.auto.tfvars - + git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add stage/services/profiles/_volpino.auto.tfvars diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 567e88fa..b5d4ac8c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: restore-keys: | ${{ runner.os }}-buildx- - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} @@ -30,7 +30,7 @@ jobs: run: | echo "::set-output name=GIT_TAG::$(git tag --points-at HEAD)" id: set_git_vars - - name: Build and push + - name: Build and push uses: docker/build-push-action@v2 with: context: . @@ -39,7 +39,16 @@ jobs: tags: ${{ github.repository }}:${{ steps.set_git_vars.outputs.GIT_TAG }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache - + - name: Push to GitHub Packages + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ghcr.io/${{ github.repository }}:${{ steps.set_git_vars.outputs.GIT_TAG }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + deploy: needs: [test, build] runs-on: ubuntu-latest @@ -55,7 +64,7 @@ jobs: echo "::set-output name=BRANCH::$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" echo "::set-output name=TAG::$(git tag --points-at HEAD)" echo "::set-output name=GIT_SHA::$(git rev-parse HEAD)" - echo "::set-output name=GIT_SHA_SHORT::$(git rev-parse --short HEAD)" + echo "::set-output name=GIT_SHA_SHORT::$(git rev-parse --short HEAD)" id: extract_variables - name: Checkout terraform config repo @@ -74,7 +83,7 @@ jobs: tar -xzvf dockerize-linux-amd64-v0.6.0.tar.gz rm dockerize-linux-amd64-v0.6.0.tar.gz ./dockerize -template prod-eu-west/services/profiles/_volpino.auto.tfvars.tmpl:prod-eu-west/services/profiles/_volpino.auto.tfvars - + git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git add prod-eu-west/services/profiles/_volpino.auto.tfvars