Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AxoSyslog snapshot image #109

Merged
merged 5 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 121 additions & 28 deletions .github/workflows/axosyslog-docker.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,69 @@
name: AxoSyslog Docker image
name: AxoSyslog Docker image builder

on:
workflow_call:
inputs:
pkg-type:
type:
required: true
type: string # stable / nightly
tarball-artifact:
type: string # stable / snapshot
platforms:
required: false
type: string
default: linux/amd64,linux/arm64,linux/arm/v7
snapshot-tarball-artifact:
required: false
type: string
snapshot-version:
required: false
type: string
snapshot-tags: # comma-separated
required: false
type: string

env:
DOCKER_IMAGE_NAME: ghcr.io/axoflow/axosyslog
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
DEBUG_PLATFORM: linux/amd64

jobs:
docker:
name: AxoSyslog Docker image
prepare:
runs-on: ubuntu-latest
outputs:
platform-matrix: ${{ steps.platforms.outputs.platform-matrix }}
steps:
- id: platforms
env:
PLATFORMS: ${{ inputs.platforms }}
run: |
PLATFORM_MATRIX="$(echo "$PLATFORMS" | jq 'split(",")' -Rc)"
echo "platform-matrix=$PLATFORM_MATRIX" >> $GITHUB_OUTPUT

image-build:
if: github.repository_owner == 'axoflow'
runs-on: ubuntu-latest
needs: prepare

strategy:
fail-fast: false
matrix:
platform: ${{ fromJSON(needs.prepare.outputs.platform-matrix) }}

steps:
- name: Prepare
env:
PLATFORM: ${{ matrix.platform }}
TYPE: ${{ inputs.type }}
run: |
[ "$TYPE" = "stable" ] || [ "$TYPE" = "snapshot" ]
echo "PLATFORM_PAIR=${PLATFORM//\//-}" >> $GITHUB_ENV

- name: Checkout source
uses: actions/checkout@v4

- name: Download source tarball artifact
if: inputs.tarball-artifact != ''
if: inputs.snapshot-tarball-artifact != ''
uses: actions/download-artifact@v4
with:
name: ${{ inputs.tarball-artifact }}
name: ${{ inputs.snapshot-tarball-artifact }}
path: docker/apkbuild/axoflow/axosyslog

- name: Set up QEMU
Expand All @@ -46,43 +78,104 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (AxoSyslog version) for Docker
id: docker-metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}

- name: Build and push production Docker image
id: build
uses: docker/build-push-action@v5
with:
context: docker
file: docker/alpine.dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.docker-metadata.outputs.labels }}
outputs: type=image,name=${{ env.DOCKER_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true,annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.docker-metadata.outputs.json).labels['org.opencontainers.image.description'] }}
build-args: |
PKG_TYPE=${{ inputs.type }}
SNAPSHOT_VERSION=${{ inputs.snapshot-version }}

- name: Export digest
env:
DIGEST: ${{ steps.build.outputs.digest }}
run: |
mkdir -p /tmp/digests
touch "/tmp/digests/${DIGEST#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge-and-push:
runs-on: ubuntu-latest
needs: image-build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata (AxoSyslog version) for Docker
id: docker-metadata-tags
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
tags: type=match,pattern=axosyslog-(.*),group=1
tags: type=match,pattern=axosyslog-([0-9].*),group=1
sep-tags: ','

- name: Compose Docker image tags
id: tags
env:
TYPE: ${{ inputs.type }}
SNAPSHOT_TAGS: ${{ inputs.snapshot-tags }}
run: |
if [[ '${{ inputs.pkg-type }}' = 'stable' ]]; then
if [[ "$TYPE" = "stable" ]]; then
TAGS='${{ steps.docker-metadata-tags.outputs.tags }}'
elif [[ '${{ inputs.pkg-type }}' = 'nightly' ]]; then
TAGS="${DOCKER_IMAGE_NAME}:nightly,${DOCKER_IMAGE_NAME}:${{ inputs.snapshot-version }}"
elif [[ "$TYPE" = "snapshot" ]]; then
TAGS="$(echo "$SNAPSHOT_TAGS" | sed "s|[^,]*|$DOCKER_IMAGE_NAME:&|g")"
else
echo Unexpected input: pkg-type=${{ inputs.pkg-type }}
echo "Unexpected input: type=$TYPE"
false
fi

