From 7b477dc65ec9253cd8b3fdbc0c012ae5eee6d528 Mon Sep 17 00:00:00 2001 From: Kamil Krzywicki Date: Wed, 14 Feb 2024 07:57:52 +0100 Subject: [PATCH] one pipelien for forks and main repo --- .github/workflows/push.yaml | 44 +++++++------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index db42a48..2c9b6d8 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -27,6 +27,9 @@ jobs: permissions: contents: read packages: write + env: + REGISTRY: "${{ github.repository == 'uswitch/vault-creds' && 'quay.io' || 'ghcr.io' }}" + IMAGE_NAME: "${{ github.repository == 'uswitch/vault-creds' && 'uswitch/vault-creds' || github.repository }}" #if: github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/v') needs: [test, build] runs-on: ubuntu-latest @@ -36,25 +39,22 @@ jobs: - name: Setup Docker buildx uses: docker/setup-buildx-action@v3 - - name: Login to Quay.io - if: github.repository == 'uswitch/vault-creds' + - name: Login to registry uses: docker/login-action@v3 with: - registry: quay.io - username: ${{ secrets.QUAY_USERNAME }} - password: ${{ secrets.QUAY_PASSWORD }} + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY == 'quay.io' && secrets.QUAY_USERNAME || github.actor }} + password: ${{ env.REGISTRY == 'quay.io' && secrets.QUAY_PASSWORD || secrets.GITHUB_TOKEN }} - id: meta - if: github.repository == 'uswitch/vault-creds' uses: docker/metadata-action@v4 with: - images: quay.io/uswitch/vault-creds + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=semver,pattern=v{{version}} type=sha,prefix=,format=long, - uses: docker/build-push-action@v4 - if: github.repository == 'uswitch/vault-creds' with: context: . labels: ${{ steps.meta.outputs.labels }} @@ -62,31 +62,3 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} build-args: LDFLAGS=-X main.SHA=${{ github.sha }} - - - name: Log into registry ghcr.io - if: github.event_name != 'pull_request' - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - id: meta-forks - if: github.repository != 'uswitch/vault-creds' - uses: docker/metadata-action@v4 - with: - images: ghcr.io/${{ github.repository }} - tags: | - type=semver,pattern=v{{version}} - type=sha,prefix=,format=long, - - - uses: docker/build-push-action@v4 - if: github.repository != 'uswitch/vault-creds' - with: - context: . - labels: ${{ steps.meta-forks.outputs.labels }} - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta-forks.outputs.tags }} - build-args: LDFLAGS=-X main.SHA=${{ github.sha }} -