Skip to content

Commit

Permalink
install docker on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Nov 1, 2023
1 parent 41addce commit 4ae324b
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
154 changes: 154 additions & 0 deletions dist/setup-docker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
const exec = require("@actions/exec");
const core = require("@actions/core");
const os = require("os");
const DOCKER_CLI_EXPERIMENTAL = core.getInput("docker_cli_experimental");
const DOCKER_DAEMON_JSON = core.getInput("docker_daemon_json");
const DOCKER_BUILDX = core.getInput("docker_buildx");
const systemExec = require("child_process").exec;
async function shell(cmd) {
return await new Promise((resolve, reject) => {
systemExec(cmd, function (error, stdout, stderr) {
if (error) {
reject(error);
}
if (stderr) {
reject(stderr);
}
resolve(stdout.trim());
});
});
}
async function buildx() {
core.debug("set DOCKER_CLI_EXPERIMENTAL");
if (DOCKER_CLI_EXPERIMENTAL === "enabled") {
core.exportVariable("DOCKER_CLI_EXPERIMENTAL", "enabled");
}
if (DOCKER_BUILDX !== "true") {
core.info("buildx disabled");
return;
}
core.exportVariable("DOCKER_CLI_EXPERIMENTAL", "enabled");
await exec.exec("docker", ["buildx", "version"]).then(async () => {
// install buildx
core.startGroup("setup qemu");
await exec.exec("docker", [
"run",
"--rm",
"--privileged",
"ghcr.io/dpsigs/tonistiigi-binfmt:latest",
"--install",
"all",
]);
core.endGroup();
core.startGroup("list /proc/sys/fs/binfmt_misc");
await exec.exec("ls -la", ["/proc/sys/fs/binfmt_misc"]).catch(() => { });
core.endGroup();
core.startGroup("create buildx instance");
await exec.exec("docker", [
"buildx",
"create",
"--use",
"--name",
"mybuilder",
"--driver",
"docker-container",
"--driver-opt",
// 'image=moby/buildkit:master'
// moby/buildkit:buildx-stable-1
"image=ghcr.io/dpsigs/moby-buildkit:master",
// $ docker pull moby/buildkit:master
// $ docker tag moby/buildkit:master ghcr.io/dpsigs/moby-buildkit:master
// $ docker push ghcr.io/dpsigs/moby-buildkit:master
]);
core.endGroup();
core.startGroup("inspect buildx instance");
await exec.exec("docker", ["buildx", "inspect", "--bootstrap"]);
core.endGroup();
}, () => {
core.info("this docker version NOT Support Buildx");
});
}
export async function installDocker() {
const platform = os.platform();
if (platform === "win32") {
core.debug("check platform");
await exec.exec("echo", [
`::error::Only Support macOS platform, this platform is ${os.platform()}`,
]);
return;
}
if (platform === "darwin") {
// macos
if (os.arch() !== "x64") {
core.warning("only support macOS x86_64, os arch is " + os.arch());
return;
}
core.exportVariable("DOCKER_CONFIG", "/Users/runner/.docker");
await exec.exec("docker", ["--version"]).catch(() => { });
await exec.exec("docker-compose", ["--version"]).catch(() => { });
core.startGroup("install docker");
// await exec.exec('brew', ['update'])
await exec.exec("wget", [
"https://raw.githubusercontent.com/Homebrew/homebrew-cask/fe866ec0765de141599745f03e215452db7f511b/Casks/docker.rb",
]);
// await exec.exec('wget', ['https://raw.githubusercontent.com/Homebrew/homebrew-cask/master/Casks/docker.rb']);
await exec.exec("brew", [
"install",
"--cask",
// DOCKER_CHANNEL !== 'stable' ? 'docker' : 'docker',
"docker.rb",
]);
core.endGroup();
await exec.exec("mkdir", ["-p", "/Users/runner/.docker"]);
await shell(`echo '${DOCKER_DAEMON_JSON}' | sudo tee /Users/runner/.docker/daemon.json`);
core.startGroup("show daemon json content");
await exec.exec("cat", ["/Users/runner/.docker/daemon.json"]);
core.endGroup();
core.startGroup("start docker step1");
// https://github.com/docker/for-mac/issues/2359#issuecomment-943131345
await exec.exec("sudo", [
"/Applications/Docker.app/Contents/MacOS/Docker",
"--unattended",
"--install-privileged-components",
]);
core.endGroup();
core.startGroup("start docker step2");
await exec.exec("open", [
"-a",
"/Applications/Docker.app",
"--args",
"--unattended",
"--accept-license",
]);
core.endGroup();
core.startGroup("wait docker running");
await exec.exec("sudo", [
"bash",
"-c",
`
set -x
command -v docker || echo 'test docker command 1: not found'
i=0
while ! /Applications/Docker.app/Contents/Resources/bin/docker system info &>/dev/null; do
(( i++ == 0 )) && printf %s '-- Waiting for Docker to finish starting up...' || printf '.'
command -v docker || echo 'test docker command loop: not found'
sleep 1
# wait 180s(3min)
if [ $i -gt 180 ];then exit 1;sudo /Applications/Docker.app/Contents/MacOS/com.docker.diagnose check;uname -a;system_profiler SPHardwareDataType;echo "::error::-- Wait docker start $i s too long, exit"; exit 1; fi
done
echo "::notice::-- Docker is ready.Wait time is $i s"
uname -a || true
system_profiler SPHardwareDataType || true
`,
]);
core.endGroup();
core.startGroup("docker version");
await exec.exec("docker", ["version"]);
core.endGroup();
core.startGroup("docker info");
await exec.exec("docker", ["info"]);
core.endGroup();
await core.group("set up buildx", buildx);
return;
}
}
2 changes: 2 additions & 0 deletions dist/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { homedir } from "node:os";
import { join } from "node:path";
import * as action from "@actions/core";
import { getExecOutput, exec } from "@actions/exec";
import { installDocker } from "./setup-docker";
export default async () => {
// throw error on unsupported platforms (windows)
if (process.platform === "win32") {
throw new Error("FluentCI is not supported on Windows");
}
await installDocker();
await exec("sh", [
"-c",
"curl -fsSL https://deno.land/x/install/install.sh | sh",
Expand Down

0 comments on commit 4ae324b

Please sign in to comment.