echo "TAGS=$TAGS" >> $GITHUB_OUTPUT
echo "DEBUG_TAGS=${TAGS//,/-dbg,}-dbg" >> $GITHUB_OUTPUT

- name: Build and push production Docker image
uses: docker/build-push-action@v5
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
context: docker
file: docker/alpine.dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ steps.tags.outputs.TAGS }}
# description should be here because it is a multi-arch image
# see docs: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images
outputs: type=image,name=${{ env.DOCKER_IMAGE_NAME }},annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.docker-metadata-tags.outputs.json).labels['org.opencontainers.image.description'] }}
build-args: |
PKG_TYPE=${{ inputs.pkg-type }}
SNAPSHOT_VERSION=${{ inputs.snapshot-version }}
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
env:
TAGS: ${{ steps.tags.outputs.TAGS }}
run: |
TAG_FLAGS="$(echo "$TAGS" | sed "s|[^,]*|-t &|g" | tr ',' ' ')"
docker buildx imagetools create $TAG_FLAGS $(printf "$DOCKER_IMAGE_NAME@sha256:%s " *)

- name: Checkout source
uses: actions/checkout@v4

- name: Download source tarball artifact
if: inputs.snapshot-tarball-artifact != ''
uses: actions/download-artifact@v4
with:
name: ${{ inputs.snapshot-tarball-artifact }}
path: docker/apkbuild/axoflow/axosyslog

- name: Build and push debug Docker image
uses: docker/build-push-action@v5
Expand All @@ -93,6 +186,6 @@ jobs:
push: true
tags: ${{ steps.tags.outputs.DEBUG_TAGS }}
build-args: |
PKG_TYPE=${{ inputs.pkg-type }}
PKG_TYPE=${{ inputs.type }}
SNAPSHOT_VERSION=${{ inputs.snapshot-version }}
DEBUG=true
52 changes: 52 additions & 0 deletions .github/workflows/axosyslog-image-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: AxoSyslog snapshot image

on:
workflow_dispatch:
inputs:
platforms:
default: "linux/amd64,linux/arm64,linux/arm/v7"
push:
branches:
- main

jobs:
tarball:
runs-on: ubuntu-latest
outputs:
snapshot-version: ${{ steps.snapshot-version.outputs.SNAPSHOT_VERSION }}
steps:
- name: Checkout AxoSyslog source
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepare docker image
run: ./dbld/rules cache-image-tarball

- name: Create source tarball
run: ./dbld/rules pkg-tarball

- name: Determine snapshot version
id: snapshot-version
run: |
tarball_filename="$(find dbld/build -name '*.tar.*' -printf '%f\n')"
tarball_name="${tarball_filename/\.tar.*}"
tarball_version="${tarball_name/axosyslog-}"
pkg_version="$(echo $tarball_version | sed -E 's|(([0-9]+\.){2}[0-9]+).*|\1|')_git$(date +%Y%m%d)"
echo "SNAPSHOT_VERSION=${pkg_version}" >> $GITHUB_OUTPUT

