diff --git a/.gitea/workflows/publish-image.yaml b/.gitea/workflows/publish-image.yaml index a1fffdf..de54a25 100644 --- a/.gitea/workflows/publish-image.yaml +++ b/.gitea/workflows/publish-image.yaml @@ -3,20 +3,30 @@ on: push: paths: - 'Dockerfile.*' - - '*.sh' + - 'workflows/scripts/*.sh' jobs: - # JOB 1: Handles the Fedora Base + # JOB 1: Setup & Calculate Short SHA + setup: + runs-on: ubuntu-latest + steps: + - name: Set Short SHA + run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV + outputs: + short_sha: ${{ env.SHORT_SHA }} + + # JOB 2: Build Base (Cached) build-base: + needs: setup runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Make scripts executable - run: chmod +x *.sh + run: chmod +x workflows/scripts/*.sh - - name: Build/Cache Base + - name: Build Base uses: docker://quay.io/buildah/stable env: USERNAME: ${{ gitea.repository_owner }} @@ -24,28 +34,36 @@ jobs: REGISTRY: gitea.212.63.210.91.nip.io with: entrypoint: /bin/sh - args: ./build-base.sh + args: workflows/scripts/build-base.sh - # JOB 2: Handles the Windows Builder - # Only runs if Base succeeds. - build-windows: - needs: build-base + # JOB 3: Build Targets (Matrix) + build-targets: + needs: [setup, build-base] runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - name: windows + dockerfile: Dockerfile.windows + - name: linux + dockerfile: Dockerfile.linux + steps: - name: Checkout uses: actions/checkout@v3 - name: Make scripts executable - run: chmod +x *.sh - - - name: Build Windows Target + run: chmod +x workflows/scripts/*.sh + + - name: Build ${{ matrix.name }} uses: docker://quay.io/buildah/stable env: USERNAME: ${{ gitea.repository_owner }} PASSWORD: ${{ secrets.USER_PACKAGE_PASSWORD }} REGISTRY: gitea.212.63.210.91.nip.io - # We pass the Git SHA here for the final image tag - TAG: ${{ gitea.sha }} + TAG: ${{ needs.setup.outputs.short_sha }} with: entrypoint: /bin/sh - args: ./build-windows.sh \ No newline at end of file + # Pass the matrix variables to our generic script + args: -c "./workflows/scripts/build-target.sh ${{ matrix.name }} ${{ matrix.dockerfile }}" \ No newline at end of file diff --git a/.gitea/workflows/scripts/build-base.sh b/.gitea/workflows/scripts/build-base.sh new file mode 100644 index 0000000..2d5f0a4 --- /dev/null +++ b/.gitea/workflows/scripts/build-base.sh @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +# --- Configuration --- +IMAGE_NAME="godot-builder-base" +# We hash the Dockerfile to create a unique cache key +FILE_HASH=$(sha256sum Dockerfile.base | cut -c 1-8) +FULL_TAG="$REGISTRY/$USERNAME/$IMAGE_NAME:$FILE_HASH" +LATEST_TAG="$REGISTRY/$USERNAME/$IMAGE_NAME:latest" + +echo "Logging in..." +buildah login -u "$USERNAME" -p "$PASSWORD" --tls-verify=false "$REGISTRY" + +echo "Checking if base image $FULL_TAG exists..." + +# If we can pull it, we don't need to build it! +if buildah pull --tls-verify=false "$FULL_TAG"; then + echo "✅ Cache Hit! Base image exists. Skipping build." + # Just re-tag 'latest' to point to this valid existing image + buildah tag "$FULL_TAG" "$LATEST_TAG" + buildah push --tls-verify=false "$LATEST_TAG" + exit 0 +fi + +echo "⚠️ Cache Miss. Building new base image..." +buildah build \ + --tls-verify=false \ + -f Dockerfile.base \ + -t "$FULL_TAG" \ + -t "$LATEST_TAG" \ + . + +echo "Pushing base image..." +buildah push --tls-verify=false "$FULL_TAG" +buildah push --tls-verify=false "$LATEST_TAG" \ No newline at end of file diff --git a/.gitea/workflows/scripts/build-target.sh b/.gitea/workflows/scripts/build-target.sh new file mode 100644 index 0000000..457d0a5 --- /dev/null +++ b/.gitea/workflows/scripts/build-target.sh @@ -0,0 +1,46 @@ +#!/bin/sh +set -e + +# Arguments passed from YAML: +# $1 = Target Name (e.g., windows, linux) +# $2 = Dockerfile Path (e.g., Dockerfile.windows) + +TARGET_NAME="$1" +DOCKERFILE="$2" +IMAGE_NAME="godot-builder-$TARGET_NAME" + +# Determine Base Tag (Must match logic in build-base.sh!) +BASE_HASH=$(sha256sum Dockerfile.base | cut -c 1-8) +BASE_FULL_TAG="$REGISTRY/$USERNAME/godot-builder-base:$BASE_HASH" + +# Target Tags (Using the Commit SHA passed from workflow) +FULL_TAG="$REGISTRY/$USERNAME/$IMAGE_NAME:$TAG" +LATEST_TAG="$REGISTRY/$USERNAME/$IMAGE_NAME:latest" + +echo "Logging in..." +buildah login -u "$USERNAME" -p "$PASSWORD" --tls-verify=false "$REGISTRY" + +echo "---------------------------------------" +echo "Building $TARGET_NAME Image..." +echo "Using Base: $BASE_FULL_TAG" +echo "---------------------------------------" + +# 1. Pull the Base (Required so Buildah knows about it) +buildah pull --tls-verify=false "$BASE_FULL_TAG" + +# 2. Create Local Alias +# This satisfies "FROM godot-fedora:custom" in your Dockerfiles +buildah tag "$BASE_FULL_TAG" "godot-fedora:custom" + +# 3. Build Target +buildah build \ + --tls-verify=false \ + --build-arg img_version=custom \ + -f "$DOCKERFILE" \ + -t "$FULL_TAG" \ + -t "$LATEST_TAG" \ + . + +echo "Pushing $TARGET_NAME image..." +buildah push --tls-verify=false "$FULL_TAG" +buildah push --tls-verify=false "$LATEST_TAG" \ No newline at end of file diff --git a/Dockerfile.linux b/Dockerfile.linux new file mode 100644 index 0000000..fd4840c --- /dev/null +++ b/Dockerfile.linux @@ -0,0 +1,35 @@ +ARG img_version +FROM godot-fedora:${img_version} + +ENV GODOT_SDK_LINUX_X86_64=/root/x86_64-godot-linux-gnu_sdk-buildroot +ENV GODOT_SDK_LINUX_X86_32=/root/i686-godot-linux-gnu_sdk-buildroot +ENV GODOT_SDK_LINUX_ARM64=/root/aarch64-godot-linux-gnu_sdk-buildroot +ENV GODOT_SDK_LINUX_ARM32=/root/arm-godot-linux-gnueabihf_sdk-buildroot +ENV BASE_PATH=${PATH} + +RUN dnf install -y wayland-devel && \ + curl -LO https://github.com/godotengine/buildroot/releases/download/godot-2023.08.x-4/x86_64-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + tar xf x86_64-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + rm -f x86_64-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + cd x86_64-godot-linux-gnu_sdk-buildroot && \ + ./relocate-sdk.sh && \ + cd /root && \ + curl -LO https://github.com/godotengine/buildroot/releases/download/godot-2023.08.x-4/i686-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + tar xf i686-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + rm -f i686-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + cd i686-godot-linux-gnu_sdk-buildroot && \ + ./relocate-sdk.sh && \ + cd /root && \ + curl -LO https://github.com/godotengine/buildroot/releases/download/godot-2023.08.x-4/aarch64-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + tar xf aarch64-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + rm -f aarch64-godot-linux-gnu_sdk-buildroot.tar.bz2 && \ + cd aarch64-godot-linux-gnu_sdk-buildroot && \ + ./relocate-sdk.sh && \ + cd /root && \ + curl -LO https://github.com/godotengine/buildroot/releases/download/godot-2023.08.x-4/arm-godot-linux-gnueabihf_sdk-buildroot.tar.bz2 && \ + tar xf arm-godot-linux-gnueabihf_sdk-buildroot.tar.bz2 && \ + rm -f arm-godot-linux-gnueabihf_sdk-buildroot.tar.bz2 && \ + cd arm-godot-linux-gnueabihf_sdk-buildroot && \ + ./relocate-sdk.sh + +CMD /bin/bash \ No newline at end of file diff --git a/Dockerfile.windows b/Dockerfile.windows index cea3e9b..228b0fa 100644 --- a/Dockerfile.windows +++ b/Dockerfile.windows @@ -4,15 +4,14 @@ FROM godot-fedora:${img_version} RUN dnf -y install --setopt=install_weak_deps=False \ mingw32-gcc mingw32-gcc-c++ mingw32-winpthreads-static mingw64-gcc mingw64-gcc-c++ mingw64-winpthreads-static -ENV LLVM_MINGW_NAME=llvm-mingw-20250528-ucrt-ubuntu-22.04-x86_64 +ENV LLVM_MINGW_VERSION=20250528 +ENV LLVM_MINGW_NAME=llvm-mingw-${LLVM_MINGW_VERSION}-ucrt-ubuntu-22.04-x86_64 -# Use a wildcard so we don't have to worry about variable expansion issues in COPY -COPY llvm-mingw-*.tar.xz . - -# Extract and Install -RUN tar xf ${LLVM_MINGW_NAME}.tar.xz && \ - rm -f ${LLVM_MINGW_NAME}.tar.xz && \ - mv ${LLVM_MINGW_NAME} /root/llvm-mingw +# DIRECT DOWNLOAD (Now works because MTU is fixed!) +RUN curl -LO "https://github.com/mstorsjo/llvm-mingw/releases/download/${LLVM_MINGW_VERSION}/${LLVM_MINGW_NAME}.tar.xz" && \ + tar xf "${LLVM_MINGW_NAME}.tar.xz" && \ + rm -f "${LLVM_MINGW_NAME}.tar.xz" && \ + mv "${LLVM_MINGW_NAME}" /root/llvm-mingw ENV PATH="/root/llvm-mingw/bin:${PATH}" diff --git a/build-base.sh b/build-base.sh deleted file mode 100644 index ee31b26..0000000 --- a/build-base.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -set -e - -# --- Configuration --- -IMAGE_NAME="godot-builder-base" -# Calculate a short hash based purely on the file content -# If you don't change the file, this hash stays the same! -FILE_HASH=$(sha256sum Dockerfile.base | cut -c 1-8) -FULL_TAG="$REGISTRY/$USERNAME/$IMAGE_NAME:$FILE_HASH" -LATEST_TAG="$REGISTRY/$USERNAME/$IMAGE_NAME:latest" - -echo "Logging in..." -buildah login -u "$USERNAME" -p "$PASSWORD" --tls-verify=false --storage-driver=vfs "$REGISTRY" - -echo "Checking if base image $FULL_TAG exists..." - -# Try to pull the specific hash. If it works, we are done! -if buildah pull --tls-verify=false --storage-driver=vfs "$FULL_TAG"; then - echo "✅ Cache Hit! Image already exists. Skipping build." - # Retag it as 'latest' just to be safe for other jobs - buildah tag --storage-driver=vfs "$FULL_TAG" "$LATEST_TAG" - buildah push --tls-verify=false --storage-driver=vfs "$LATEST_TAG" - exit 0 -fi - -echo "⚠️ Cache Miss. Building new base image..." -buildah build \ - --tls-verify=false \ - --storage-driver=vfs \ - --network=host \ - -f Dockerfile.base \ - -t "$FULL_TAG" \ - -t "$LATEST_TAG" \ - . - -echo "Pushing new base image..." -buildah push --tls-verify=false --storage-driver=vfs "$FULL_TAG" -buildah push --tls-verify=false --storage-driver=vfs "$LATEST_TAG" \ No newline at end of file diff --git a/build-windows.sh b/build-windows.sh deleted file mode 100644 index 30af51f..0000000 --- a/build-windows.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/sh -set -e - -# --- Configuration --- -BASE_IMAGE_NAME="godot-builder-base" -WIN_IMAGE_NAME="godot-builder-windows" - -# We need the SAME hash logic to find the right base -BASE_HASH=$(sha256sum Dockerfile.base | cut -c 1-8) -BASE_TAG="$REGISTRY/$USERNAME/$BASE_IMAGE_NAME:$BASE_HASH" - -# For the Windows image, we still use the Git SHA (passed from workflow) -# because we want a new Windows builder for every code commit. -WIN_TAG="$REGISTRY/$USERNAME/$WIN_IMAGE_NAME:$TAG" - -TARBALL="llvm-mingw-20250528-ucrt-ubuntu-22.04-x86_64.tar.xz" - -echo "Logging in..." -buildah login -u "$USERNAME" -p "$PASSWORD" --tls-verify=false --storage-driver=vfs "$REGISTRY" - -echo "---------------------------------------" -echo "Preparing Base Image..." -echo "---------------------------------------" -# Pull the base (which build-base.sh guaranteed exists) -buildah pull --tls-verify=false --storage-driver=vfs "$BASE_TAG" - -# Create the local alias so Dockerfile.windows finds it -# This satisfies: FROM godot-fedora:custom -buildah tag --storage-driver=vfs "$BASE_TAG" "godot-fedora:custom" - -echo "---------------------------------------" -echo "Preparing Context..." -echo "---------------------------------------" - -# Check if the file exists in the 'files/' folder (provided by actions/checkout) -if [ -f "files/$TARBALL" ]; then - echo "✅ Found local tarball in repository. Copying to build context..." - cp "files/$TARBALL" . -else - echo "❌ CRITICAL ERROR: $TARBALL not found in 'files/' directory!" - echo "Did you forget to git add/push the file?" - exit 1 -fi - -echo "---------------------------------------" -echo "Building Windows Image..." -echo "---------------------------------------" - -buildah build \ - --tls-verify=false \ - --storage-driver=vfs \ - --network=host \ - --build-arg img_version=custom \ - -f Dockerfile.windows \ - -t "$WIN_TAG" \ - -t "$REGISTRY/$USERNAME/$WIN_IMAGE_NAME:latest" \ - . - -echo "Pushing Windows image..." -buildah push --tls-verify=false --storage-driver=vfs "$WIN_TAG" -buildah push --tls-verify=false --storage-driver=vfs "$REGISTRY/$USERNAME/$WIN_IMAGE_NAME:latest" \ No newline at end of file