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 98% rename from .gitea/workflows/scripts/build-image.sh rename to .gitea/workflows/scripts/build-individual-image.sh index bc51702..fdb9226 --- a/.gitea/workflows/scripts/build-image.sh +++ b/.gitea/workflows/scripts/build-individual-image.sh @@ -86,7 +86,7 @@ docker build \ ${ADDITIONAL_TAGS} \ -t ${FULL_IMAGE} \ ${DOCKER_BUILD_ARGS} \ - . + -f ./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 new file mode 100644 index 0000000..c3648a8 --- /dev/null +++ b/.gitea/workflows/scripts/build-runner-image.sh @@ -0,0 +1,114 @@ +#!/bin/sh +# Ensure UNITY_VERSION is set, pull from arguments if not +if [ -z "${UNITY_VERSION}" ]; then + if [ -n "$1" ]; then + UNITY_VERSION=$1 + else + echo "Error: UNITY_VERSION is not set." + exit 1 + fi +fi + +# Fetch the changelog and extract the changeset ID for the specified Unity version +# 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 +if [ -z "${UNITY_MODULES}" ]; then + if [ -n "$3" ]; then + UNITY_MODULES=$3 + else + echo "Error: UNITY_MODULES is not set." + exit 1 + fi +fi + +# Ensure IMAGE is set, pull from arguments if not +if [ -z "${IMAGE}" ]; then + if [ -n "$3" ]; then + IMAGE=$3 + else + echo "Error: IMAGE is not set." + exit 1 + fi +fi + +# Ensure GAME_CI_VERSION is set, default to 3 if not +if [ -z "${GAMECI_VERSION}" ]; then + GAMECI_VERSION=3 +fi + +# Ensure IMAGE_OS is set, default to ubuntu if not +if [ -z "${GAMECI_OS}" ]; then + + # windows-il2cpp requires windows OS + if [ "${UNITY_PLATFORM}" = "windows-il2cpp" ]; then + GAMECI_OS="windows" + else + GAMECI_OS="ubuntu" + fi + + # TODO: MacOS probably requires a mac image. + # Might be worth just putting this in the strategy at this point +fi + +# Ensure PLATFORM is set, default to the current system if not +if [ -z "${PLATFORM}" ]; then + PLATFORM=$(uname -m) + case "${PLATFORM}" in + x86_64) PLATFORM="linux/amd64" ;; + arm64) PLATFORM="linux/arm64" ;; + *) + echo "Error: Unsupported platform ${PLATFORM}." + exit 1 + ;; + esac +fi + +# Ensure some additional build settings are set +if [ -z "${DOCKER_BUILD_ARGS}" ]; then + DOCKER_BUILD_ARGS="" +fi + +BASE_TAG=${GAMECI_OS}-${UNITY_VERSION}-base-${GAMECI_VERSION} +BASE_IMAGE=unityci/editor:${BASE_TAG} +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}" +echo "- Image: ${DEST_IMAGE}" + +docker buildx 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} \ + -f ./dockerfiles/runner.dockerfile . + +if [ $? -ne 0 ]; then + echo "Error: Docker build failed." + exit 1 +fi + +# Export IMAGE and TAG for GitHub Actions +if [ -n "$GITHUB_OUTPUT" ]; then + echo "IMAGE=${IMAGE}" >> $GITHUB_OUTPUT + echo "TAG=$DEST_TAG" >> $GITHUB_OUTPUT + echo "FULL_IMAGE=${DEST_IMAGE}" >> $GITHUB_OUTPUT +fi 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/README.md b/README.md index 71eeccd..9c3db94 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,13 @@ A table of available Docker images for Unity CI/CD: |---------|----------|----------|----------|----------|----------|----------| | 6000.0.35f1 |[🐳 View](https://docker.lakes.house/unityci/editor/tag/ubuntu-6000.0.35f1-android-runner) |[🐳 View](https://docker.lakes.house/unityci/editor/tag/ubuntu-6000.0.35f1-ios-runner) |[🐳 View](https://docker.lakes.house/unityci/editor/tag/ubuntu-6000.0.35f1-linux-il2cpp-runner) |[🐳 View](https://docker.lakes.house/unityci/editor/tag/ubuntu-6000.0.35f1-mac-mono-runner) |[🐳 View](https://docker.lakes.house/unityci/editor/tag/ubuntu-6000.0.35f1-webgl-runner) |[🐳 View](https://docker.lakes.house/unityci/editor/tag/ubuntu-6000.0.35f1-windows-mono-runner) | + +# Usage + + + +TODO: +https://github.com/mob-sakai/unity-changeset/blob/main/src/unityGraphQL.ts + +use this library to get the change set. +Might as well orchestrate the build with it too. \ No newline at end of file diff --git a/Dockerfile b/dockerfiles/individual.dockerfile similarity index 100% rename from Dockerfile rename to dockerfiles/individual.dockerfile diff --git a/dockerfiles/runner.dockerfile b/dockerfiles/runner.dockerfile new file mode 100644 index 0000000..3cea866 --- /dev/null +++ b/dockerfiles/runner.dockerfile @@ -0,0 +1,85 @@ +ARG BASE_IMAGE=unityci/editor +ARG HUB_IMAGE="unityci/hub" + +########################### +# Builder # +########################### +FROM $HUB_IMAGE AS builder +# Install editor +ARG VERSION +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" +RUN for mod in $MODULE; do \ + if [ "$mod" = "base" ] ; then \ + echo "running default modules for this baseOs"; \ + else \ + unity-hub install-modules --version "$VERSION" --module "$mod" --childModules | tee /var/log/install-module-${mod}.log && \ + grep 'Missing module\|Completed with errors' /var/log/install-module-${mod}.log | exit $(wc -l); \ + fi \ + done \ + # Set execute permissions for modules + && chmod -R 755 /opt/unity/editors/$VERSION/Editor/Data/PlaybackEngines + +RUN echo "$VERSION-$MODULE" | grep -q -vP '^(2021.2.(?![0-4](?![0-9]))|2021.[3-9]|202[2-9]|[6-9][0-9]{3}|[1-9][0-9]{4,}).*linux' \ + && exit 0 \ + || unity-hub install-modules --version "$VERSION" --module "linux-server" --childModules | \ + tee /var/log/install-module-linux-server.log && grep 'Missing module' /var/log/install-module-linux-server.log | exit $(wc -l); + +RUN echo "$VERSION-$MODULE" | grep -q -vP '^(2021.2.(?![0-4](?![0-9]))|2021.[3-9]|202[2-9]|[6-9][0-9]{3}|[1-9][0-9]{4,}).*windows' \ + && exit 0 \ + || 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 \ + 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 [ "/bin/bash" ]~ \ No newline at end of file diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..1589d55 --- /dev/null +++ b/test.sh @@ -0,0 +1,5 @@ +UNITY_VERSION=6000.0.35f1 \ +UNITY_CHANGESET="9a3bc604008a" \ +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