mirror of
https://github.com/klutchell/unbound-docker.git
synced 2026-10-22 16:03:30 +00:00
162 lines
4.9 KiB
YAML
162 lines
4.9 KiB
YAML
name: docker
|
|
|
|
on:
|
|
workflow_call:
|
|
secrets:
|
|
DOCKERHUB_USERNAME:
|
|
required: false
|
|
DOCKERHUB_TOKEN:
|
|
required: false
|
|
inputs:
|
|
working_directory:
|
|
description: 'Github actions working directory'
|
|
type: string
|
|
required: false
|
|
default: '.'
|
|
images:
|
|
description: 'Newline separated list of images (without tags) to push, default is no push'
|
|
type: string
|
|
required: false
|
|
cache_from:
|
|
description: 'Newline separated list of additional external cache sources'
|
|
type: string
|
|
required: false
|
|
platforms:
|
|
description: 'Newline separated list of target platforms, default is linux/amd64'
|
|
type: string
|
|
required: false
|
|
default: 'linux/amd64'
|
|
context:
|
|
description: 'Docker build context directory, default is ./'
|
|
type: string
|
|
required: false
|
|
dockerfile:
|
|
description: 'Path to the Dockerfile relative to the context, default is ./Dockerfile'
|
|
type: string
|
|
required: false
|
|
target:
|
|
description: 'Sets the target stage to build'
|
|
type: string
|
|
required: false
|
|
dockerhub_description_repo:
|
|
type: string
|
|
required: false
|
|
|
|
jobs:
|
|
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
services:
|
|
registry:
|
|
image: registry:2.8.1
|
|
ports:
|
|
- 5000:5000
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: ${{ inputs.working_directory }}
|
|
shell: bash
|
|
|
|
env:
|
|
LOCAL_IMAGE: localhost:5000/sut
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
- uses: docker/setup-qemu-action@v2
|
|
|
|
- id: buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
with:
|
|
driver-opts: network=host
|
|
install: true
|
|
|
|
- uses: actions/cache@v3
|
|
with:
|
|
path: /tmp/buildkit-cache/buildkit-state.tar
|
|
key: ${{ runner.os }}-buildkit-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildkit-
|
|
|
|
- uses: dashevo/gh-action-cache-buildkit-state@v1
|
|
with:
|
|
builder: buildx_buildkit_${{ steps.buildx.outputs.name }}0
|
|
cache-path: /tmp/buildkit-cache
|
|
cache-max-size: 5g
|
|
|
|
- id: meta
|
|
uses: docker/metadata-action@v4
|
|
with:
|
|
images: ${{ inputs.images || env.LOCAL_IMAGE }}
|
|
tags: |
|
|
type=ref,event=tag
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=sha
|
|
type=semver,pattern={{version}}
|
|
|
|
- id: build
|
|
uses: docker/build-push-action@v3
|
|
with:
|
|
platforms: ${{ inputs.platforms }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-to: type=gha,mode=max
|
|
cache-from: |
|
|
type=gha
|
|
${{ steps.meta.outputs.tags }}
|
|
${{ inputs.cache_from }}
|
|
context: ${{ inputs.context }}
|
|
file: ${{ inputs.dockerfile }}
|
|
target: ${{ inputs.target }}
|
|
tags: ${{ env.LOCAL_IMAGE }}:latest
|
|
load: false
|
|
push: true
|
|
|
|
- shell: bash
|
|
env:
|
|
PLATFORMS: ${{ inputs.platforms }}
|
|
TAGS: ${{ steps.meta.outputs.tags }}
|
|
run: |
|
|
for platform in $PLATFORMS
|
|
do
|
|
docker pull --platform=$platform ${{ env.LOCAL_IMAGE }}:latest
|
|
docker tag ${{ env.LOCAL_IMAGE }}:latest sut:latest
|
|
docker tag ${{ env.LOCAL_IMAGE }}:latest ${{ github.repository }}:latest
|
|
for tag in $TAGS
|
|
do
|
|
docker tag ${{ env.LOCAL_IMAGE }}:latest ${tag}
|
|
done
|
|
docker inspect ${{ env.LOCAL_IMAGE }}:latest
|
|
docker compose -f docker-compose.yml -f docker-compose.test.yml up --no-build --exit-code-from sut
|
|
done
|
|
|
|
- uses: docker/login-action@v2
|
|
if: ${{ github.actor == github.repository_owner && contains(inputs.images, 'ghcr.io') }}
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- uses: docker/login-action@v2
|
|
if: ${{ github.actor == github.repository_owner && contains(inputs.images, 'docker.io') }}
|
|
with:
|
|
registry: docker.io
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- uses: akhilerm/tag-push-action@v2.0.0
|
|
if: github.actor == github.repository_owner
|
|
with:
|
|
src: ${{ env.LOCAL_IMAGE }}:latest
|
|
dst: |
|
|
${{ steps.meta.outputs.tags }}
|
|
|
|
- uses: peter-evans/dockerhub-description@v3
|
|
if: ${{ github.actor == github.repository_owner && inputs.dockerhub_description_repo != '' && github.event_name == 'push' && github.ref_name == github.event.repository.default_branch }}
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
repository: ${{ inputs.dockerhub_description_repo }}
|