Skip to content

Commit

Permalink
Merge pull request #482 from tphakala/version-tag-fixes
Browse files Browse the repository at this point in the history
feat: Improve version handling and build process
  • Loading branch information
tphakala authored Feb 21, 2025
2 parents c46b148 + 19d474e commit 2bff84b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags

- name: Get version
id: get_version
run: |
VERSION=$(git describe --tags --always)
echo "VERSION=${VERSION}" >> ${GITHUB_ENV}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down Expand Up @@ -164,7 +173,7 @@ jobs:
push: true
platforms: ${{ matrix.platform }}
build-args: |
VERSION=nightly-$(date +'%Y%m%d')
BUILD_VERSION=${{ steps.get_version.outputs.version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand All @@ -175,6 +184,13 @@ jobs:
needs: docker
runs-on: ubuntu-24.04
steps:
- name: Get version
id: get_version
run: |
VERSION=$(git describe --tags --always)
echo "VERSION=${VERSION}" >> ${GITHUB_ENV}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -189,6 +205,12 @@ jobs:
- name: Create and push manifest
run: |
DATE=$(date +'%Y%m%d')
# Create and push the version-specific manifest
docker manifest create ghcr.io/${{ env.REPO }}:${{ steps.get_version.outputs.version }} \
ghcr.io/${{ env.REPO }}:${{ steps.get_version.outputs.version }}-amd64 \
ghcr.io/${{ env.REPO }}:${{ steps.get_version.outputs.version }}-arm64
docker manifest push ghcr.io/${{ env.REPO }}:${{ steps.get_version.outputs.version }}
# Create and push the dated manifest
docker manifest create ghcr.io/${{ env.REPO }}:nightly-${DATE} \
Expand Down
34 changes: 25 additions & 9 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ jobs:
uses: softprops/action-gh-release@v1
with:
files: birdnet-go-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
tag_name: nightly-${{ env.RELEASE_DATE }}
name: "Nightly Build ${{ env.RELEASE_DATE }}"
prerelease: true
tag_name: v${{ github.ref_name }}
name: "Release ${{ github.ref_name }}"
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -133,6 +133,15 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags

- name: Get version
id: get_version
run: |
VERSION=$(git describe --tags --always)
echo "VERSION=${VERSION}" >> ${GITHUB_ENV}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand Down Expand Up @@ -164,7 +173,7 @@ jobs:
push: true
platforms: ${{ matrix.platform }}
build-args: |
VERSION=${{ github.ref_name }}
BUILD_VERSION=${{ steps.get_version.outputs.version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
Expand All @@ -175,6 +184,13 @@ jobs:
needs: docker
runs-on: ubuntu-24.04
steps:
- name: Get version
id: get_version
run: |
VERSION=$(git describe --tags --always)
echo "VERSION=${VERSION}" >> ${GITHUB_ENV}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -187,12 +203,12 @@ jobs:
echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
- name: Create and push manifest
run: |
run: |
# Create and push the versioned manifest
docker manifest create ghcr.io/${{ env.REPO }}:${{ github.ref_name }} \
ghcr.io/${{ env.REPO }}:${{ github.ref_name }}-amd64 \
ghcr.io/${{ env.REPO }}:${{ github.ref_name }}-arm64
docker manifest push ghcr.io/${{ env.REPO }}:${{ github.ref_name }}
docker manifest create ghcr.io/${{ env.REPO }}:${{ steps.get_version.outputs.version }} \
ghcr.io/${{ env.REPO }}:${{ steps.get_version.outputs.version }}-amd64 \
ghcr.io/${{ env.REPO }}:${{ steps.get_version.outputs.version }}-arm64
docker manifest push ghcr.io/${{ env.REPO }}:${{ steps.get_version.outputs.version }}
# Create and push the latest manifest
docker manifest create ghcr.io/${{ env.REPO }}:latest \
Expand Down
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ ARG TENSORFLOW_VERSION=2.17.1

FROM --platform=$BUILDPLATFORM golang:1.23.5-bookworm AS buildenv

# Pass VERSION through to the build stage
ARG VERSION
ENV VERSION=$VERSION
# Pass BUILD_VERSION through to the build stage
ARG BUILD_VERSION
ENV BUILD_VERSION=${BUILD_VERSION:-unknown}

# Install Task and other dependencies
RUN apt-get update -q && apt-get install -q -y \
Expand Down Expand Up @@ -38,6 +38,8 @@ COPY --chown=dev-user . ./

# Enter Build stage
FROM --platform=$BUILDPLATFORM buildenv AS build
ARG BUILD_VERSION
ENV BUILD_VERSION=${BUILD_VERSION:-unknown}

ARG TARGETPLATFORM

Expand All @@ -48,7 +50,8 @@ RUN --mount=type=cache,target=/go/pkg/mod,uid=10001,gid=10001 \
task download-assets && \
task generate-tailwindcss && \
TARGET=$(echo ${TARGETPLATFORM} | tr '/' '_') && \
DOCKER_LIB_DIR=/home/dev-user/lib VERSION=${VERSION} task ${TARGET}
echo "Building with BUILD_VERSION=${BUILD_VERSION}" && \
BUILD_VERSION="${BUILD_VERSION}" DOCKER_LIB_DIR=/home/dev-user/lib task ${TARGET}

# Create final image using a multi-platform base image
FROM --platform=$TARGETPLATFORM debian:bookworm-slim

Check warning on line 57 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-push-docker-image

Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior

RedundantTargetPlatform: Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior More info: https://docs.docker.com/go/dockerfile/rule/redundant-target-platform/
Expand Down
7 changes: 6 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ vars:
BUILD_DATE:
sh: date -u +%Y-%m-%dT%H:%M:%SZ
VERSION:
sh: git describe --tags --always 2>/dev/null || echo "unknown"
sh: |
if [ ! -z "$BUILD_VERSION" ]; then
echo "$BUILD_VERSION"
else
git describe --tags --always 2>/dev/null || echo "unknown"
fi
UNAME_S:
sh: uname -s
UNAME_M:
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func mainWithExitCode() int {
settings.Version = version
settings.BuildDate = buildDate

fmt.Printf("🐦 \033[37mBirdNET-Go v%s (built: %s), using config file: %s\033[0m\n",
fmt.Printf("🐦 \033[37mBirdNET-Go %s (built: %s), using config file: %s\033[0m\n",
settings.Version, settings.BuildDate, viper.ConfigFileUsed())

// Execute the root command
Expand Down

0 comments on commit 2bff84b

Please sign in to comment.