- name: Store source tarball as artifact
uses: actions/upload-artifact@v4
with:
name: source-tarball
path: dbld/build/*.tar.*

publish-image:
uses: ./.github/workflows/axosyslog-docker.yml
needs: tarball
with:
type: snapshot
platforms: ${{ inputs.platforms || 'linux/amd64' }}
snapshot-tarball-artifact: source-tarball
snapshot-version: ${{ needs.tarball.outputs.snapshot-version }}
snapshot-tags: dev-${{ github.ref_name }}
65 changes: 65 additions & 0 deletions .github/workflows/axosyslog-image-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI @ AxoSyslog image

on:
pull_request:
push:

jobs:
tarball:
runs-on: ubuntu-latest
outputs:
snapshot-version: ${{ steps.snapshot-version.outputs.SNAPSHOT_VERSION }}
steps:
- name: Checkout AxoSyslog source
uses: actions/checkout@v4

- name: Prepare docker image
run: ./dbld/rules cache-image-tarball

- name: Create source tarball
run: ./dbld/rules pkg-tarball

- name: Determine snapshot version
id: snapshot-version
run: |
tarball_filename="$(find dbld/build -name '*.tar.*' -printf '%f\n')"
tarball_name="${tarball_filename/\.tar.*}"
tarball_version="${tarball_name/axosyslog-}"
pkg_version="$(echo $tarball_version | sed -E 's|(([0-9]+\.){2}[0-9]+).*|\1|')_git$(date +%Y%m%d)"
echo "SNAPSHOT_VERSION=${pkg_version}" >> $GITHUB_OUTPUT

- name: Store source tarball as artifact
uses: actions/upload-artifact@v4
with:
name: source-tarball
path: dbld/build/*.tar.gz

build-and-test:
runs-on: ubuntu-latest
needs: tarball
steps:
- name: Checkout AxoSyslog source
uses: actions/checkout@v4

- name: Download source tarball artifact
uses: actions/download-artifact@v4
with:
name: source-tarball
path: docker/apkbuild/axoflow/axosyslog

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: docker
file: docker/alpine.dockerfile
load: true
tags: axosyslog:test
build-args: |
PKG_TYPE=snapshot
SNAPSHOT_VERSION=${{ needs.tarball.outputs.snapshot-version }}

- name: Smoke test
run: |
export SYSLOG_NG_IMAGE="axosyslog:test"
export SYSLOG_NG_VERSION="${{ needs.tarball.outputs.snapshot-version }}"
docker/tests/smoke.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Nightly release
name: AxoSyslog nightly

on:
workflow_dispatch:
Expand Down Expand Up @@ -69,44 +69,15 @@ jobs:
# with:
# pkg-type: nightly

build-and-test:
runs-on: ubuntu-latest
needs: tarball
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Download source tarball artifact
uses: actions/download-artifact@v4
with:
name: source-tarball
path: docker/apkbuild/axoflow/axosyslog

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: docker
file: docker/alpine.dockerfile
load: true
tags: axosyslog:test
build-args: |
PKG_TYPE=nightly
SNAPSHOT_VERSION=${{ needs.tarball.outputs.snapshot-version }}

- name: Smoke test
run: |
export SYSLOG_NG_IMAGE="axosyslog:test"
export SYSLOG_NG_VERSION="${{ needs.tarball.outputs.snapshot-version }}"
docker/tests/smoke.sh

publish-image:
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/axosyslog-docker.yml
needs: [tarball, build-and-test]
needs: tarball
with:
pkg-type: nightly
tarball-artifact: source-tarball
type: snapshot
snapshot-tarball-artifact: source-tarball
snapshot-version: ${{ needs.tarball.outputs.snapshot-version }}
snapshot-tags: nightly,${{ needs.tarball.outputs.snapshot-version }}

# https://github.com/actions/delete-package-versions/issues/90
cleanup-old-images:
Expand Down
4 changes: 2 additions & 2 deletions docker/alpine.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ RUN mkdir packages \
&& abuild-keygen -n -a -i \
&& printf 'export JOBS=$(nproc)\nexport MAKEFLAGS=-j$JOBS\n' >> .abuild/abuild.conf \
&& cd axoflow/axosyslog \
&& if [ "$PKG_TYPE" = "nightly" ]; then \
&& if [ "$PKG_TYPE" = "snapshot" ]; then \
tarball_filename="$(ls axosyslog-*.tar.*)"; \
[ -z "$tarball_filename" ] && echo "Tarball for nightly can not be found" && exit 1; \
[ -z "$tarball_filename" ] && echo "Tarball for snapshot can not be found" && exit 1; \
tarball_name="${tarball_filename/\.tar.*}"; \
sed -i -e "s|^pkgver=.*|pkgver=$SNAPSHOT_VERSION|" -e "s|^builddir=.*|builddir=\"\$srcdir/$tarball_name\"|" APKBUILD; \
sed -i -e "s|^source=.*|source=\"$tarball_filename|" APKBUILD; \
Expand Down
Loading