From ebc1d31422216affe9f6e8b32745a539c938790a Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Thu, 7 Nov 2024 19:54:05 -0500 Subject: [PATCH] ci: remove push redundant calls --- .../workflows/build-images-action/action.yml | 39 +++++++++++++++++++ .forgejo/workflows/build-images.yml | 27 +++---------- 2 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 .forgejo/workflows/build-images-action/action.yml diff --git a/.forgejo/workflows/build-images-action/action.yml b/.forgejo/workflows/build-images-action/action.yml new file mode 100644 index 0000000..bf3cbd2 --- /dev/null +++ b/.forgejo/workflows/build-images-action/action.yml @@ -0,0 +1,39 @@ +name: Build Container Images +inputs: + image-prefix: + required: true + registry-user: + required: true + registry-token: + required: true + registry-endpoint: + required: true +runs: + using: composite + steps: + - uses: actions/checkout@v4 + - name: Setup Spud + uses: https://forge.karnov.club/spadinastan/setup-spud-action@feat/install-spud-in-env + - name: Login to Registry + run: podman login -u ${{ inputs.registry-user }} -p ${{ inputs.registry-token }} ${{ inputs.registry-endpoint }} + - name: Set image metadata + id: image-metadata + run: | + echo "image-tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - name: Build images + run: | + spud build -d ./service.yml + podman image ls + - name: Push tagged images to registry + if: ${{ github.event_name == 'push' }} + run: | + for image in $(podman image ls --format {{.Repository}} | grep localhost/${{ inputs.image-prefix }}) + do + for tag in latest ${{ steps.image-metadata.outputs.image-tag }} ${{ github.ref_name }} + do + SRC=$image:latest + DEST=${{ vars.REGISTRY_ENDPOINT }}/$image:$tag + echo "Pushing $SRC to $DEST" + podman push $SRC $DEST + done + done diff --git a/.forgejo/workflows/build-images.yml b/.forgejo/workflows/build-images.yml index 2498124..5b6513d 100644 --- a/.forgejo/workflows/build-images.yml +++ b/.forgejo/workflows/build-images.yml @@ -18,27 +18,12 @@ jobs: runs-on: imagefactory-latest steps: - uses: actions/checkout@v4 - - name: Setup Spud - uses: https://forge.karnov.club/spadinastan/setup-spud-action@feat/install-spud-in-env - - name: Login to Registry - run: podman login -u ${{ secrets.REGISTRY_USER }} -p ${{ secrets.REGISTRY_TOKEN }} ${{ vars.REGISTRY_ENDPOINT }} - - name: Set image metadata - id: image-metadata - run: | - echo "image-tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - - name: Build images - run: | - spud build -d ./service.yml - podman image ls - - name: Push tagged images to registry - if: ${{ github.event_name == 'push' }} - run: | - podman push localhost/sesame/caddy:latest ${{ vars.REGISTRY_ENDPOINT }}/sesame/caddy:latest - podman push localhost/sesame/caddy:latest ${{ vars.REGISTRY_ENDPOINT }}/sesame/caddy:${{ steps.image-metadata.outputs.image-tag }} - podman push localhost/sesame/caddy:latest ${{ vars.REGISTRY_ENDPOINT }}/sesame/caddy:${{ github.ref_name }} - podman push localhost/sesame/promtail:latest ${{ vars.REGISTRY_ENDPOINT }}/sesame/promtail:latest - podman push localhost/sesame/promtail:latest ${{ vars.REGISTRY_ENDPOINT }}/sesame/promtail:${{ steps.image-metadata.outputs.image-tag }} - podman push localhost/sesame/promtail:latest ${{ vars.REGISTRY_ENDPOINT }}/sesame/promtail:${{ github.ref_name }} + - uses: ./.forgejo/workflows/build-images-action + with: + image-prefix: sesame + registry-user: ${{ secrets.REGISTRY_USER }} + registry-token: ${{ secrets.REGISTRY_TOKEN }} + registry-endpoint: ${{ vars.REGISTRY_ENDPOINT }} post-run: runs-on: imagefactory-latest needs: [build]