Skip to content

Commit

Permalink
Fix docker build process for nightly builds (#407)
Browse files Browse the repository at this point in the history
* refactor: update Dockerfile to allow dynamic TARGETPLATFORM configuration
* fix: tag both images
  • Loading branch information
tphakala authored Jan 24, 2025
1 parent 6177acb commit b60845e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
37 changes: 35 additions & 2 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
strategy:
matrix:
platform: [linux/amd64, linux/arm64]

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -152,6 +152,8 @@ jobs:
with:
images: ghcr.io/${{ env.REPO }}
tags: |
type=raw,value=nightly-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
type=raw,value=nightly-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}-{{date 'YYYYMMDD'}}
type=raw,value=nightly
type=raw,value=nightly-{{date 'YYYYMMDD'}}
Expand All @@ -167,4 +169,35 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
provenance: false

create-manifest:
needs: docker
runs-on: ubuntu-24.04
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate downcase repository name
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
- name: Create and push manifest
run: |
DATE=$(date +'%Y%m%d')
# Create and push the dated manifest
docker manifest create ghcr.io/${{ env.REPO }}:nightly-${DATE} \
ghcr.io/${{ env.REPO }}:nightly-amd64-${DATE} \
ghcr.io/${{ env.REPO }}:nightly-arm64-${DATE}
docker manifest push ghcr.io/${{ env.REPO }}:nightly-${DATE}
# Create and push the latest manifest
docker manifest create ghcr.io/${{ env.REPO }}:nightly \
ghcr.io/${{ env.REPO }}:nightly-amd64-${DATE} \
ghcr.io/${{ env.REPO }}:nightly-arm64-${DATE}
docker manifest push ghcr.io/${{ env.REPO }}:nightly
36 changes: 20 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
ARG TFLITE_LIB_DIR=/usr/lib
ARG TENSORFLOW_VERSION=2.17.1
ARG TARGETPLATFORM=linux/amd64 # Default to linux/amd64 for local builds
ARG VERSION=unknown

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

# Pass VERSION through to the build stage
ARG VERSION
ENV VERSION=$VERSION

# Install Task and other dependencies
RUN apt-get update && apt-get install -y \
RUN apt-get update -q && apt-get install -q -y \
curl \
git \
sudo \
zip \
npm \
gcc-aarch64-linux-gnu \
&& rm -rf /var/lib/apt/lists/* \
&& sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
gcc-aarch64-linux-gnu && \
rm -rf /var/lib/apt/lists/*

# Install Task
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin

# Create dev-user for building and devcontainer usage
RUN groupadd --gid 10001 dev-user && \
Expand All @@ -36,28 +36,32 @@ WORKDIR /home/dev-user/src/BirdNET-Go
# Copy all source files first to have Git information available
COPY --chown=dev-user . ./

# Now run the tasks with VERSION env var
RUN task check-tensorflow && \
task download-assets && \
task generate-tailwindcss
# Enter Build stage
FROM --platform=$BUILDPLATFORM buildenv AS build

# Compile BirdNET-Go
ARG TARGETPLATFORM

# Build assets and compile BirdNET-Go
RUN --mount=type=cache,target=/go/pkg/mod,uid=10001,gid=10001 \
--mount=type=cache,target=/home/dev-user/.cache/go-build,uid=10001,gid=10001 \
task check-tensorflow && \
task download-assets && \
task generate-tailwindcss && \
TARGET=$(echo ${TARGETPLATFORM} | tr '/' '_') && \
DOCKER_LIB_DIR=/home/dev-user/lib VERSION=${VERSION} task ${TARGET}

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

# Install ALSA library and SOX
RUN apt-get update && apt-get install -y --no-install-recommends \
RUN apt-get update -q && apt-get install -q -y --no-install-recommends \
ca-certificates \
libasound2 \
ffmpeg \
sox \
&& rm -rf /var/lib/apt/lists/*
sox

# Clean up apt cache
RUN rm -rf /var/lib/apt/lists/*

# Set TFLITE_LIB_DIR based on architecture
ARG TARGETPLATFORM
Expand Down
6 changes: 4 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ tasks:
generate-tailwindcss:
cmds:
- npm -D install daisyui
- npx --yes tailwindcss@latest -i {{.TAILWIND_INPUT}} -o {{.TAILWIND_OUTPUT}} --minify
- npx --yes tailwindcss@3.4.17 -i {{.TAILWIND_INPUT}} -o {{.TAILWIND_OUTPUT}} --minify

labels-zip:
vars:
Expand Down Expand Up @@ -132,8 +132,10 @@ tasks:
vars: {TFLITE_LIB_DIR: '{{.TFLITE_LIB_DIR}}', TFLITE_LIB_ARCH: '{{.TFLITE_LIB_ARCH}}', TARGET: '{{.TARGET}}'}
- |
mkdir -p {{.TFLITE_LIB_DIR}}
if [ "$(uname -m)" != "aarch64" ]; then
export CC=aarch64-linux-gnu-gcc
fi
GOOS=linux GOARCH=arm64 {{.CGO_FLAGS}} \
CC=aarch64-linux-gnu-gcc \
CGO_LDFLAGS="-L{{.TFLITE_LIB_DIR}} -ltensorflowlite_c" \
go build {{.BUILD_FLAGS}} -o {{.BINARY_DIR}}/{{.BINARY_NAME}}
Expand Down

0 comments on commit b60845e

Please sign in to comment.