Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
853d5fa804 | ||
|
|
61c10b2d7d | ||
|
|
e84b18afd5 | ||
|
|
f06ec3b4a1 | ||
|
|
991feac6c3 | ||
|
|
a79473b652 | ||
|
|
6f86e0250d | ||
|
|
0a09638c5b | ||
|
|
ea7b423421 | ||
|
|
24115c327a | ||
|
|
bdd1a426f5 | ||
|
|
e2acba1767 | ||
|
|
735c66bebf |
41
.github/buildx-releases.json
vendored
41
.github/buildx-releases.json
vendored
@@ -40,6 +40,47 @@
|
||||
"https://github.com/docker/buildx/releases/download/v0.17.1/checksums.txt"
|
||||
]
|
||||
},
|
||||
"v0.18.0-rc3": {
|
||||
"id": 182564109,
|
||||
"tag_name": "v0.18.0-rc3",
|
||||
"html_url": "https://github.com/docker/buildx/releases/tag/v0.18.0-rc3",
|
||||
"assets": [
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.darwin-amd64",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.darwin-amd64.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.darwin-amd64.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.darwin-arm64",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.darwin-arm64.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.darwin-arm64.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-amd64",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-amd64.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-amd64.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm-v6",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm-v6.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm-v6.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm-v7",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm-v7.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm-v7.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm64",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm64.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-arm64.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-ppc64le",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-ppc64le.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-ppc64le.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-riscv64",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-riscv64.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-riscv64.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-s390x",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-s390x.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.linux-s390x.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.windows-amd64.exe",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.windows-amd64.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.windows-amd64.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.windows-arm64.exe",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.windows-arm64.provenance.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/buildx-v0.18.0-rc3.windows-arm64.sbom.json",
|
||||
"https://github.com/docker/buildx/releases/download/v0.18.0-rc3/checksums.txt"
|
||||
]
|
||||
},
|
||||
"v0.18.0-rc2": {
|
||||
"id": 182417114,
|
||||
"tag_name": "v0.18.0-rc2",
|
||||
|
||||
11
.github/workflows/validate.yml
vendored
11
.github/workflows/validate.yml
vendored
@@ -17,16 +17,17 @@ jobs:
|
||||
prepare:
|
||||
runs-on: ubuntu-20.04
|
||||
outputs:
|
||||
targets: ${{ steps.targets.outputs.matrix }}
|
||||
targets: ${{ steps.generate.outputs.targets }}
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Matrix
|
||||
id: targets
|
||||
run: |
|
||||
echo "matrix=$(docker buildx bake validate --print | jq -cr '.group.validate.targets')" >> $GITHUB_OUTPUT
|
||||
name: List targets
|
||||
id: generate
|
||||
uses: docker/bake-action/subaction/list-targets@v5
|
||||
with:
|
||||
target: validate
|
||||
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {jest, describe, expect, test, beforeEach, afterEach} from '@jest/globals';
|
||||
import {jest, describe, test, beforeEach, afterEach, expect} from '@jest/globals';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
@@ -43,7 +43,9 @@ aarch64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-g
|
||||
test.each([
|
||||
{type: 'image', tag: '27.3.1'} as InstallSourceImage,
|
||||
{type: 'image', tag: 'master'} as InstallSourceImage,
|
||||
{type: 'image', tag: 'latest'} as InstallSourceImage,
|
||||
{type: 'archive', version: 'v26.1.4', channel: 'stable'} as InstallSourceArchive,
|
||||
{type: 'archive', version: 'latest', channel: 'stable'} as InstallSourceArchive,
|
||||
])(
|
||||
'install docker %s', async (source) => {
|
||||
if (process.env.ImageOS && process.env.ImageOS.startsWith('ubuntu')) {
|
||||
@@ -64,12 +66,17 @@ aarch64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-g
|
||||
daemonConfig: `{"debug":true,"features":{"containerd-snapshotter":true}}`
|
||||
});
|
||||
await expect((async () => {
|
||||
await install.download();
|
||||
await install.install();
|
||||
await Docker.printVersion();
|
||||
await Docker.printInfo();
|
||||
})().finally(async () => {
|
||||
await install.tearDown();
|
||||
})).resolves.not.toThrow();
|
||||
try {
|
||||
await install.download();
|
||||
await install.install();
|
||||
await Docker.printVersion();
|
||||
await Docker.printInfo();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
} finally {
|
||||
await install.tearDown();
|
||||
}
|
||||
})()).resolves.not.toThrow();
|
||||
}, 30 * 60 * 1000);
|
||||
});
|
||||
|
||||
84
__tests__/undock/undock.test.ts
Normal file
84
__tests__/undock/undock.test.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright 2024 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.
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import {describe, expect, it, jest, test} from '@jest/globals';
|
||||
import * as semver from 'semver';
|
||||
|
||||
import {Exec} from '../../src/exec';
|
||||
import {Undock} from '../../src/undock/undock';
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'undock-undock-'));
|
||||
|
||||
describe('run', () => {
|
||||
it('extracts moby/moby-bin:26.1.5', async () => {
|
||||
const undock = new Undock();
|
||||
await expect(
|
||||
(async () => {
|
||||
// prettier-ignore
|
||||
await undock.run({
|
||||
source: 'moby/moby-bin:26.1.5',
|
||||
dist: tmpDir,
|
||||
all: true
|
||||
});
|
||||
})()
|
||||
).resolves.not.toThrow();
|
||||
}, 100000);
|
||||
});
|
||||
|
||||
describe('isAvailable', () => {
|
||||
it('checks undock is available', async () => {
|
||||
const execSpy = jest.spyOn(Exec, 'getExecOutput');
|
||||
const undock = new Undock();
|
||||
await undock.isAvailable();
|
||||
// eslint-disable-next-line jest/no-standalone-expect
|
||||
expect(execSpy).toHaveBeenCalledWith(`undock`, [], {
|
||||
silent: true,
|
||||
ignoreReturnCode: true
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('printVersion', () => {
|
||||
it('prints undock version', async () => {
|
||||
const execSpy = jest.spyOn(Exec, 'exec');
|
||||
const undock = new Undock();
|
||||
await undock.printVersion();
|
||||
expect(execSpy).toHaveBeenCalledWith(`undock`, ['--version'], {
|
||||
failOnStdErr: false
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('version', () => {
|
||||
it('valid', async () => {
|
||||
const undock = new Undock();
|
||||
expect(semver.valid(await undock.version())).not.toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('versionSatisfies', () => {
|
||||
test.each([
|
||||
['v0.4.1', '>=0.3.2', true],
|
||||
['v0.8.0', '>0.6.0', true],
|
||||
['v0.8.0', '<0.3.0', false]
|
||||
])('given %p', async (version, range, expected) => {
|
||||
const undock = new Undock();
|
||||
expect(await undock.versionSatisfies(range, version)).toBe(expected);
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,7 @@
|
||||
ARG NODE_VERSION=20
|
||||
ARG DOCKER_VERSION=27.2.1
|
||||
ARG BUILDX_VERSION=0.17.1
|
||||
ARG UNDOCK_VERSION=0.8.0
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache cpio findutils git
|
||||
@@ -73,8 +74,9 @@ RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run lint
|
||||
|
||||
FROM docker:${DOCKER_VERSION} as docker
|
||||
FROM docker/buildx-bin:${BUILDX_VERSION} as buildx
|
||||
FROM docker:${DOCKER_VERSION} AS docker
|
||||
FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
|
||||
FROM crazymax/undock:${UNDOCK_VERSION} AS undock
|
||||
|
||||
FROM deps AS test
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
@@ -83,6 +85,7 @@ RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=bind,from=docker,source=/usr/local/bin/docker,target=/usr/bin/docker \
|
||||
--mount=type=bind,from=buildx,source=/buildx,target=/usr/libexec/docker/cli-plugins/docker-buildx \
|
||||
--mount=type=bind,from=buildx,source=/buildx,target=/usr/bin/buildx \
|
||||
--mount=type=bind,from=undock,source=/usr/local/bin/undock,target=/usr/bin/undock \
|
||||
--mount=type=secret,id=GITHUB_TOKEN \
|
||||
GITHUB_TOKEN=$(cat /run/secrets/GITHUB_TOKEN) yarn run test:coverage --coverageDirectory=/tmp/coverage
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ group "pre-checkin" {
|
||||
}
|
||||
|
||||
group "validate" {
|
||||
targets = ["lint", "vendor-validate", "license-validate"]
|
||||
targets = ["lint", "vendor-validate", "dockerfile-validate", "license-validate"]
|
||||
}
|
||||
|
||||
target "build" {
|
||||
@@ -54,6 +54,18 @@ target "vendor-validate" {
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
target "dockerfile-validate" {
|
||||
matrix = {
|
||||
dockerfile = [
|
||||
"dev.Dockerfile",
|
||||
"./hack/dockerfiles/license.Dockerfile"
|
||||
]
|
||||
}
|
||||
name = "dockerfile-validate-${md5(dockerfile)}"
|
||||
dockerfile = dockerfile
|
||||
call = "check"
|
||||
}
|
||||
|
||||
target "test" {
|
||||
dockerfile = "dev.Dockerfile"
|
||||
target = "test"
|
||||
|
||||
@@ -237,12 +237,10 @@ provision:
|
||||
|
||||
HOME=/tmp undock moby/moby-bin:{{srcImageTag}} /usr/local/bin
|
||||
|
||||
wget https://raw.githubusercontent.com/moby/moby/{{srcImageTag}}/contrib/init/systemd/docker.service \
|
||||
https://raw.githubusercontent.com/moby/moby/v{{srcImageTag}}/contrib/init/systemd/docker.service \
|
||||
-O /etc/systemd/system/docker.service || true
|
||||
wget https://raw.githubusercontent.com/moby/moby/{{srcImageTag}}/contrib/init/systemd/docker.socket \
|
||||
https://raw.githubusercontent.com/moby/moby/v{{srcImageTag}}/contrib/init/systemd/docker.socket \
|
||||
-O /etc/systemd/system/docker.socket || true
|
||||
wget https://raw.githubusercontent.com/moby/moby/{{gitCommit}}/contrib/init/systemd/docker.service \
|
||||
-O /etc/systemd/system/docker.service
|
||||
wget https://raw.githubusercontent.com/moby/moby/{{gitCommit}}/contrib/init/systemd/docker.socket \
|
||||
-O /etc/systemd/system/docker.socket
|
||||
|
||||
sed -i 's|^ExecStart=.*|ExecStart=/usr/local/bin/dockerd -H fd://|' /etc/systemd/system/docker.service
|
||||
sed -i 's|containerd.service||' /etc/systemd/system/docker.service
|
||||
|
||||
@@ -34,6 +34,7 @@ import {Util} from '../util';
|
||||
import {limaYamlData, dockerServiceLogsPs1, setupDockerWinPs1} from './assets';
|
||||
import {GitHubRelease} from '../types/github';
|
||||
import {HubRepository} from '../hubRepository';
|
||||
import {Image} from '../types/oci/config';
|
||||
|
||||
export interface InstallSourceImage {
|
||||
type: 'image';
|
||||
@@ -71,6 +72,8 @@ export class Install {
|
||||
private _version: string | undefined;
|
||||
private _toolDir: string | undefined;
|
||||
|
||||
private gitCommit: string | undefined;
|
||||
|
||||
private readonly limaInstanceName = 'docker-actions-toolkit';
|
||||
|
||||
constructor(opts: InstallOpts) {
|
||||
@@ -127,12 +130,28 @@ export class Install {
|
||||
const cli = await HubRepository.build('dockereng/cli-bin');
|
||||
extractFolder = await cli.extractImage(tag);
|
||||
|
||||
const moby = await HubRepository.build('moby/moby-bin');
|
||||
if (['win32', 'linux'].includes(platform)) {
|
||||
core.info(`Downloading dockerd from moby/moby-bin:${tag}`);
|
||||
const moby = await HubRepository.build('moby/moby-bin');
|
||||
await moby.extractImage(tag, extractFolder);
|
||||
} else if (platform == 'darwin') {
|
||||
// On macOS, the docker daemon binary will be downloaded inside the lima VM
|
||||
// On macOS, the docker daemon binary will be downloaded inside the lima VM.
|
||||
// However, we will get the exact git revision from the image config
|
||||
// to get the matching systemd unit files.
|
||||
core.info(`Getting git revision from moby/moby-bin:${tag}`);
|
||||
|
||||
// There's no macOS image for moby/moby-bin - a linux daemon is run inside lima.
|
||||
const manifest = await moby.getPlatformManifest(tag, 'linux');
|
||||
|
||||
const config = await moby.getJSONBlob<Image>(manifest.config.digest);
|
||||
core.debug(`Config ${JSON.stringify(config.config)}`);
|
||||
|
||||
this.gitCommit = config.config?.Labels?.['org.opencontainers.image.revision'];
|
||||
if (!this.gitCommit) {
|
||||
core.warning(`No git revision can be determined from the image. Will use master.`);
|
||||
this.gitCommit = 'master';
|
||||
}
|
||||
core.info(`Git revision is ${this.gitCommit}`);
|
||||
} else {
|
||||
core.warning(`dockerd not supported on ${platform}, only the Docker cli will be available`);
|
||||
}
|
||||
@@ -193,6 +212,9 @@ export class Install {
|
||||
}
|
||||
|
||||
private async installDarwin(): Promise<string> {
|
||||
if (this.source.type == 'image' && !this.gitCommit) {
|
||||
throw new Error('gitCommit must be set. Run download first.');
|
||||
}
|
||||
const src = this.source;
|
||||
const limaDir = path.join(os.homedir(), '.lima', this.limaInstanceName);
|
||||
await io.mkdirP(limaDir);
|
||||
@@ -229,8 +251,9 @@ export class Install {
|
||||
customImages: Install.limaCustomImages(),
|
||||
daemonConfig: limaDaemonConfig,
|
||||
dockerSock: `${limaDir}/docker.sock`,
|
||||
gitCommit: this.gitCommit,
|
||||
srcType: src.type,
|
||||
srcArchiveVersion: srcArchive.version?.replace(/^v/, ''),
|
||||
srcArchiveVersion: this._version, // Use the resolved version (e.g. latest -> 27.4.0)
|
||||
srcArchiveChannel: srcArchive.channel,
|
||||
srcImageTag: (src as InstallSourceImage).tag
|
||||
});
|
||||
|
||||
@@ -21,8 +21,8 @@ import * as core from '@actions/core';
|
||||
import {Manifest} from './types/oci/manifest';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import fs from 'fs';
|
||||
import {MEDIATYPE_IMAGE_INDEX_V1, MEDIATYPE_IMAGE_MANIFEST_V1} from './types/oci/mediatype';
|
||||
import {MEDIATYPE_IMAGE_MANIFEST_V2, MEDIATYPE_IMAGE_MANIFEST_LIST_V2} from './types/docker/mediatype';
|
||||
import {MEDIATYPE_IMAGE_CONFIG_V1, MEDIATYPE_IMAGE_INDEX_V1, MEDIATYPE_IMAGE_MANIFEST_V1} from './types/oci/mediatype';
|
||||
import {MEDIATYPE_IMAGE_CONFIG_V1 as DOCKER_MEDIATYPE_IMAGE_CONFIG_V1, MEDIATYPE_IMAGE_MANIFEST_LIST_V2, MEDIATYPE_IMAGE_MANIFEST_V2} from './types/docker/mediatype';
|
||||
import {DockerHub} from './dockerhub';
|
||||
|
||||
export class HubRepository {
|
||||
@@ -40,15 +40,20 @@ export class HubRepository {
|
||||
return new HubRepository(repository, token);
|
||||
}
|
||||
|
||||
public async getPlatformManifest(tagOrDigest: string, os?: string): Promise<Manifest> {
|
||||
const index = await this.getManifest<Index>(tagOrDigest);
|
||||
if (index.mediaType != MEDIATYPE_IMAGE_INDEX_V1 && index.mediaType != MEDIATYPE_IMAGE_MANIFEST_LIST_V2) {
|
||||
core.error(`Unsupported image media type: ${index.mediaType}`);
|
||||
throw new Error(`Unsupported image media type: ${index.mediaType}`);
|
||||
}
|
||||
const digest = HubRepository.getPlatformManifestDigest(index, os);
|
||||
return await this.getManifest<Manifest>(digest);
|
||||
}
|
||||
|
||||
// Unpacks the image layers and returns the path to the extracted image.
|
||||
// Only OCI indexes/manifest list are supported for now.
|
||||
public async extractImage(tag: string, destDir?: string): Promise<string> {
|
||||
const index = await this.getManifest<Index>(tag);
|
||||
if (index.mediaType != MEDIATYPE_IMAGE_INDEX_V1 && index.mediaType != MEDIATYPE_IMAGE_MANIFEST_LIST_V2) {
|
||||
throw new Error(`Unsupported image media type: ${index.mediaType}`);
|
||||
}
|
||||
const digest = HubRepository.getPlatformManifestDigest(index);
|
||||
const manifest = await this.getManifest<Manifest>(digest);
|
||||
const manifest = await this.getPlatformManifest(tag);
|
||||
|
||||
const paths = manifest.layers.map(async layer => {
|
||||
const url = this.blobUrl(layer.digest);
|
||||
@@ -99,25 +104,35 @@ export class HubRepository {
|
||||
}
|
||||
|
||||
public async getManifest<T>(tagOrDigest: string): Promise<T> {
|
||||
const url = `https://registry-1.docker.io/v2/${this.repo}/manifests/${tagOrDigest}`;
|
||||
return await this.registryGet<T>(tagOrDigest, 'manifests', [MEDIATYPE_IMAGE_INDEX_V1, MEDIATYPE_IMAGE_MANIFEST_LIST_V2, MEDIATYPE_IMAGE_MANIFEST_V1, MEDIATYPE_IMAGE_MANIFEST_V2]);
|
||||
}
|
||||
|
||||
public async getJSONBlob<T>(tagOrDigest: string): Promise<T> {
|
||||
return await this.registryGet<T>(tagOrDigest, 'blobs', [MEDIATYPE_IMAGE_CONFIG_V1, DOCKER_MEDIATYPE_IMAGE_CONFIG_V1]);
|
||||
}
|
||||
|
||||
private async registryGet<T>(tagOrDigest: string, endpoint: 'manifests' | 'blobs', accept: Array<string>): Promise<T> {
|
||||
const url = `https://registry-1.docker.io/v2/${this.repo}/${endpoint}/${tagOrDigest}`;
|
||||
|
||||
const headers = {
|
||||
Authorization: `Bearer ${this.token}`,
|
||||
Accept: [MEDIATYPE_IMAGE_INDEX_V1, MEDIATYPE_IMAGE_MANIFEST_LIST_V2, MEDIATYPE_IMAGE_MANIFEST_V1, MEDIATYPE_IMAGE_MANIFEST_V2].join(', ')
|
||||
Accept: accept.join(', ')
|
||||
};
|
||||
|
||||
const resp = await HubRepository.http.get(url, headers);
|
||||
const body = await resp.readBody();
|
||||
const statusCode = resp.message.statusCode || 500;
|
||||
if (statusCode != 200) {
|
||||
core.error(`registryGet(${this.repo}:${tagOrDigest}) failed: ${statusCode} ${body}`);
|
||||
throw DockerHub.parseError(resp, body);
|
||||
}
|
||||
|
||||
return <T>JSON.parse(body);
|
||||
}
|
||||
|
||||
private static getPlatformManifestDigest(index: Index): string {
|
||||
private static getPlatformManifestDigest(index: Index, osOverride?: string): string {
|
||||
// This doesn't handle all possible platforms normalizations, but it's good enough for now.
|
||||
let pos: string = os.platform();
|
||||
let pos: string = osOverride || os.platform();
|
||||
if (pos == 'win32') {
|
||||
pos = 'windows';
|
||||
}
|
||||
@@ -150,8 +165,10 @@ export class HubRepository {
|
||||
return true;
|
||||
});
|
||||
if (!manifest) {
|
||||
core.error(`Cannot find manifest for ${pos}/${arch}/${variant}`);
|
||||
throw new Error(`Cannot find manifest for ${pos}/${arch}/${variant}`);
|
||||
}
|
||||
|
||||
return manifest.digest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import {Bake as BuildxBake} from './buildx/bake';
|
||||
import {Install as BuildxInstall} from './buildx/install';
|
||||
import {Builder} from './buildx/builder';
|
||||
import {BuildKit} from './buildkit/buildkit';
|
||||
import {Undock} from './undock/undock';
|
||||
import {GitHub} from './github';
|
||||
|
||||
export interface ToolkitOpts {
|
||||
@@ -38,6 +39,7 @@ export class Toolkit {
|
||||
public buildxInstall: BuildxInstall;
|
||||
public builder: Builder;
|
||||
public buildkit: BuildKit;
|
||||
public undock: Undock;
|
||||
|
||||
constructor(opts: ToolkitOpts = {}) {
|
||||
this.github = new GitHub({token: opts.githubToken});
|
||||
@@ -47,5 +49,6 @@ export class Toolkit {
|
||||
this.buildxInstall = new BuildxInstall();
|
||||
this.builder = new Builder({buildx: this.buildx});
|
||||
this.buildkit = new BuildKit({buildx: this.buildx});
|
||||
this.undock = new Undock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,3 +17,5 @@
|
||||
export const MEDIATYPE_IMAGE_MANIFEST_LIST_V2 = 'application/vnd.docker.distribution.manifest.list.v2+json';
|
||||
|
||||
export const MEDIATYPE_IMAGE_MANIFEST_V2 = 'application/vnd.docker.distribution.manifest.v2+json';
|
||||
|
||||
export const MEDIATYPE_IMAGE_CONFIG_V1 = 'application/vnd.docker.container.image.v1+json';
|
||||
|
||||
@@ -23,3 +23,5 @@ export const MEDIATYPE_IMAGE_INDEX_V1 = 'application/vnd.oci.image.index.v1+json
|
||||
export const MEDIATYPE_IMAGE_LAYER_V1 = 'application/vnd.oci.image.layer.v1.tar';
|
||||
|
||||
export const MEDIATYPE_EMPTY_JSON_V1 = 'application/vnd.oci.empty.v1+json';
|
||||
|
||||
export const MEDIATYPE_IMAGE_CONFIG_V1 = 'application/vnd.oci.image.config.v1+json';
|
||||
|
||||
148
src/undock/undock.ts
Normal file
148
src/undock/undock.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Copyright 2024 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.
|
||||
*/
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as semver from 'semver';
|
||||
|
||||
import {Exec} from '../exec';
|
||||
|
||||
export interface UndockOpts {
|
||||
binPath?: string;
|
||||
}
|
||||
|
||||
export interface UndockRunOpts {
|
||||
source: string;
|
||||
dist: string;
|
||||
logLevel?: string;
|
||||
logCaller?: boolean;
|
||||
cacheDir?: string;
|
||||
platform?: string;
|
||||
all?: boolean;
|
||||
include?: Array<string>;
|
||||
insecure?: boolean;
|
||||
rmDist?: boolean;
|
||||
wrap?: boolean;
|
||||
}
|
||||
|
||||
export class Undock {
|
||||
private readonly binPath: string;
|
||||
private _version: string;
|
||||
private _versionOnce: boolean;
|
||||
|
||||
constructor(opts?: UndockOpts) {
|
||||
this.binPath = opts?.binPath || 'undock';
|
||||
this._version = '';
|
||||
this._versionOnce = false;
|
||||
}
|
||||
|
||||
public async run(opts: UndockRunOpts): Promise<void> {
|
||||
if (!opts.source) {
|
||||
throw new Error('source is required');
|
||||
}
|
||||
if (!opts.dist) {
|
||||
throw new Error('dist is required');
|
||||
}
|
||||
const args: Array<string> = [];
|
||||
if (opts.logLevel) {
|
||||
args.push(`--log-level=${opts.logLevel}`);
|
||||
}
|
||||
if (opts.logCaller) {
|
||||
args.push('--log-caller');
|
||||
}
|
||||
if (opts.cacheDir) {
|
||||
args.push(`--cachedir=${opts.cacheDir}`);
|
||||
}
|
||||
if (opts.platform) {
|
||||
args.push(`--platform=${opts.platform}`);
|
||||
}
|
||||
if (opts.all) {
|
||||
args.push('--all');
|
||||
}
|
||||
if (opts.include) {
|
||||
opts.include.forEach(i => {
|
||||
args.push(`--include=${i}`);
|
||||
});
|
||||
}
|
||||
if (opts.insecure) {
|
||||
args.push('--insecure');
|
||||
}
|
||||
if (opts.rmDist) {
|
||||
args.push('--rm-dist');
|
||||
}
|
||||
if (opts.wrap) {
|
||||
args.push('--wrap');
|
||||
}
|
||||
args.push(opts.source, opts.dist);
|
||||
await Exec.exec(this.binPath, args, {
|
||||
failOnStdErr: false
|
||||
});
|
||||
}
|
||||
|
||||
public async isAvailable(): Promise<boolean> {
|
||||
const ok: boolean = await Exec.getExecOutput(this.binPath, [], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
})
|
||||
.then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
core.debug(`Undock.isAvailable cmd err: ${res.stderr.trim()}`);
|
||||
return false;
|
||||
}
|
||||
return res.exitCode == 0;
|
||||
})
|
||||
.catch(error => {
|
||||
core.debug(`Undock.isAvailable error: ${error}`);
|
||||
return false;
|
||||
});
|
||||
|
||||
core.debug(`Undock.isAvailable: ${ok}`);
|
||||
return ok;
|
||||
}
|
||||
|
||||
public async version(): Promise<string> {
|
||||
if (this._versionOnce) {
|
||||
return this._version;
|
||||
}
|
||||
this._versionOnce = true;
|
||||
this._version = await Exec.getExecOutput(this.binPath, ['--version'], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
return res.stdout.trim();
|
||||
});
|
||||
return this._version;
|
||||
}
|
||||
|
||||
public async printVersion() {
|
||||
await Exec.exec(this.binPath, ['--version'], {
|
||||
failOnStdErr: false
|
||||
});
|
||||
}
|
||||
|
||||
public async versionSatisfies(range: string, version?: string): Promise<boolean> {
|
||||
const ver = version ?? (await this.version());
|
||||
if (!ver) {
|
||||
core.debug(`Undock.versionSatisfies false: undefined version`);
|
||||
return false;
|
||||
}
|
||||
const res = semver.satisfies(ver, range) || /^[0-9a-f]{7}$/.exec(ver) !== null;
|
||||
core.debug(`Undock.versionSatisfies ${ver} statisfies ${range}: ${res}`);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user