emqx/.github/workflows/build_and_push_docker_images.yaml
2023-08-06 14:16:56 +02:00

174 lines
4.6 KiB
YAML

name: Build and push docker images
concurrency:
group: docker-build-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_call:
inputs:
profile:
required: true
type: string
edition:
required: true
type: string
version:
required: true
type: string
latest:
required: true
type: string
publish:
required: true
type: string
otp_vsn:
required: true
type: string
elixir_vsn:
required: true
type: string
runner:
required: true
type: string
builder_vsn:
required: true
type: string
workflow_dispatch:
inputs:
ref:
required: false
version:
required: true
type: string
profile:
required: false
type: string
default: 'emqx'
edition:
required: false
type: string
default: 'Opensource'
latest:
required: false
type: boolean
default: false
publish:
required: false
type: boolean
default: false
otp_vsn:
required: false
type: string
default: '25.3.2-1'
elixir_vsn:
required: false
type: string
default: '1.14.5'
runner:
required: false
type: string
default: 'ubuntu-22.04'
builder_vsn:
required: false
type: string
default: '5.1-3'
jobs:
docker:
runs-on: ${{ inputs.runner }}
strategy:
fail-fast: false
matrix:
profile:
- ${{ inputs.profile }}
registry:
- 'docker.io'
- 'public.ecr.aws'
os:
- [debian11, "debian:11-slim", "deploy/docker/Dockerfile"]
builder:
- ${{ inputs.builder_vsn }}
otp:
- ${{ inputs.otp_vsn }}
elixir:
- 'no_elixir'
- ${{ inputs.elixir_vsn }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.ref }}
fetch-depth: 0
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Login to hub.docker.com
uses: docker/login-action@v2
if: matrix.registry == 'docker.io'
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Login to AWS ECR
uses: docker/login-action@v2
if: matrix.registry == 'public.ecr.aws'
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ecr: true
- name: prepare for docker/metadata-action
id: pre-meta
shell: bash
run: |
extra_labels=
img_suffix=
if [ "${{ matrix.elixir }}" != 'no_elixir' ]; then
img_suffix="-elixir"
extra_labels="org.opencontainers.image.elixir.version=${{ matrix.elixir }}"
fi
extra_deps=
if [[ "${{ matrix.profile }}" = *enterprise* ]]; then
extra_deps='libsasl2-2,libsasl2-modules-gssapi-mit'
fi
echo "img_suffix=$img_suffix" >> $GITHUB_OUTPUT
echo "extra_labels=$extra_labels" >> $GITHUB_OUTPUT
echo "extra_deps=$extra_deps" >> $GITHUB_OUTPUT
- uses: docker/metadata-action@v4
id: meta
with:
images: |
${{ matrix.registry }}/${{ github.repository_owner }}/${{ matrix.profile }}
flavor: |
latest=${{ matrix.elixir == 'no_elixir' }}
suffix=${{ steps.pre-meta.outputs.img_suffix }}
tags: |
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.version }}
type=semver,pattern={{version}},value=${{ inputs.version }}
type=raw,value=${{ inputs.version }}
type=raw,value=latest,enable=${{ inputs.latest }}
labels: |
org.opencontainers.image.otp.version=${{ matrix.otp }}
org.opencontainers.image.edition=${{ inputs.edition }}
${{ steps.pre-meta.outputs.extra_labels }}
- uses: docker/build-push-action@v3
with:
push: ${{ inputs.publish == 'true' || github.repository_owner != 'emqx' }}
pull: true
no-cache: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
EMQX_NAME=${{ matrix.profile }}${{ steps.pre-meta.outputs.img_suffix }}
EXTRA_DEPS=${{ steps.pre-meta.outputs.extra_deps }}
file: source/${{ matrix.os[2] }}