Skip to content

Commit 576efee

Browse files
committed
buildx
1 parent e7bfb3f commit 576efee

15 files changed

Lines changed: 147 additions & 41 deletions

File tree

.config/appveyor/publish.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ skip_non_tags: true
66
image: Ubuntu2004
77
environment:
88
NPM_TOKEN: NPM_TOKEN
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: devcontainer-config/setup
11+
REGISTRY_TOKEN: REGISTRY_TOKEN
912
build_script:
1013
- sh: >-
1114
set -e
@@ -22,3 +25,9 @@ deploy_script:
2225
devcontainer exec --workspace-folder . pnpm build
2326
2427
devcontainer exec --workspace-folder . --remote-env NPM_TOKEN=${NPM_TOKEN} pnpm run publish
28+
29+
devcontainer exec --workspace-folder . \
30+
--remote-env REGISTRY=${REGISTRY} \
31+
--remote-env IMAGE_NAME=${IMAGE_NAME} \
32+
--remote-env REGISTRY_TOKEN=${REGISTRY_TOKEN} \
33+
pnpm run buildx

.config/cspell/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
"gitignoreRoot": ".",
66
"ignorePaths": ["LICENSE", "local.env"],
77
"words": [
8+
"buildx",
89
"csharpierignore",
910
"csharpierrc",
1011
"devcontainer",
1112
"devcontainers",
13+
"distroless",
1214
"execa",
1315
"globalconfig",
1416
"msbuild",

.devcontainer/compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
devcontainer:
33
env_file:
44
- .env
5-
- path: local.env
5+
- path: ../.local/.env
66
required: false
77
build:
88
context: .

ReadMe.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
# 🚧
2+
3+
```sh
4+
alias create-devcontainer='docker run --rm -it \
5+
-u $(id -u):$(id -g) -v ${PWD}:${PWD} -w ${PWD} \
6+
ghcr.io/devcontainer-config/setup'
7+
```

docker/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM --platform=linux/amd64 gcr.io/distroless/nodejs24-debian12 AS linux-amd64-base
2+
FROM --platform=linux/arm64 gcr.io/distroless/nodejs24-debian12 AS linux-arm64-base
3+
4+
ARG TARGETOS
5+
ARG TARGETARCH
6+
FROM ${TARGETOS}-${TARGETARCH}-base
7+
8+
COPY .local/docker /etc/devcontainer-config-setup
9+
10+
ENTRYPOINT [ "/nodejs/bin/node", "/etc/devcontainer-config-setup/index.js" ]

docker/Dockerfile.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.local/docker/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"type": "module",
55
"scripts": {
66
"build": "pnpm vite-node scripts/build.ts",
7+
"buildx": "pnpm vite-node scripts/buildx.ts",
78
"fix": "pnpm vite-node scripts/fix.ts",
89
"installPackage": "pnpm vite-node scripts/installPackage.ts",
910
"lint": "pnpm vite-node scripts/lint.ts",

scripts/buildx.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import path from "node:path";
2+
3+
import { $ } from "execa";
4+
5+
import { projectRoot } from "@/scripts/project.js";
6+
import { $$ } from "@/scripts/shell.js";
7+
import { getVersionTag } from "@/scripts/tasks/build.js";
8+
import { deploy } from "@/scripts/tasks/deploy.js";
9+
10+
const platforms: string[] = ["linux/amd64", "linux/arm64"];
11+
12+
const packagePath = path.resolve(projectRoot, ".local/docker");
13+
14+
async function buildImage(registry: string, imageName: string, tags: string[], publish: boolean) {
15+
console.log("Building multi-arch Docker image...");
16+
17+
const dockerfilePath = path.join(projectRoot, "docker/Dockerfile");
18+
const dockerPlatforms = platforms.join(",");
19+
20+
const args = ["buildx", "build", "--file", dockerfilePath, "--platform", dockerPlatforms];
21+
22+
for (const tag of tags) {
23+
args.push("--tag", `${registry}/${imageName}:${tag}`);
24+
}
25+
26+
if (publish) {
27+
args.push("--push");
28+
}
29+
30+
args.push(projectRoot);
31+
32+
await $$`docker ${args}`;
33+
console.log("Docker image built successfully.");
34+
}
35+
36+
const registry = process.env.REGISTRY ?? "local";
37+
const imageName = process.env.IMAGE_NAME ?? "setup";
38+
const version = await getVersionTag();
39+
const tags = [version, "latest"];
40+
const token = process.env.REGISTRY_TOKEN;
41+
const publish = !!token;
42+
43+
if (publish) {
44+
await $({ verbose: "full", input: token })`docker login ${registry} --username USERNAME --password-stdin`;
45+
}
46+
47+
await deploy(packagePath);
48+
await buildImage(registry, imageName, tags, publish);

scripts/project.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import path from "node:path";
22

3+
export const projectName = "devcontainer-config-setup";
4+
35
export const projectRoot = path.resolve(import.meta.dirname, "..");
46

57
export const workspaces = path.resolve(projectRoot, "..");

scripts/restore.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
import { cs$$ } from "@/scripts/shell.js";
1+
import { $ } from "execa";
2+
3+
import { projectName } from "@/scripts/project.js";
4+
import { $$, cs$$ } from "@/scripts/shell.js";
25

36
await cs$$`pnpm restore`;
7+
8+
// Create buildx builder
9+
const { exitCode } = await $({ stdio: "ignore", reject: false })`docker buildx use ${projectName}`;
10+
if (exitCode !== 0) {
11+
await $$`docker buildx create --name ${projectName} --use --bootstrap --driver-opt network=host`;
12+
}

0 commit comments

Comments
 (0)