From ad14947957dd8a61e34fe09cba0e26c5ef2d7017 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Thu, 7 Nov 2024 22:23:43 -0500 Subject: [PATCH] feat: initial push --- README.md | 21 +++++++++++++++++++++ action.yml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 README.md create mode 100644 action.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..8c6cb93 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Push Container Images Forgejo Action + +An action that handles pushing multiple images and tags to a given registry. + +## Interface + +```yml +inputs: + image-prefix: + description: Image name prefix to identify images to push. + required: true + registry-user: + description: Username for registry authentication. + required: true + registry-token: + description: Token/password for registry authentication. + required: true + registry-endpoint: + description: Registry endpoint to authenticate with and push to. + required: true +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..65e9075 --- /dev/null +++ b/action.yml @@ -0,0 +1,35 @@ +name: Push Container Images +inputs: + image-prefix: + description: Image name prefix to identify images to push. + required: true + registry-user: + description: Username for registry authentication. + required: true + registry-token: + description: Token/password for registry authentication. + required: true + registry-endpoint: + description: Registry endpoint to authenticate with and push to. + required: true +runs: + using: composite + steps: + - 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: Push tagged images to registry + 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=${{ inputs.registry-endpoint }}/$image:$tag + echo "Pushing $SRC to $DEST" + podman push $SRC $DEST + done + done