ci: use bake file for container build

This commit is contained in:
jo 2023-02-26 15:18:10 +01:00 committed by Kyle Robbertze
parent d6d1b83513
commit 0dd034b7b6
3 changed files with 74 additions and 86 deletions

View File

@ -1,31 +0,0 @@
name: Build container
description: Build and push a container
inputs:
target:
required: true
runs:
using: composite
steps:
- uses: docker/metadata-action@v4
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ inputs.target }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- uses: docker/build-push-action@v4
with:
context: .
pull: true
push: ${{ github.event_name == 'push' }}
build-args: |
LIBRETIME_VERSION=${{ env.LIBRETIME_VERSION }}
target: ${{ inputs.target }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ inputs.target }}
cache-to: type=gha,scope=${{ inputs.target }},mode=max

View File

@ -11,12 +11,37 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}
jobs: jobs:
build: meta:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: strategy:
REGISTRY: ghcr.io matrix:
NAMESPACE: ${{ github.repository_owner }} target: [analyzer, api, legacy, playout, worker]
if: ${{ github.repository_owner == 'libretime' }}
steps:
- uses: actions/checkout@v3
- uses: docker/metadata-action@v4
id: meta
with:
bake-target: ${{ matrix.target }}
images: |
ghcr.io/libretime/libretime-${{ matrix.target }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Upload metadata bake file
uses: actions/upload-artifact@v3
with:
name: meta-${{ matrix.target }}
path: ${{ steps.meta.outputs.bake-file }}
build:
needs: [meta]
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'libretime' }} if: ${{ github.repository_owner == 'libretime' }}
steps: steps:
@ -24,65 +49,35 @@ jobs:
- uses: docker/setup-buildx-action@v2 - uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2 - name: Login ghcr.io
if: github.event_name == 'push'
uses: docker/login-action@v2
with: with:
registry: ${{ env.REGISTRY }} registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Download all metadata bake files
uses: actions/download-artifact@v3
- name: Guess LIBRETIME_VERSION - name: Guess LIBRETIME_VERSION
run: | run: |
make VERSION make VERSION
echo "LIBRETIME_VERSION=$(cat VERSION | tr -d [:blank:])" >> $GITHUB_ENV echo "LIBRETIME_VERSION=$(cat VERSION | tr -d [:blank:])" >> $GITHUB_ENV
- name: Build python-builder - name: Build
uses: docker/build-push-action@v4 uses: docker/bake-action@v2
with: with:
context: .
pull: true pull: true
target: python-builder push: ${{ github.event_name == 'push' }}
cache-from: type=gha,scope=python-builder files: |
cache-to: type=gha,scope=python-builder,mode=max docker-bake.json
meta-analyzer/docker-metadata-action-bake.json
- name: Build python-base meta-api/docker-metadata-action-bake.json
uses: docker/build-push-action@v4 meta-legacy/docker-metadata-action-bake.json
with: meta-playout/docker-metadata-action-bake.json
context: . meta-worker/docker-metadata-action-bake.json
pull: true set: |
target: python-base *.cache-from=type=gha,scope=container
cache-from: type=gha,scope=python-base *.cache-to=type=gha,scope=container,mode=max
cache-to: type=gha,scope=python-base,mode=max *.args.LIBRETIME_VERSION=${{ env.LIBRETIME_VERSION }}
- name: Build python-base-ffmpeg
uses: docker/build-push-action@v4
with:
context: .
pull: true
target: python-base-ffmpeg
cache-from: type=gha,scope=python-base-ffmpeg
cache-to: type=gha,scope=python-base-ffmpeg,mode=max
- name: Build analyzer
uses: ./.github/workflows/actions/build-container
with:
target: libretime-analyzer
- name: Build api
uses: ./.github/workflows/actions/build-container
with:
target: libretime-api
- name: Build playout
uses: ./.github/workflows/actions/build-container
with:
target: libretime-playout
- name: Build worker
uses: ./.github/workflows/actions/build-container
with:
target: libretime-worker
- name: Build legacy
uses: ./.github/workflows/actions/build-container
with:
target: libretime-legacy

24
docker-bake.json Normal file
View File

@ -0,0 +1,24 @@
{
"group": {
"default": {
"targets": ["analyzer", "playout", "api", "worker", "legacy"]
}
},
"target": {
"analyzer": {
"target": "libretime-analyzer"
},
"playout": {
"target": "libretime-playout"
},
"api": {
"target": "libretime-api"
},
"worker": {
"target": "libretime-worker"
},
"legacy": {
"target": "libretime-legacy"
}
}
}