diff --git a/.github/workflows/axosyslog-docker.yml b/.github/workflows/axosyslog-docker.yml index 44ba18c08f..dc32679c09 100644 --- a/.github/workflows/axosyslog-docker.yml +++ b/.github/workflows/axosyslog-docker.yml @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/axosyslog-image-snapshot.yml b/.github/workflows/axosyslog-image-snapshot.yml new file mode 100644 index 0000000000..8501e90540 --- /dev/null +++ b/.github/workflows/axosyslog-image-snapshot.yml @@ -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 }} diff --git a/.github/workflows/axosyslog-image-test.yml b/.github/workflows/axosyslog-image-test.yml new file mode 100644 index 0000000000..0b53373b92 --- /dev/null +++ b/.github/workflows/axosyslog-image-test.yml @@ -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 diff --git a/.github/workflows/nightly-release.yml b/.github/workflows/axosyslog-nightly.yml similarity index 84% rename from .github/workflows/nightly-release.yml rename to .github/workflows/axosyslog-nightly.yml index f1bc387142..cbfaae77c4 100644 --- a/.github/workflows/nightly-release.yml +++ b/.github/workflows/axosyslog-nightly.yml @@ -1,4 +1,4 @@ -name: Nightly release +name: AxoSyslog nightly on: workflow_dispatch: @@ -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: diff --git a/.github/workflows/stable-release.yml b/.github/workflows/axosyslog-stable.yml similarity index 100% rename from .github/workflows/stable-release.yml rename to .github/workflows/axosyslog-stable.yml diff --git a/docker/alpine.dockerfile b/docker/alpine.dockerfile index 139d89522d..f4727911c6 100644 --- a/docker/alpine.dockerfile +++ b/docker/alpine.dockerfile @@ -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; \