Build in a container with GitHub Actions
Run containerized Unity builds from a GitHub Actions workflow on a self-hosted runner.
読み終わるまでの所要時間 2 分最終更新 5日前
Run containerized Unity builds from a GitHub Actions workflow on a self-hosted runner.
GitHub Actions can run a job's steps inside a container started from your Editor image. This example builds your project for the Web platform, caches the folder between runs, and uploads the build as an artifact.
LibraryPrerequisites
- An Editor image in a registry your build agent can pull from. For more information, refer to Build a Unity Editor Docker image.
- A self-hosted runner on a Linux x64 machine on the same private network as your license server.
- A license server configuration file, , at
services-config.jsonon the runner machine. For the file's content, refer to Build with Unity in a Docker container./etc/unity/services-config.json - The user or group that the container's actions run as has write access to the files and folders mounted into the container.
- and
gitinstalled in your Editor image. Thegit-lfsstep runs inside the container, so it can't use the runner machine's Git to check out the repository and its Git LFS files.actions/checkout - A build method in your project, such as in Run the build.
BuildScript.BuildWeb
Add the build workflow
To add the build workflow:
-
Create a workflow file in your repository, such as, with the following content:
.github/workflows/build-web.ymlname: Build for Webon: push: workflow_dispatch:jobs: build-web: runs-on: [self-hosted, linux, x64] container: image: ghcr.io/my-studio/unity-editor:6000.7.0f1-webgl-android options: >- --shm-size=8g -v /etc/unity/services-config.json:/usr/share/unity3d/config/services-config.json:ro steps: - uses: actions/checkout@v4 with: lfs: true - uses: actions/cache@v4 with: path: Library key: library-web-${{ hashFiles('Packages/packages-lock.json') }} - name: Build run: >- /opt/unity/editors/6000.7.0f1/Editor/Unity -batchmode -nographics -projectPath . -buildTarget WebGL -executeMethod BuildScript.BuildWeb -logFile - -quit - uses: actions/upload-artifact@v4 with: name: web path: Build/WebThe workflow runs on every push and on demand. Thesection starts the job in your Editor image with 8 GB of shared memory and mounts the license server configuration file read-only. Thecontainerstep saves and restores theactions/cachefolder under a key derived fromLibrary, so jobs reuse thePackages/packages-lock.jsonfolder until your packages change.Library -
Commit the workflow file and push it to your repository.
GitHub Actions runs the build on your self-hosted runner and uploads the Web build as the artifact. If the build method fails, the Editor exits with a nonzero code and the job fails.
web