From 046c8e195bfc6c826415b71362ed888e329b99c1 Mon Sep 17 00:00:00 2001 From: Lachee Date: Fri, 19 Sep 2025 15:09:36 +1000 Subject: [PATCH] Updated build scripts --- .gitea/workflows/create-image.yaml | 8 +-- .gitea/workflows/create-runner.yaml | 50 ++++++++++++++++++ ...ild-image.sh => build-individual-image.sh} | 3 +- .../workflows/scripts/build-runner-image.sh | 24 +++++---- .github/workflows/create-image.yaml | 4 +- .github/workflows/create-runner.yaml | 52 +++++++++++++++++++ dockerfiles/individual.dockerfile | 41 +++++++++++++++ Dockerfile => dockerfiles/runner.dockerfile | 18 ++++--- test.sh | 4 -- 9 files changed, 175 insertions(+), 29 deletions(-) create mode 100644 .gitea/workflows/create-runner.yaml rename .gitea/workflows/scripts/{build-image.sh => build-individual-image.sh} (97%) mode change 100755 => 100644 create mode 100644 .github/workflows/create-runner.yaml create mode 100644 dockerfiles/individual.dockerfile rename Dockerfile => dockerfiles/runner.dockerfile (88%) delete mode 100644 test.sh diff --git a/.gitea/workflows/create-image.yaml b/.gitea/workflows/create-image.yaml index 7b6b6ec..2711e46 100644 --- a/.gitea/workflows/create-image.yaml +++ b/.gitea/workflows/create-image.yaml @@ -1,9 +1,9 @@ -name: Create Images +name: 🤓 Individual Runners on: - push: - branches: [main] - paths: ['versions.txt'] + # push: + # branches: [main] + # paths: ['versions.txt'] workflow_dispatch: inputs: diff --git a/.gitea/workflows/create-runner.yaml b/.gitea/workflows/create-runner.yaml new file mode 100644 index 0000000..a7edf54 --- /dev/null +++ b/.gitea/workflows/create-runner.yaml @@ -0,0 +1,50 @@ +name: 😎 Uber Runner + +on: + push: + branches: [main] + paths: + - versions.txt + - dockerfiles/runner.dockerfile + - .github/workflows/create-runner.yaml + +jobs: + build-docker: + runs-on: ubuntu-latest + env: + DOCKER_REGISTRY: docker.lakes.house/ + UNITY_MODULES: webgl android ios mac-mono windows-mono linux-il2cpp + GAMECI_VERSION: 3 + + name: Build + steps: + - uses: actions/checkout@v4 + - name: Login to Docker Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Get Unity Version + run: | + VERSION=$(head -n 1 versions.txt) + echo "UNITY_VERSION=$VERSION" >> $GITHUB_ENV + echo "Unity Version: $VERSION" + + - name: Docker Build + run: .gitea/workflows/scripts/build-runner-image.sh + id: build-image + env: + UNITY_VERSION: ${{ env.UNITY_VERSION }} + UNITY_MODULES: ${{ env.UNITY_MODULES }} + GAMECI_VERSION: ${{ env.GAMECI_VERSION }} + GAMECI_OS: ubuntu + IMAGE: ${{ env.DOCKER_REGISTRY }}unityci/editor + + - name: Docker Push + run: | + echo "Pushing Docker Image ${{ steps.build-image.outputs.FULL_IMAGE }}" + echo "- Image: ${{ steps.build-image.outputs.IMAGE }}" + echo "- Tag: ${{ steps.build-image.outputs.TAG }}" + docker push ${{ steps.build-image.outputs.FULL_IMAGE }} \ No newline at end of file diff --git a/.gitea/workflows/scripts/build-image.sh b/.gitea/workflows/scripts/build-individual-image.sh old mode 100755 new mode 100644 similarity index 97% rename from .gitea/workflows/scripts/build-image.sh rename to .gitea/workflows/scripts/build-individual-image.sh index bc51702..1d08962 --- a/.gitea/workflows/scripts/build-image.sh +++ b/.gitea/workflows/scripts/build-individual-image.sh @@ -85,8 +85,7 @@ docker build \ --build-arg BASE_IMAGE=${BASE_IMAGE} \ ${ADDITIONAL_TAGS} \ -t ${FULL_IMAGE} \ - ${DOCKER_BUILD_ARGS} \ - . + ${DOCKER_BUILD_ARGS} dockerfiles/individual.dockerfile if [ $? -ne 0 ]; then echo "Error: Docker build failed." diff --git a/.gitea/workflows/scripts/build-runner-image.sh b/.gitea/workflows/scripts/build-runner-image.sh index 4be1b3a..a35d580 100644 --- a/.gitea/workflows/scripts/build-runner-image.sh +++ b/.gitea/workflows/scripts/build-runner-image.sh @@ -10,13 +10,16 @@ if [ -z "${UNITY_VERSION}" ]; then fi # Fetch the changelog and extract the changeset ID for the specified Unity version -CHANGELOG_URL="https://public-cdn.cloud.unity3d.com/hub/prod/releases-${UNITY_VERSION}.json" -CHANGESET_ID=$(curl -s "$CHANGELOG_URL" | grep -o '"changeset":[^,]*' | head -n 1 | cut -d':' -f2 | tr -d ' "') - -if [ -z "$CHANGESET_ID" ]; then - echo "Warning: Could not retrieve changeset ID for Unity version ${UNITY_VERSION}." -else - echo "Unity ${UNITY_VERSION} changeset ID: ${CHANGESET_ID}" +# This is because hub doesnt remember every version of unity and uses the changset for the exact id lookup. +if [ -z "${UNITY_CHANGESET}" ]; then + echo "Warning: No changeset provided. Scraping one from the change logs." + echo "This might take a while. Use the UNITY_CHANGESET to avoid this lookup." + CHANGELOG_URL="https://unity.com/releases/editor/whats-new/${UNITY_VERSION}" + UNITY_CHANGESET=$(curl -s -r 0-500 "$CHANGELOG_URL" | grep -oP 'unityhub://(?:[0-9a-z.])+/\K([a-z0-9]+)' | head -n 1) + if [ -z "$UNITY_CHANGESET" ]; then + echo "Error: Could not extract changeset for Unity version ${UNITY_VERSION}." + exit 1 + fi fi # Ensure we have some modules @@ -82,6 +85,8 @@ DEST_TAG=${GAMECI_OS}-${UNITY_VERSION}-runner DEST_IMAGE=${IMAGE}:${DEST_TAG} echo "Building Docker image ${DEST_IMAGE}" +echo "- Version: ${UNITY_VERSION}" +echo "- Changeset: ${UNITY_CHANGESET}" echo "- Platfrom: ${PLATFORM}" echo "- Base: ${BASE_IMAGE}" echo "- Tag: ${DEST_TAG}" @@ -90,11 +95,10 @@ echo "- Image: ${DEST_IMAGE}" docker build \ --platform ${PLATFORM} \ --build-arg "VERSION=${UNITY_VERSION}" \ + --build-arg "CHANGESET=${UNITY_CHANGESET}" \ --build-arg "BASE_IMAGE=${BASE_IMAGE}" \ --build-arg "MODULE=${UNITY_MODULES}" \ - -t ${DEST_IMAGE} \ - ${DOCKER_BUILD_ARGS} \ - . + -t ${DEST_IMAGE} ${DOCKER_BUILD_ARGS} dockerfiles/runner.dockerfile if [ $? -ne 0 ]; then echo "Error: Docker build failed." diff --git a/.github/workflows/create-image.yaml b/.github/workflows/create-image.yaml index 1aaca6d..df1e458 100644 --- a/.github/workflows/create-image.yaml +++ b/.github/workflows/create-image.yaml @@ -1,4 +1,4 @@ -name: Create Images +name: Individual Runners on: workflow_dispatch: @@ -43,7 +43,7 @@ jobs: echo "Unity Version: $VERSION" - name: Docker Build - run: .gitea/workflows/scripts/build-image.sh + run: .gitea/workflows/scripts/build-individual-image.sh id: build-image env: UNITY_VERSION: ${{ env.UNITY_VERSION }} diff --git a/.github/workflows/create-runner.yaml b/.github/workflows/create-runner.yaml new file mode 100644 index 0000000..ced1f11 --- /dev/null +++ b/.github/workflows/create-runner.yaml @@ -0,0 +1,52 @@ +name: 😎 Uber Runner + +on: + workflow_dispatch: + push: + branches: [main] + paths: + - versions.txt + - dockerfiles/runner.dockerfile + - .github/workflows/create-runner.yaml + +jobs: + build-docker: + runs-on: ubuntu-latest + env: + UNITY_MODULES: webgl android ios mac-mono windows-mono linux-il2cpp + + environment: + name: Docker Hub + + name: Build + steps: + - uses: actions/checkout@v4 + + - uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Get Unity Version + id: unity-version + run: | + VERSION=$(head -n 1 versions.txt) + echo "UNITY_VERSION=$VERSION" >> $GITHUB_ENV + echo "Unity Version: $VERSION" + + - name: Docker Build + run: .gitea/workflows/scripts/build-runner-image.sh + id: build-image + env: + UNITY_VERSION: ${{ env.UNITY_VERSION }} + UNITY_MODULES: ${{ env.UNITY_MODULES }} + GAMECI_VERSION: ${{ env.GAMECI_VERSION }} + GAMECI_OS: ubuntu + IMAGE: "${{ vars.DOCKERHUB_USERNAME }}/unity-runner" + + - name: Docker Push + run: | + echo "Pushing Docker Image ${{ steps.build-image.outputs.FULL_IMAGE }}" + echo "- Image: ${{ steps.build-image.outputs.IMAGE }}" + echo "- Tag: ${{ steps.build-image.outputs.TAG }}" + docker push ${{ steps.build-image.outputs.FULL_IMAGE }} \ No newline at end of file diff --git a/dockerfiles/individual.dockerfile b/dockerfiles/individual.dockerfile new file mode 100644 index 0000000..fd7f140 --- /dev/null +++ b/dockerfiles/individual.dockerfile @@ -0,0 +1,41 @@ +ARG BASE_IMAGE=unityci/editor + +FROM $BASE_IMAGE +RUN apt-get update && \ + apt-get install -y \ + git \ + curl \ + gcc \ + make \ + libssl-dev \ + zlib1g-dev \ + libsqlite3-dev + +# Set up the scripts +RUN git clone --depth=1 https://github.com/game-ci/unity-builder.git /gameci && \ + cp -rf /gameci/dist/platforms/ubuntu/steps /steps && \ + cp -rf /gameci/dist/default-build-script /UnityBuilderAction && \ + cp /gameci/dist/platforms/ubuntu/entrypoint.sh /entrypoint.sh + +# Set up Node.js environment for github actions +RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ + apt-get install -y nodejs && \ + npm install -g npm@latest + +# Install Blender +ARG BLENDER_SHORT_VERSION=3.4 +ARG BLENDER_FULL_VERSION=3.4.1 +RUN echo "BLENDER_FULL_VERSION: $BLENDER_FULL_VERSION" && \ + echo echo "BLENDER_SHORT_VERSION: $BLENDER_SHORT_VERSION" && \ + apt-get install -y wget && \ + wget https://download.blender.org/release/Blender$BLENDER_SHORT_VERSION/blender-$BLENDER_FULL_VERSION-linux-x64.tar.xz && \ + tar -xf blender-$BLENDER_FULL_VERSION-linux-x64.tar.xz && \ + rm blender-$BLENDER_FULL_VERSION-linux-x64.tar.xz +ENV PATH="$PATH:/blender-$BLENDER_FULL_VERSION-linux-x64" + +# Add custom scripts +COPY scripts/build.sh /build.sh +RUN chmod +x /build.sh + +# Done +ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file diff --git a/Dockerfile b/dockerfiles/runner.dockerfile similarity index 88% rename from Dockerfile rename to dockerfiles/runner.dockerfile index 645ea18..1c62e0c 100644 --- a/Dockerfile +++ b/dockerfiles/runner.dockerfile @@ -7,10 +7,9 @@ ARG HUB_IMAGE="unityci/hub" FROM $HUB_IMAGE AS builder # Install editor ARG VERSION -ARG CHANGE_SET -RUN unity-hub install --version "$VERSION" --changeset "$CHANGE_SET" | \ - tee /var/log/install-editor.log && grep 'Failed to install\|Error while installing an editor\|Completed with errors' /var/log/install-editor.log | \ - exit $(wc -l) +ARG CHANGESET +RUN unity-hub install --version "$VERSION" --changeset "$CHANGESET" \ + | tee /var/log/install-editor.log && grep 'Failed to install\|Error while installing an editor\|Completed with errors' /var/log/install-editor.log | exit $(wc -l) # Install modules for that editor ARG MODULE="non-existent-module" @@ -35,12 +34,17 @@ RUN echo "$VERSION-$MODULE" | grep -q -vP '^(2021.2.(?![0-4](?![0-9]))|2021.[3-9 || unity-hub install-modules --version "$VERSION" --module "windows-server" --childModules | \ tee /var/log/install-module-windows-server.log && grep 'Missing module' /var/log/install-module-windows-server.log | exit $(wc -l); - - ########################### # Editor # ########################### FROM $BASE_IMAGE + +# Always put "Editor" and "modules.json" directly in $UNITY_PATH +ARG VERSION +ARG MODULE +COPY --from=builder /opt/unity/editors/$VERSION/ "$UNITY_PATH/" +RUN echo $VERSION > "$UNITY_PATH/version" + RUN apt-get update && \ apt-get install -y \ git \ @@ -78,4 +82,4 @@ COPY scripts/build.sh /build.sh RUN chmod +x /build.sh # Done -ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file +# ENTRYPOINT [ "/bin/bash" ] \ No newline at end of file diff --git a/test.sh b/test.sh deleted file mode 100644 index 1091168..0000000 --- a/test.sh +++ /dev/null @@ -1,4 +0,0 @@ -UNITY_VERSION=6000.0.35f1 \ -UNITY_MODULES="webgl linux-server windows-mono mac-mono linux-il2cpp" \ -IMAGE=docker.lakes.house/unityci/editor \ - ./.gitea/workflows/scripts/build-runner-image.sh \ No newline at end of file