From b74d20058445ab21746b3fc268fab627ca252ecb Mon Sep 17 00:00:00 2001 From: Luke Else Date: Thu, 23 Oct 2025 09:32:05 +0100 Subject: [PATCH] feat: Corrected kotlin dev and added in build script to allow local running --- .gitea/workflows/build-and-push.yml | 35 +++-------------- build.sh | 58 +++++++++++++++++++++++++++++ kotlin-dev/Dockerfile | 4 +- 3 files changed, 66 insertions(+), 31 deletions(-) create mode 100755 build.sh diff --git a/.gitea/workflows/build-and-push.yml b/.gitea/workflows/build-and-push.yml index daf71ae..0f52514 100644 --- a/.gitea/workflows/build-and-push.yml +++ b/.gitea/workflows/build-and-push.yml @@ -24,35 +24,12 @@ jobs: - name: Build and push containers run: | - # ...existing code... - set -euo pipefail - - registry="${{ secrets.CONTAINER_REGISTRY }}" - username="${{ secrets.CONTAINER_REGISTRY_USERNAME }}" - - # Build 'base' and 'lab' groups first (including subdirectories) - for group in base lab; do - if [ -d "$group" ]; then - echo "Processing group: $group" - find "$group" -type f -iname 'Dockerfile' -exec dirname {} \; | sed 's|^\./||' | sort -u | while read -r dir; do - tag="$registry/$username/$dir:latest" - echo "Building $dir -> $tag" - docker build -t "$tag" "$dir" - docker push "$tag" - done - else - echo "Skipping missing group: $group" - fi - done - - # Then build everything else (exclude base and lab) - echo "Processing remaining Dockerfiles" - find . -type f -iname 'Dockerfile' -exec dirname {} \; | sed 's|^\./||' | sort -u | grep -Ev '^(base|lab)(/|$)' | while read -r dir; do - tag="$registry/$username/$dir:latest" - echo "Building $dir -> $tag" - docker build -t "$tag" "$dir" - docker push "$tag" - done + - name: Build and push containers + env: + CONTAINER_REGISTRY: ${{ secrets.CONTAINER_REGISTRY }} + CONTAINER_REGISTRY_USERNAME: ${{ secrets.CONTAINER_REGISTRY_USERNAME }} + run: | + ./build.sh -p - name: Docker Prune run: docker system prune -f --all diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..4973dca --- /dev/null +++ b/build.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Defaults +default_registry="git.luke-else.co.uk" +default_username="luke-else" + +# Use env vars if set, otherwise fallback to defaults +registry="${CONTAINER_REGISTRY:-$default_registry}" +username="${CONTAINER_REGISTRY_USERNAME:-$default_username}" + +# Parse args: only push when -p or --push is provided +push=false +usage() { echo "Usage: $0 [--push|-p]"; } + +while [ "$#" -gt 0 ]; do + case "$1" in + -p|--push) push=true; shift ;; + -h|--help) usage; exit 0 ;; + *) echo "Unknown option: $1"; usage; exit 1 ;; + esac +done + +echo "Registry: $registry" +echo "Username: $username" +echo "Push enabled: $push" + +# Build 'base' and 'lab' groups first (including subdirectories) +for group in base lab; do + if [ -d "$group" ]; then + echo "Processing group: $group" + find "$group" -type f -iname 'Dockerfile' -exec dirname {} \; | sed 's|^\./||' | sort -u | while read -r dir; do + tag="$registry/$username/$dir:latest" + echo "Building $dir -> $tag" + docker build -t "$tag" "$dir" + if [ "$push" = true ]; then + docker push "$tag" + else + echo "Push skipped for $tag" + fi + done + else + echo "Skipping missing group: $group" + fi +done + +# Then build everything else (exclude base and lab) +echo "Processing remaining Dockerfiles" +find . -type f -iname 'Dockerfile' -exec dirname {} \; | sed 's|^\./||' | sort -u | grep -Ev '^(base|lab)(/|$)' | while read -r dir; do + tag="$registry/$username/$dir:latest" + echo "Building $dir -> $tag" + docker build -t "$tag" "$dir" + if [ "$push" = true ]; then + docker push "$tag" + else + echo "Push skipped for $tag" + fi +done \ No newline at end of file diff --git a/kotlin-dev/Dockerfile b/kotlin-dev/Dockerfile index 8c0d04c..8b58006 100644 --- a/kotlin-dev/Dockerfile +++ b/kotlin-dev/Dockerfile @@ -1,6 +1,6 @@ FROM git.luke-else.co.uk/luke-else/lab:latest -RUN apk add --no-cache unzip zip openjdk21 +RUN sudo apk add --no-cache unzip zip openjdk21 # Set Java environment variables ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk @@ -14,4 +14,4 @@ RUN curl -s "https://get.sdkman.io" | bash && \ # Make SDKMAN tools available in PATH ENV SDKMAN_DIR="/root/.sdkman" -ENV PATH="$SDKMAN_DIR/candidates/kotlin/current/bin:$SDKMAN_DIR/candidates/gradle/current/bin:$PATH" \ No newline at end of file +ENV PATH="$SDKMAN_DIR/candidates/kotlin/current/bin:$SDKMAN_DIR/candidates/gradle/current/bin:$PATH"