Files
unbound-docker/.github/workflows/docker.yml
T
2022-07-30 10:42:11 -04:00

146 lines
4.0 KiB
YAML

name: docker
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: false
DOCKERHUB_PASSWORD:
required: false
inputs:
images:
type: string
required: true
working_directory:
type: string
required: false
context:
type: string
required: false
dockerfile:
type: string
required: false
target:
type: string
required: false
cache_from:
type: string
required: false
platforms:
type: string
required: false
publish:
type: boolean
required: false
dockerhub_description_repo:
type: string
required: false
jobs:
build:
runs-on: ubuntu-latest
services:
registry:
image: registry:2.7.1
ports:
- 5000:5000
defaults:
run:
working-directory: ${{ inputs.working_directory || '.' }}
env:
TEST_TAG: localhost:5000/sut:latest
PLATFORMS: ${{ inputs.platforms || 'linux/amd64' }}
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 }}
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: ${{ env.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.TEST_TAG }}
load: false
push: true
- id: test
run: |
for platform in $PLATFORMS ; do
docker pull --platform=$platform ${{ env.TEST_TAG }}
docker inspect ${{ env.TEST_TAG }}
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: ${{ inputs.publish != false && contains(inputs.images, 'ghcr.io') }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@v2
if: ${{ inputs.publish != false && 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.TEST_TAG }}
dst: |
${{ steps.meta.outputs.tags }}
- uses: peter-evans/dockerhub-description@v3
if: ${{ inputs.publish != false && inputs.dockerhub_description_repo != '' && (github.event_name != 'pull_request' || (github.event.action == 'closed' && github.event.pull_request.merged == true)) }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ inputs.dockerhub_description_repo }}