61 lines
1.6 KiB
YAML
61 lines
1.6 KiB
YAML
name: Reusable Docker Build
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
image_name:
|
|
required: true
|
|
type: string
|
|
context:
|
|
required: false
|
|
type: string
|
|
default: "."
|
|
dockerfile:
|
|
required: false
|
|
type: string
|
|
default: "./Dockerfile"
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: docker
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
driver: docker
|
|
|
|
- name: Configure registry auth
|
|
if: github.event_name != 'pull_request'
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
ACTOR: ${{ github.actor }}
|
|
run: |
|
|
mkdir -p ~/.docker
|
|
AUTH=$(printf '%s:%s' "$ACTOR" "$TOKEN" | base64 -w0)
|
|
printf '{"auths":{"git.vodyanoysh.ru":{"auth":"%s"}}}' "$AUTH" > ~/.docker/config.json
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: git.vodyanoysh.ru/${{ inputs.image_name }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=semver,pattern={{version}}
|
|
type=sha,prefix=sha-
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ${{ inputs.context }}
|
|
file: ${{ inputs.dockerfile }}
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|