Skip to content

Commit

Permalink
Lock upload to triggering IG and kill prior jobs in branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jmandel committed Sep 19, 2023
1 parent 1829aed commit b3eb892
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
6 changes: 3 additions & 3 deletions images/ig-build/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def early_failure(msg):
return {
"result_dir": clone_dir,
"message": message_header + msg,
"pubargs": [config['org'], config['repo'], config['branch'], 'failure', 'nondefault']
"pubargs": ['failure', 'nondefault']
}

if cloned_exit != 0:
Expand Down Expand Up @@ -120,7 +120,7 @@ def early_failure(msg):
return {
"result_dir": clone_dir,
"message":"".join(message).format(**details),
"pubargs": [details['org'], details['repo'], details['branch'], 'failure', details['default']]
"pubargs": ['failure', details['default']]
}


Expand All @@ -133,7 +133,7 @@ def early_failure(msg):
return {
"result_dir": build_dir,
"message":"".join(message).format(**details),
"pubargs": [details['org'], details['repo'], details['branch'], 'success', details['default']]
"pubargs": ['success', details['default']]
}

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion images/ig-build/watch-and-publish
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cat /scratch/done

# Then, Run publish.sh with the arguments from the 'done' file
cd /scratch/upload
publish "${pubargs[@]}"
publish "${IG_ORG}" "${IG_REPO}" "${IG_BRANCH}" "${pubargs[@]}"

# Send Zulip message
echo "Uploaded; notifying zulip"
Expand Down
40 changes: 25 additions & 15 deletions triggers/ig-commit-trigger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ functions.http("ig-commit-trigger", async function (req, res) {
});
}

const jobGroupId = `igbuild-${org}-${repo}-${branch}`.toLocaleLowerCase();

const jobId = `igbuild-${commitHash.slice(0, 6)}-${org}-${repo}-${branch}`
.toLocaleLowerCase()
.replace(/[^A-Za-z0-9]/g, "")
.slice(0, 63);

const igIniUrl = `https://raw.githubusercontent.com/${org}/${repo}/${branch}/ig.ini`;
const igIni = await fetch(igIniUrl);

Expand All @@ -50,24 +53,31 @@ functions.http("ig-commit-trigger", async function (req, res) {

const job = JSON.parse(JSON.stringify(jobSource));
job.metadata.name = jobId;
const container = job.spec.template.spec.containers[0];
container.env = container.env.concat([
{
name: "IG_ORG",
value: org,
},
{
name: "IG_REPO",
value: repo,
},
{
name: "IG_BRANCH",
value: branch,
},
]);
job.metadata.labels["job-group-id"] = jobGroupId;
job.spec.template.spec.containers.forEach((container) => {
container.env = container.env.concat([
{
name: "IG_ORG",
value: org,
},
{
name: "IG_REPO",
value: repo,
},
{
name: "IG_BRANCH",
value: branch,
},
]);
});

try {
const existing = await k8sBatch.listNamespacedJob("fhir", false, false, undefined, undefined, `job-group-id=${jobGroupId}`);
const created = await k8sBatch.createNamespacedJob("fhir", job);

console.log("Kill existing jobs", existing?.body?.items?.map(j => j?.metadata?.name))
await Promise.all(existing?.body?.items?.map((i) => k8sBatch.deleteNamespacedJob(i.metadata.name, "fhir")))

return res.status(200).json({
created: true,
org: org,
Expand Down

0 comments on commit b3eb892

Please sign in to comment.