81 lines
2.3 KiB
YAML
81 lines
2.3 KiB
YAML
---
|
|
name: Docker Build
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
dockerfile:
|
|
description: 'Path to Dockerfile'
|
|
required: true
|
|
type: string
|
|
context:
|
|
description: 'Build context'
|
|
default: '.'
|
|
required: false
|
|
image:
|
|
description: 'Where to store the built image'
|
|
required: true
|
|
type: string
|
|
submodules:
|
|
description: 'Submodules pull strategy'
|
|
default: 'recursive'
|
|
required: false
|
|
type: string
|
|
user:
|
|
description: 'Git user for checkout'
|
|
default: 'automation'
|
|
required: false
|
|
type: string
|
|
token:
|
|
description: 'Git token for checkout'
|
|
required: true
|
|
type: string
|
|
outputs:
|
|
tag:
|
|
description: 'Built image tag'
|
|
value: ${{ steps.build.outputs.tag }}
|
|
image:
|
|
description: 'Built image name'
|
|
value: ${{ steps.build.outputs.image }}
|
|
sha:
|
|
description: 'Git SHA used for the build'
|
|
value: ${{ steps.build.outputs.sha }}
|
|
jobs:
|
|
build:
|
|
name: Build Docker Image
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v5
|
|
with:
|
|
submodules: ${{ inputs.submodules }}
|
|
token: "${{ inputs.token }}"
|
|
- name: Gather registry metadata
|
|
uses: docker/metadata-action@v5
|
|
id: meta
|
|
with:
|
|
images: ${{ inputs.image }}
|
|
tags: |
|
|
type=sha,prefix=,suffix=,format=long
|
|
- name: Registry login
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: git.etc.nu
|
|
username: "${{ inputs.user }}"
|
|
password: "${{ inputs.token }}"
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
- name: Build and push image
|
|
uses: docker/build-push-action@v6
|
|
id: build
|
|
with:
|
|
file: ${{ inputs.dockerfile }}
|
|
context: ${{ inputs.context }}
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=registry,ref=${{ inputs.image }}/cache
|
|
cache-to: type=registry,ref=${{ inputs.image }}/cache,mode=max
|
|
outputs:
|
|
tag: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
|
|
image: ${{ inputs.image }}
|
|
sha: ${{ gitea.sha }}
|