|
| 1 | +name: docker |
| 2 | +description: Installs `docker` for Serai |
| 3 | + |
| 4 | +runs: |
| 5 | + using: "composite" |
| 6 | + steps: |
| 7 | + - name: Remove preinstalled Docker |
| 8 | + if: runner.os == 'Linux' |
| 9 | + shell: bash |
| 10 | + run: | |
| 11 | + docker system prune --all --force |
| 12 | +
|
| 13 | + sudo apt remove -y *docker* |
| 14 | +
|
| 15 | + # Install `uidmap`, required for the explicitly-installed rootless Docker |
| 16 | + sudo apt install -y uidmap |
| 17 | +
|
| 18 | + - name: Install rootless Docker (Linux) |
| 19 | + uses: docker/setup-docker-action@1a6edb0ba9ac496f6850236981f15d8f9a82254d # 5.0.0 |
| 20 | + if: runner.os == 'Linux' |
| 21 | + with: |
| 22 | + rootless: true |
| 23 | + set-host: true |
| 24 | + # https://github.com/moby/moby/issues/45014 |
| 25 | + daemon-config: | |
| 26 | + { |
| 27 | + "exec-opts": ["native.cgroupdriver=cgroupfs"] |
| 28 | + } |
| 29 | +
|
| 30 | + - name: Remove preinstalled Docker |
| 31 | + if: runner.os == 'macOS' |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + # Docker isn't pre-installed on macOS images, so we solely have to confirm it isn't |
| 35 | + if [ $(command -v docker; printf $?) -eq 0 ]; then |
| 36 | + echo "\`docker`` was pre-installed" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | +
|
| 40 | + - name: Get the arguments to start Lima with |
| 41 | + shell: bash |
| 42 | + if: runner.os == 'macOS' |
| 43 | + run: | |
| 44 | + if [ $(uname -m) = "x86_64" ]; then |
| 45 | + # On Intel CPUs, where we can use the Virtualization Framework, we do so |
| 46 | + echo "LIMA_START_ARGS=--vm-type=vz --mount-type=virtiofs" >> "$GITHUB_ENV" |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Install Docker (macOS) |
| 50 | + uses: docker/setup-docker-action@1a6edb0ba9ac496f6850236981f15d8f9a82254d # 5.0.0 |
| 51 | + if: runner.os == 'macOS' |
| 52 | + env: |
| 53 | + # m1 chips, as seen in the GitHub CI, don't support nested hardware virtualization. |
| 54 | + # |
| 55 | + # We need `-machine virt` to stop Lima from providing `accel=hvf`due to this |
| 56 | + # [QEMU issue](https://gitlab.com/qemu-project/qemu/-/issues/2981). |
| 57 | + # |
| 58 | + # We also need `-cpu *` to stop Lima from providing `-cpu host` as: |
| 59 | + # 1) `-cpu host` requires `kvm` or `hvf` (which we don't have) |
| 60 | + # 2) `-cpu host` implies `host-phys-bits=on` which is borked in this environment |
| 61 | + # From which CPU to actually emulate, we choose what will be the most performant. |
| 62 | + # |
| 63 | + # We accomplish both of these goals with the methodology from |
| 64 | + # [this comment](https://github.com/lima-vm/lima/pull/3173#issuecomment-2623130310). |
| 65 | + QEMU_SYSTEM_AARCH64: "qemu-system-aarch64 -machine virt -cpu max,pmu=off,sve=on,sve128=on,sme=off,pauth=off" |
| 66 | + with: |
| 67 | + set-host: true |
| 68 | + |
| 69 | + - name: Install `buildx` |
| 70 | + if: runner.os == 'macOS' |
| 71 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # 4.0.0 |
| 72 | + with: |
| 73 | + # This is Docker's default, but `setup-buildx-action` defaults to `docker-container` |
| 74 | + # (for _some_ reason) which means built images won't be loaded into Docker (`--load`) by |
| 75 | + # default. We want that behavior. |
| 76 | + driver: docker |
| 77 | + |
| 78 | + - name: Remove preinstalled Docker |
| 79 | + if: runner.os == 'Windows' |
| 80 | + shell: pwsh |
| 81 | + run: | |
| 82 | + docker system prune --all --force |
| 83 | +
|
| 84 | + # GitHub uses an install script from Microsoft, so we run the complimentary uninstall script |
| 85 | + Invoke-WebRequest https://raw.githubusercontent.com/microsoft/Windows-Containers/Main/helpful_tools/Install-DockerCE/uninstall-docker-ce.ps1 -OutFile .\uninstall-docker-ce.ps1 |
| 86 | + & .\uninstall-docker-ce.ps1 -Force |
| 87 | +
|
| 88 | + # These are defined/installed by the GitHub runner image definition |
| 89 | + # GitHub also adds Docker Compose, but to Docker's directory, causing it to be removed when Docker is |
| 90 | + Remove-Item -LiteralPath C:\Windows\SysWOW64\docker.exe -Force |
| 91 | + Remove-Item -LiteralPath C:\Windows\System32\docker-credential-wincred.exe -Force |
| 92 | +
|
| 93 | + # The preinstalled Docker, and Docker from `setup-docker-action`, do not allow running Linux |
| 94 | + # containers. We manually install `podman` to workaround this. Alternatively, we could install |
| 95 | + # 'Docker Desktop' and run `docker desktop engine use linux`, but 'Docker Desktop' is a |
| 96 | + # pseudo-enterprise product and it isn't worth installing/configuring it compared to installing |
| 97 | + # a more direct solution which behaves as a drop-in replacement _to the degree we need it_. |
| 98 | + - name: Install Podman (Windows) |
| 99 | + if: runner.os == 'Windows' |
| 100 | + shell: pwsh |
| 101 | + run: | |
| 102 | + Invoke-WebRequest https://github.com/containers/podman/releases/download/v5.8.1/podman-installer-windows-amd64.msi -OutFile podman.msi |
| 103 | + Start-Process -Wait -PassThru 'msiexec' -ArgumentList "/package podman.msi /quiet /log podman-msi.log MACHINE_PROVIDER=wsl ALLUSERS=1" |
| 104 | + Get-Content podman-msi.log |
| 105 | +
|
| 106 | + $env:PATH += ';C:\Program Files\Podman' |
| 107 | +
|
| 108 | + # Start Podman |
| 109 | + podman machine init |
| 110 | + podman machine start |
| 111 | +
|
| 112 | + # Claim `podman` is `docker`, as we expect `docker` |
| 113 | + # Installing to `System32` is gross, but functional and where `docker.exe` was pre-installed |
| 114 | + New-Item -ItemType SymbolicLink -Path 'C:\Windows\System32\docker.exe' -Target (Get-Command podman).Path |
| 115 | +
|
| 116 | + # When cross-compiling to a target architecture, the host still impacts the result. For our |
| 117 | + # runtime, a WASM blob which should be exactly reproducible, we fix the builder to x86-64 |
| 118 | + # accordingly. This requires we be able to run a x86-64 userspace. |
| 119 | + - name: Install x64 Qemu for non-x64 Docker |
| 120 | + if: (runner.os != 'Windows') && (runner.arch != 'X64') |
| 121 | + uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # 4.0.0 |
| 122 | + with: |
| 123 | + platforms: amd64 |
| 124 | + |
| 125 | + # This ensures we have a consistent clean build, there aren't any issues from any version of |
| 126 | + # `docker` we removed before installing our current version, and checks that `docker` was in |
| 127 | + # fact installed and can be successfully called. |
| 128 | + - name: Ensure there's no Docker cache |
| 129 | + shell: bash |
| 130 | + run: docker system prune --all --force |
0 commit comments