@docker/actions-toolkit
Version:
Toolkit for Docker (GitHub) Actions
22 lines (21 loc) • 11.3 kB
TypeScript
/**
* Copyright 2023 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export declare const setupDockerWinPs1: () => string;
export declare const dockerServiceLogsPs1: () => string;
export declare const limaYaml: () => string;
export declare const setupDockerWinPs1Data = "\n[CmdletBinding()]\nparam(\n [Parameter(Mandatory = $true)]\n [string]$ToolDir,\n\n [Parameter(Mandatory = $true)]\n [string]$RunDir,\n\n [Parameter(Mandatory = $true)]\n [string]$DockerHostSocket,\n\n [Parameter(Mandatory = $false)]\n [string]$DockerHostTCP,\n\n [Parameter(Mandatory = $false)]\n [string]$DaemonConfig)\n\n$pwver = (Get-ItemProperty -Path HKLM:\\SOFTWARE\\Microsoft\\PowerShell\\3\\PowerShellEngine -Name 'PowerShellVersion').PowerShellVersion\nWrite-Host \"PowerShell version: $pwver\"\n\n# Create run directory\nNew-Item -ItemType Directory \"$RunDir\" -ErrorAction SilentlyContinue | Out-Null\n\n# Remove existing service\nif (Get-Service docker -ErrorAction SilentlyContinue) {\n $dockerVersion = (docker version -f \"{{.Server.Version}}\")\n Write-Host \"Current installed Docker version: $dockerVersion\"\n # stop service\n Stop-Service -Force -Name docker\n Write-Host \"Service stopped\"\n # remove service\n sc.exe delete \"docker\"\n # removes event log entry. we could use \"Remove-EventLog -LogName -Source docker\"\n # but this cmd is not available atm\n $ErrorActionPreference = \"SilentlyContinue\"\n & reg delete \"HKLM\\SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\docker\" /f 2>&1 | Out-Null\n $ErrorActionPreference = \"Stop\"\n Write-Host \"Service removed\"\n}\n\n$env:Path = \"$ToolDir;\" + [System.Environment]::GetEnvironmentVariable(\"Path\",\"Machine\") + \";\" + [System.Environment]::GetEnvironmentVariable(\"Path\",\"User\")\nWrite-Host \"Path: $env:Path\"\n\n$env:DOCKER_HOST = $DockerHostSocket\nWrite-Host \"DOCKER_HOST: $env:DOCKER_HOST\"\n\nif ($DaemonConfig) {\n Write-Host \"Writing Docker daemon config\"\n New-Item -ItemType Directory -Force -Path \"$env:ProgramData\\Docker\\config\"\n $DaemonConfig | Out-File -FilePath \"$env:ProgramData\\Docker\\config\\daemon.json\"\n}\n\n$arguments = @(\n \"--host=$DockerHostSocket\",\n \"--data-root=$RunDir\\\\moby-root\",\n \"--exec-root=$RunDir\\\\moby-exec\",\n \"--pidfile=$RunDir\\\\docker.pid\",\n \"--register-service\"\n)\nif ($DockerHostTCP) {\n $arguments += \"--host=$DockerHostTCP\"\n}\n\nWrite-Host \"Creating service\"\nNew-Item -ItemType Directory \"$RunDir\\moby-root\" -ErrorAction SilentlyContinue | Out-Null\nNew-Item -ItemType Directory \"$RunDir\\moby-exec\" -ErrorAction SilentlyContinue | Out-Null\nStart-Process -Wait -NoNewWindow \"$ToolDir\\dockerd\" -ArgumentList $arguments\nWrite-Host \"Starting service\"\nStart-Service -Name docker\nWrite-Host \"Service started successfully!\"\n\n$tries=20\nWrite-Host \"Waiting for Docker daemon to start...\"\nWhile ($true) {\n $ErrorActionPreference = \"SilentlyContinue\"\n & \"$ToolDir\\docker\" version | Out-Null\n $ErrorActionPreference = \"Stop\"\n If ($LastExitCode -eq 0) {\n break\n }\n $tries--\n If ($tries -le 0) {\n Throw \"Failed to get a response from Docker daemon\"\n }\n Write-Host -NoNewline \".\"\n Start-Sleep -Seconds 1\n}\nWrite-Host \"Docker daemon started successfully!\"\n";
export declare const dockerServiceLogsPs1Data = "\nGet-WinEvent -ea SilentlyContinue `\n -FilterHashtable @{ProviderName= \"docker\"; LogName = \"application\"} |\n Sort-Object @{Expression=\"TimeCreated\";Descending=$false} |\n ForEach-Object {\"$($_.TimeCreated.ToUniversalTime().ToString(\"o\")) [$($_.LevelDisplayName)] $($_.Message)\"}\n";
export declare const limaYamlData = "\n# Source: https://github.com/lima-vm/lima/blob/master/templates/docker-rootful.yaml\n\n# VM type: \"qemu\" or \"vz\" (on macOS 13 and later).\n# The vmType can be specified only on creating the instance.\n# The vmType of existing instances cannot be changed.\n# Builtin default: \"qemu\"\nvmType: qemu\n\n# OS: \"Linux\".\n# Builtin default: \"Linux\"\nos: null\n\n# Arch: \"default\", \"x86_64\", \"aarch64\".\n# Builtin default: \"default\" (corresponds to the host architecture)\narch: null\n\nimages:\n{{#each customImages}}\n- location: \"{{location}}\"\n arch: \"{{arch}}\"\n digest: \"{{digest}}\"\n{{/each}}\n- location: \"https://cloud-images.ubuntu.com/releases/24.04/release-20250228/ubuntu-24.04-server-cloudimg-amd64.img\"\n arch: \"x86_64\"\n digest: \"sha256:a3aea891c930ee0c762077b963834f5e083eb8102574f1e4dfc9e6e4c1c73ac0\"\n kernel:\n location: \"https://cloud-images.ubuntu.com/releases/24.04/release-20250228/unpacked/ubuntu-24.04-server-cloudimg-amd64-vmlinuz-generic\"\n digest: \"sha256:2d9f30959f01675fd28aa1c2fe8934728e46766d04ecfad2d206823696a3f830\"\n cmdline: \"root=LABEL=cloudimg-rootfs ro console=tty1 console=ttyAMA0 no_timer_check\"\n initrd:\n location: \"https://cloud-images.ubuntu.com/releases/24.04/release-20250228/unpacked/ubuntu-24.04-server-cloudimg-amd64-initrd-generic\"\n digest: \"sha256:231352d027aeebf0bb7dca281dfebae894c86e789c7377788d3c2c149471caa3\"\n- location: \"https://cloud-images.ubuntu.com/releases/24.04/release-20250228/ubuntu-24.04-server-cloudimg-arm64.img\"\n arch: \"aarch64\"\n digest: \"sha256:278a0e8475008673d9d3da10ae66a7b1a3dda059746b83d749eca386a5670bd4\"\n# Fallback to the latest release image.\n# Hint: run `limactl prune` to invalidate the cache\n- location: \"https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img\"\n arch: \"x86_64\"\n- location: \"https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img\"\n arch: \"aarch64\"\n\n# CPUs\n# Builtin default: min(4, host CPU cores)\ncpus: null\n\n# Memory size\n# Builtin default: min(\"4GiB\", half of host memory)\nmemory: null\n\n# Disk size\n# Builtin default: \"100GiB\"\ndisk: 60GiB\n\n# Expose host directories to the guest, the mount point might be accessible from all UIDs in the guest\n# Builtin default: null (Mount nothing)\n# This file: Mount the home as read-only, /tmp/lima as writable\nmounts:\n- location: \"~\"\n- location: \"/tmp/lima\"\n writable: true\n\n# Mount type for above mounts, such as \"reverse-sshfs\" (from sshocker), \"9p\" (EXPERIMENTAL, from QEMU\u2019s virtio-9p-pci, aka virtfs),\n# or \"virtiofs\" (EXPERIMENTAL, needs `vmType: vz`)\n# Builtin default: \"reverse-sshfs\" (for QEMU), \"virtiofs\" (for vz)\nmountType: null\n\ncontainerd:\n system: false\n user: false\n\nprovision:\n- mode: system\n # This script defines the host.docker.internal hostname when hostResolver is disabled.\n # It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts.\n # Names defined in /etc/hosts inside the VM are not resolved inside containers when\n # using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later).\n script: |\n #!/bin/sh\n sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts\n- mode: system\n script: |\n #!/bin/sh\n apt-get install -f -y iptables\n- mode: system\n script: |\n #!/bin/bash\n set -eux -o pipefail\n command -v docker >/dev/null 2>&1 && exit 0\n if [ ! -e /etc/systemd/system/docker.socket.d/override.conf ]; then\n mkdir -p /etc/systemd/system/docker.socket.d\n # Alternatively we could just add the user to the \"docker\" group, but that requires restarting the user session\n cat <<-EOF >/etc/systemd/system/docker.socket.d/override.conf\n [Socket]\n SocketUser=${LIMA_CIDATA_USER}\n EOF\n fi\n if [ ! -e /etc/docker/daemon.json ]; then\n mkdir -p /etc/docker\n cat <<-EOF >/etc/docker/daemon.json\n {{stringify daemonConfig}}\n EOF\n fi\n export DEBIAN_FRONTEND=noninteractive\n if [ \"{{srcType}}\" == \"archive\" ]; then\n curl -fsSL https://get.docker.com | sh -s -- --channel {{srcArchiveChannel}} --version {{srcArchiveVersion}}\n sed -i 's|^ExecStart=.*|ExecStart=/usr/bin/dockerd -H fd://{{#if localTCPPort}} -H tcp://0.0.0.0:2375{{/if}} --containerd=/run/containerd/containerd.sock|' /usr/lib/systemd/system/docker.service\n systemctl daemon-reload\n systemctl restart docker\n systemctl status docker.socket || true\n systemctl status docker.service || true\n elif [ \"{{srcType}}\" == \"image\" ]; then\n arch=$(uname -m)\n case $arch in\n x86_64) arch=amd64;;\n aarch64) arch=arm64;;\n esac\n url=\"https://github.com/crazy-max/undock/releases/download/v0.8.0/undock_0.8.0_linux_$arch.tar.gz\"\n\n wget \"$url\" -O /tmp/undock.tar.gz\n tar -C /usr/local/bin -xvf /tmp/undock.tar.gz\n undock --version\n\n HOME=/tmp undock moby/moby-bin:{{srcImageTag}} /usr/local/bin\n\n wget https://raw.githubusercontent.com/moby/moby/{{gitCommit}}/contrib/init/systemd/docker.service -O /etc/systemd/system/docker.service\n wget https://raw.githubusercontent.com/moby/moby/{{gitCommit}}/contrib/init/systemd/docker.socket -O /etc/systemd/system/docker.socket\n\n sed -i 's|^ExecStart=.*|ExecStart=/usr/local/bin/dockerd -H fd://{{#if localTCPPort}} -H tcp://0.0.0.0:2375{{/if}}|' /etc/systemd/system/docker.service\n sed -i 's|containerd.service||' /etc/systemd/system/docker.service\n if ! getent group docker; then\n groupadd --system docker\n fi\n systemctl daemon-reload\n fail=0\n if ! systemctl enable --now docker; then\n fail=1\n fi\n systemctl status docker.socket || true\n systemctl status docker.service || true\n exit $fail\n fi\n\nprobes:\n- script: |\n #!/bin/bash\n set -eux -o pipefail\n # Don't check for docker CLI as it's not installed in the VM (only on the host)\n if ! timeout 30s bash -c \"until pgrep dockerd; do sleep 3; done\"; then\n echo >&2 \"dockerd is not running\"\n exit 1\n fi\n hint: See \"/var/log/cloud-init-output.log\". in the guest\n\nhostResolver:\n # hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also\n # resolve inside containers, and not just inside the VM itself.\n hosts:\n host.docker.internal: host.lima.internal\n\nportForwards:\n- guestSocket: \"/var/run/docker.sock\"\n hostSocket: \"{{dockerSock}}\"\n{{#if localTCPPort}}\n- guestPort: 2375\n hostPort: {{localTCPPort}}\n{{/if}}\n\naudio:\n # EXPERIMENTAL\n # QEMU audiodev, e.g., \"none\", \"coreaudio\", \"pa\", \"alsa\", \"oss\".\n # VZ driver, use \"vz\" as device name\n # Choosing \"none\" will mute the audio output, and not play any sound.\n # Builtin default: \"\"\n device: none\n";