Add reusable docker workflow.
This commit is contained in:
34
.gitea/workflows/docker.yaml
Normal file
34
.gitea/workflows/docker.yaml
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user