From 3d85c8b15ff71fb376c1c5072432b29f72909d4e Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 2 Mar 2024 14:47:21 -0700 Subject: [PATCH] Add reusable docker workflow. --- .gitea/workflows/docker.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .gitea/workflows/docker.yaml diff --git a/.gitea/workflows/docker.yaml b/.gitea/workflows/docker.yaml new file mode 100644 index 0000000..a73d0c4 --- /dev/null +++ b/.gitea/workflows/docker.yaml @@ -0,0 +1,34 @@ +# Reusable workflow, callable from other repos, to build and possibly push a +# container image. The container must contain a file /tag which contains the +# desired image tag. + +on: + workflow_call: + inputs: + image_name: + description: Image name, like docker.io/me/my_image + required: true + type: string + push: + description: True if the image should be pushed after building + required: false + default: false + type: boolean +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: build + run: docker build -t ${{ inputs.image_name }}:${{ github.run_number }} + - name: push + if: ${{ inputs.push }} + run: | + docker create --name ${{ inputs.image_name }}_${{ github.run_number }} ${{ inputs.image_name }}:${{ github.run_number }} + docker export -o /tmp/image ${{ inputs.image_name }}_${{ github.run_number }} + docker rm ${{ inputs.image_name }}_${{ github.run_number }} + docker rmi ${{ inputs.image_name }}:${{ github.run_number }} + tar -x -C /tmp -f /tmp/image tag + tag=$(cat /tmp/tag) + docker tag ${{ inputs.image_name }}:${{ github.run_number }} ${{ inputs.image_name }}:$tag + docker push ${{ inputs.image_name }}:$tag