-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
name: "Docker Desktop action" | ||
description: "Start Docker Desktop on a Github Action node" | ||
inputs: | ||
docker-desktop-build-url: | ||
description: "Docker Desktop build url to use for installation" | ||
required: false | ||
default: "latest" | ||
username: | ||
description: "username on the node" | ||
required: false | ||
default: "runner" | ||
env: | ||
description: "env variables to pass when running Desktop, as a JSON string" | ||
required: false | ||
default: "{}" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Bloc calls to segment.io | ||
id: redirect-segment | ||
shell: bash | ||
run: | | ||
cat /etc/hosts | grep '127.0.0.2 api.segment.io' || echo '127.0.0.2 api.segment.io' | sudo tee -a /etc/hosts | ||
cat /etc/hosts | grep '127.0.0.2 api.segment.io' # Ensure the segment line is there | ||
- name: Install macOS Docker Desktop dmg | ||
if: runner.os == 'macOS' | ||
shell: bash | ||
env: ${{fromJson(inputs.env)}} | ||
run: | | ||
sw_vers | ||
mkdir ./temp | ||
mkdir ./mount | ||
buildUrl=${{ inputs.docker-desktop-build-url }} | ||
if [[ "$buildUrl" == "latest" ]]; then | ||
buildUrl="https://desktop.docker.com/mac/main/amd64/Docker.dmg" | ||
fi | ||
curl --fail -o ./temp/DockerDesktop.dmg $buildUrl | ||
/usr/bin/hdiutil attach -noverify ./temp/DockerDesktop.dmg -mountpoint ./mount/desktop -nobrowse | ||
echo "dmg mounted" | ||
sudo ./mount/desktop/Docker.app/Contents/MacOS/install --accept-license | ||
echo "dmg installed" | ||
echo "ls /Library/Application Support/com.docker.docker" | ||
ls "/Library/Application Support/com.docker.docker" || true | ||
mkdir -p ./cache/desktopInstallSettings | ||
cp "/Library/Application Support/com.docker.docker/"* ./cache/desktopInstallSettings/ | ||
echo "ls ./cache/desktopInstallSettings/" | ||
ls ./cache/desktopInstallSettings/ || true | ||
/usr/bin/hdiutil detach ./mount/desktop | ||
echo "dmg unmounted" | ||
- name: Install macOS Docker Desktop app | ||
if: runner.os == 'macOS' | ||
shell: bash | ||
env: ${{fromJson(inputs.env)}} | ||
run: | | ||
sudo mkdir -p /Library/PrivilegedHelperTools | ||
sudo /Applications/Docker.app/Contents/MacOS/install config --user ${{inputs.username}} | ||
sudo /Applications/Docker.app/Contents/MacOS/install vmnetd | ||
echo "app installed" | ||
/usr/bin/open /Applications/Docker.app --args --unattended --add-host-docker-internal-registry | ||
echo "Docker starting..." | ||
- name: Download appcast | ||
if: runner.os == 'Linux' | ||
shell: bash | ||
run: | | ||
curl https://desktop.docker.com/linux/main/amd64/appcast.xml --fail -o appcast.xml | ||
- name: Get Docker Desktop latest build url | ||
if: runner.os == 'Linux' && inputs.docker-desktop-build-url == 'latest' | ||
uses: mavrosxristoforos/[email protected] | ||
id: get-latest-build-url | ||
with: | ||
xml-file: appcast.xml | ||
xpath: //channel/link | ||
|
||
- name: Define the build URL to use | ||
if: runner.os == 'Linux' | ||
id: get-build-url | ||
shell: bash | ||
run: | | ||
buildUrl=${{ inputs.docker-desktop-build-url }} | ||
if [[ "$buildUrl" == "latest" ]]; then | ||
buildUrl=${{ steps.get-latest-build-url.outputs.info }} | ||
fi | ||
echo "build-url=$buildUrl" >> $GITHUB_OUTPUT | ||
- name: Cache Docker Desktop packages | ||
if: runner.os == 'Linux' | ||
id: cache-docker-desktop | ||
uses: actions/cache@v3 | ||
with: | ||
key: "docker-desktop-4.25.0-amd64" | ||
path: | | ||
~/downloads/ | ||
- name: Download Docker Desktop | ||
if: runner.os == 'Linux' && steps.cache-docker-desktop.outputs.cache-hit != 'true' | ||
shell: bash | ||
run: | | ||
mkdir -p ~/.downloads | ||
curl --fail -sSL ${{ steps.get-build-url.outputs.build-url }} > ~/.downloads/docker-desktop.deb | ||
- name: Check for CPU with VM support | ||
if: runner.os == 'Linux' | ||
shell: bash | ||
run: | | ||
egrep '(vmx|svm)' /proc/cpuinfo | ||
# https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/ | ||
- name: Enable KVM group perms | ||
if: runner.os == 'Linux' | ||
shell: bash | ||
run: | | ||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | ||
sudo udevadm control --reload-rules | ||
sudo udevadm trigger --name-match=kvm | ||
- name: Install and Run Docker Desktop | ||
if: runner.os == 'Linux' | ||
shell: bash | ||
env: ${{fromJson(inputs.env)}} | ||
run: | | ||
sudo add-apt-repository universe | ||
sudo apt update -y | ||
sudo apt-get install ca-certificates curl gnupg | ||
sudo install -m 0755 -d /etc/apt/keyrings | ||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | ||
sudo chmod a+r /etc/apt/keyrings/docker.gpg | ||
echo \ | ||
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | ||
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ | ||
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | ||
sudo apt update -y | ||
sudo apt remove moby-cli moby-compose moby-buildx | ||
sudo apt install qemu-kvm | ||
sudo apt install ~/.downloads/docker-desktop.deb qemu-kvm | ||
mkdir -p ~/.docker/desktop | ||
echo '{"settingsVersion": 30, "licenseTermsVersion": 2}' > ~/.docker/desktop/settings.json | ||
docker context create desktop-linux --docker host=unix://${HOME}/.docker/desktop/docker.sock --description "Docker Desktop" | ||
docker context use desktop-linux | ||
/opt/docker-desktop/bin/com.docker.backend & | ||
- name: Wait for Docker to be up and running | ||
shell: bash | ||
run: | | ||
until docker ps; do echo "docker not ready, sleep 10 s and try again"; sleep 10; done | ||
echo "Docker started and ready" | ||
docker version |