|
| 1 | +const { execSync } = require("child_process"); |
| 2 | + |
| 3 | +const version = process.env.VERSION.replace(/^v/, ""); |
| 4 | +const repo = process.env.GITHUB_REPOSITORY.toLowerCase(); |
| 5 | +const imagePath = `ghcr.io/${repo}`; |
| 6 | + |
| 7 | +const ociTypes = ["", "-full", "-dev", "-dev-full", "-v3", "-v3-full"]; |
| 8 | + |
| 9 | +ociTypes.forEach((ociType) => { |
| 10 | + const dockerEnv = { |
| 11 | + ...process.env, |
| 12 | + JOBS_ENABLED: ociType.includes("-full") ? "true" : "", |
| 13 | + ELASTIC_ENABLED: ociType.includes("-full") ? "true" : "", |
| 14 | + LDAP_ENABLED: ociType.includes("-full") ? "true" : "", |
| 15 | + OIDC_ENABLED: ociType.includes("-full") ? "true" : "", |
| 16 | + COMPOSE_PROFILES: ociType.includes("-full") ? "*" : "", |
| 17 | + DEV: ociType.includes("-dev") ? "true" : "", |
| 18 | + BE_VERSION: ociType.includes("-v3") ? "v3" : "v4", |
| 19 | + }; |
| 20 | + |
| 21 | + try { |
| 22 | + // 1. Resolve Compose |
| 23 | + execSync( |
| 24 | + "docker compose -f ../../compose.yaml config --no-path-resolution > resolved-compose.yaml", |
| 25 | + { |
| 26 | + env: dockerEnv, |
| 27 | + }, |
| 28 | + ); |
| 29 | + |
| 30 | + // 2. Inline & Escape $ (Safe Node-style string replacement) |
| 31 | + execSync( |
| 32 | + "yq -i \"(.configs[] | select(has(\\\"file\\\"))) |= (.content = (load_str(.file) | split(\\\"$\\\") | join(\\\"$$\\\")) | del(.file))\" resolved-compose.yaml", |
| 33 | + { stdio: "inherit" } |
| 34 | + ); |
| 35 | + |
| 36 | + // 3. Publish |
| 37 | + const ociTags = [ |
| 38 | + `${imagePath}:${version}${ociType}`, |
| 39 | + `${imagePath}:latest${ociType}`, |
| 40 | + ]; |
| 41 | + ociTags.forEach((ociTag) => { |
| 42 | + execSync( |
| 43 | + `yes | docker compose -f resolved-compose.yaml publish --resolve-image-digests --with-env --yes ${ociTag}`, |
| 44 | + { |
| 45 | + env: dockerEnv, |
| 46 | + stdio: "inherit", |
| 47 | + }, |
| 48 | + ); |
| 49 | + }); |
| 50 | + } catch { |
| 51 | + process.exit(1); |
| 52 | + } |
| 53 | +}); |
0 commit comments