35 lines
1.3 KiB
YAML
35 lines
1.3 KiB
YAML
# 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: cjyar-24
|
|
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
|