Skip to content

Commit

Permalink
CRIB 493 current chainlink develop images are broken and dont work on…
Browse files Browse the repository at this point in the history
… crib (smartcontractkit#14790)

* Reapply "CRIB 462 update go releaser dev space to work with latest changes (#1…" (smartcontractkit#14766)

This reverts commit b476a4a.

* Correct interpreter for x86 and add smoke test

* TEST: Remove other workflows

* Fix interpreter on x86 for plugins

* Fix version check

* TEST: Intentionally break amd64

* Revert "TEST: Intentionally break amd64"

This reverts commit 1ee47c0.

* Revert "TEST: Remove other workflows"

This reverts commit 6ea2f81.
  • Loading branch information
HenryNguyen5 authored Oct 16, 2024
1 parent ca71878 commit fcf7805
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 136 deletions.
152 changes: 138 additions & 14 deletions .github/actions/goreleaser-build-sign-publish/release.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,146 @@
#!/usr/bin/env node
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");

function main() {
const goreleaserConfig = mustGetEnv("GORELEASER_CONFIG");
const releaseType = mustGetEnv("RELEASE_TYPE");
const command = constructGoreleaserCommand(releaseType, goreleaserConfig);

if (process.env.DRY_RUN) {
console.log(`Generated command: ${command}`);
console.log("Dry run enabled. Exiting without executing the command.");
return;
const args = process.argv.slice(2);
const useExistingDist = args.includes("--use-existing-dist");
const chainlinkVersion = getVersion();

if (!useExistingDist) {
const goreleaserConfig = mustGetEnv("GORELEASER_CONFIG");
const releaseType = mustGetEnv("RELEASE_TYPE");
const command = constructGoreleaserCommand(
releaseType,
chainlinkVersion,
goreleaserConfig
);

if (process.env.DRY_RUN) {
console.log(`Generated command: ${command}`);
console.log("Dry run enabled. Exiting without executing the command.");
return;
} else {
console.log(`Executing command: ${command}`);
execSync(command, { stdio: "inherit" });
}
} else {
console.log(`Executing command: ${command}`);
execSync(command, { stdio: "inherit" });
console.log(
"Skipping Goreleaser command execution as '--use-existing-dist' is set."
);
}

const artifactsJsonPath = findArtifactsJson();
const dockerImages = extractDockerImages(artifactsJsonPath);
const repoSha = execSync("git rev-parse HEAD", { encoding: "utf-8" }).trim();

const results = dockerImages.map((image) => {
try {
console.log(`Checking version for image: ${image}, expected version: ${chainlinkVersion}, expected SHA: ${repoSha}`);
const versionOutput = execSync(`docker run --rm ${image} --version`, {
encoding: "utf-8",
});
console.log(`Output from image ${image}: ${versionOutput}`);

const cleanedOutput = versionOutput.replace("chainlink version ", "").trim();
const [version, sha] = cleanedOutput.split("@");
if (!version || !sha) {
throw new Error("Version or SHA not found in output.");
}

if (sha.trim() !== repoSha) {
throw new Error(`SHA mismatch: Expected ${repoSha}, got ${sha.trim()}`);
}
if (version.trim() !== chainlinkVersion) {
throw new Error(
`Version mismatch: Expected ${chainlinkVersion}, got ${version.trim()}`
);
}

return { image, success: true, message: "Version check passed." };
} catch (error) {
return { image, success: false, message: error.message };
}
});

printSummary(results);
if (results.some((result) => !result.success)) {
process.exit(1);
}
}

main();
function printSummary(results) {
const passed = results.filter((result) => result.success);
const failed = results.filter((result) => !result.success);

console.log("\nSummary:");
console.log(`Total images checked: ${results.length}`);
console.log(`Passed: ${passed.length}`);
console.log(`Failed: ${failed.length}`);

if (passed.length > 0) {
console.log("\nPassed images:");
passed.forEach((result) =>
console.log(`${result.image}:\n${result.message}`)
);
}

if (failed.length > 0) {
console.log("\nFailed images:");
failed.forEach((result) =>
console.log(`${result.image}:\n${result.message}`)
);
}
}

function findArtifactsJson() {
const distDir = path.resolve(process.cwd(), "dist");
const files = [];

function findJsonFiles(dir) {
const items = fs.readdirSync(dir, { withFileTypes: true });
for (const item of items) {
const fullPath = path.join(dir, item.name);
if (item.isDirectory()) {
findJsonFiles(fullPath);
} else if (item.isFile() && item.name === "artifacts.json") {
files.push(fullPath);
}
}
}

findJsonFiles(distDir);

if (files.length === 0) {
console.error("Error: No artifacts.json found in /dist.");
process.exit(1);
} else if (files.length > 1) {
console.error("Error: Multiple artifacts.json files found.");
process.exit(1);
}

return files[0];
}

function extractDockerImages(artifactsJsonPath) {
console.log(`Reading artifacts.json from: ${artifactsJsonPath}`);
const artifactsJson = JSON.parse(fs.readFileSync(artifactsJsonPath, "utf-8"));

const dockerImages = artifactsJson
.filter((artifact) => artifact.type === "Docker Image")
.map((artifact) => artifact.name);

if (dockerImages.length === 0) {
console.error("Error: No Docker images found in artifacts.json.");
process.exit(1);
}

function constructGoreleaserCommand(releaseType, goreleaserConfig) {
const version = getVersion();
console.log(`Found Docker images:\n - ${dockerImages.join("\n - ")}`);
return dockerImages;
}

function constructGoreleaserCommand(releaseType, version, goreleaserConfig) {
const flags = [];

checkReleaseType(releaseType);
Expand Down Expand Up @@ -59,6 +180,7 @@ function checkReleaseType(releaseType) {
console.error(
`Error: Invalid release type: ${releaseType}. Must be one of: ${validReleaseTypesStr}`
);
process.exit(1);
}
}

Expand All @@ -74,7 +196,7 @@ function mustGetEnv(key) {

function getVersion() {
try {
const pkgPath = process.cwd() + "/package.json";
const pkgPath = path.resolve(process.cwd(), "package.json");
console.log("Looking for chainlink version in package.json at: ", pkgPath);
const packageJson = require(pkgPath);
if (!packageJson.version) {
Expand All @@ -91,3 +213,5 @@ function getVersion() {
process.exit(1);
}
}

main();
25 changes: 16 additions & 9 deletions .goreleaser.develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project_name: chainlink
env:
- IMG_PRE={{ if index .Env "IMAGE_PREFIX" }}{{ .Env.IMAGE_PREFIX }}{{ else }}localhost:5001{{ end }}
- IMG_TAG={{ if index .Env "IMAGE_TAG" }}{{ .Env.IMAGE_TAG }}{{ else }}develop{{ end }}
- CGO_ENABLED=1
- VERSION={{ if index .Env "CHAINLINK_VERSION" }}{{ .Env.CHAINLINK_VERSION }}{{ else }}v0.0.0-local{{ end }}
release:
disable: "true"
Expand All @@ -16,8 +17,14 @@ builds:
no_unique_dist_dir: "true"
ldflags:
- -s -w -r=$ORIGIN/libs
- -X github.com/smartcontractkit/chainlink/v2/core/static.Version={{ .Env.VERSION }}
- -X github.com/smartcontractkit/chainlink/v2/core/static.Sha={{ .FullCommit }}
- |-
-extldflags "-Wl,--dynamic-linker={{ if contains .Runtime.Goarch "amd64" -}}
/lib64/ld-linux-x86-64.so.2
{{- else if contains .Runtime.Goarch "arm64" -}}
/lib/ld-linux-aarch64.so.1
{{- end }}"
- -X github.com/smartcontractkit/chainlink/v2/core/static.Version={{ .Env.VERSION }}
flags:
- -trimpath
- -buildmode=pie
Expand Down Expand Up @@ -49,8 +56,8 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.source=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.title=chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
- --label=org.opencontainers.image.url=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
use: buildx
- id: linux-amd64-chainlink-plugins
goos: linux
Expand Down Expand Up @@ -78,8 +85,8 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.source=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.title=chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
- --label=org.opencontainers.image.url=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
use: buildx
- id: linux-arm64-chainlink
goos: linux
Expand All @@ -101,8 +108,8 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.source=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.title=chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
- --label=org.opencontainers.image.url=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
use: buildx
- id: linux-arm64-chainlink-plugins
goos: linux
Expand All @@ -129,8 +136,8 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.source=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.title=chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
- --label=org.opencontainers.image.url=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
use: buildx
- id: linux-amd64-ccip
goos: linux
Expand All @@ -155,8 +162,8 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.source=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.title=chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
- --label=org.opencontainers.image.url=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
use: buildx
- id: linux-amd64-ccip-plugins
goos: linux
Expand Down Expand Up @@ -186,8 +193,8 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.source=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.title=chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
- --label=org.opencontainers.image.url=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
use: buildx
- id: linux-arm64-ccip
goos: linux
Expand All @@ -211,8 +218,8 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.source=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.title=chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
- --label=org.opencontainers.image.url=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
use: buildx
- id: linux-arm64-ccip-plugins
goos: linux
Expand Down Expand Up @@ -241,8 +248,8 @@ dockers:
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.source=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.title=chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
- --label=org.opencontainers.image.url=https://github.com/smartcontractkit/chainlink
- --label=org.opencontainers.image.version={{ .Env.VERSION }}
use: buildx
docker_manifests:
- id: tagged-chainlink
Expand Down
Loading

0 comments on commit fcf7805

Please sign in to comment.