37 lines
1.3 KiB
YAML
37 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: string # really boolean
|
|
jobs:
|
|
build:
|
|
runs-on: cjyar-24
|
|
steps:
|
|
- name: docker login
|
|
if: ${{ inputs.push == 'true' }}
|
|
run: docker login -u cjyar -p "${{ secrets.DOCKER_TOKEN }}"
|
|
- uses: actions/checkout@v4
|
|
- name: build
|
|
run: docker build -t ${{ inputs.image_name }}:${{ gitea.run_number }} .
|
|
- name: push
|
|
if: ${{ inputs.push == 'true' }}
|
|
run: |
|
|
docker create --name run_${{ gitea.run_number }} ${{ inputs.image_name }}:${{ gitea.run_number }}
|
|
docker export -o /tmp/image run_${{ gitea.run_number }}
|
|
docker rm run_${{ gitea.run_number }}
|
|
tar -x -C /tmp -f /tmp/image tag
|
|
tag=$(cat /tmp/tag)
|
|
docker tag ${{ inputs.image_name }}:${{ gitea.run_number }} ${{ inputs.image_name }}:$tag
|
|
docker push ${{ inputs.image_name }}:$tag
|