Skip to content

Commit 543bcac

Browse files
Simon Emmsroboquat
Simon Emms
authored andcommitted
Add KOTS unstable publish to werft
When a build is run on the main branch, it publishes the latest release to the unstable channel in KOTS.
1 parent eac94bc commit 543bcac

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

.werft/build.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { deployToPreviewEnvironment } from './jobs/build/deploy-to-preview-envir
1111
import { triggerIntegrationTests } from './jobs/build/trigger-integration-tests';
1212
import { jobConfig } from './jobs/build/job-config';
1313
import { typecheckWerftJobs } from './jobs/build/typecheck-werft-jobs';
14+
import { publishKotsUnstable } from './jobs/build/publish-kots-unstable'
1415

1516
// Will be set once tracing has been initialized
1617
let werft: Werft
@@ -59,4 +60,5 @@ async function run(context: any) {
5960

6061
await deployToPreviewEnvironment(werft, config)
6162
await triggerIntegrationTests(werft, config, context.Owner)
63+
await publishKotsUnstable(werft, config)
6264
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { exec } from '../../util/shell';
2+
import { Werft } from "../../util/werft";
3+
import { JobConfig } from "./job-config";
4+
5+
const phases = {
6+
PUBLISH_KOTS_UNSTABLE: 'publish kots unstable',
7+
};
8+
9+
const REPLICATED_SECRET = 'replicated';
10+
const REPLICATED_CHANNEL = 'Unstable';
11+
const REPLICATED_YAML_DIR = './install/kots/manifests';
12+
const INSTALLER_JOB_IMAGE = 'spec.template.spec.containers[0].image';
13+
14+
export async function publishKotsUnstable(werft: Werft, config: JobConfig) {
15+
if (config.mainBuild) {
16+
werft.phase(phases.PUBLISH_KOTS_UNSTABLE, 'Publish unstable release to KOTS');
17+
18+
const imageAndTag = exec(`yq r ${REPLICATED_YAML_DIR}/gitpod-installer-job.yaml ${INSTALLER_JOB_IMAGE}`);
19+
const [image] = imageAndTag.split(':');
20+
21+
// Set the tag to the current version
22+
exec(`yq w -i ${REPLICATED_YAML_DIR}/gitpod-installer-job.yaml ${INSTALLER_JOB_IMAGE} ${image}:${config.version}`);
23+
24+
const app = exec(`kubectl get secret ${REPLICATED_SECRET} --namespace werft -o jsonpath='{.data.app}' | base64 -d`);
25+
const token = exec(`kubectl get secret ${REPLICATED_SECRET} --namespace werft -o jsonpath='{.data.token}' | base64 -d`);
26+
27+
exec(`replicated release create \
28+
--lint \
29+
--ensure-channel \
30+
--app ${app} \
31+
--token ${token} \
32+
--yaml-dir ${REPLICATED_YAML_DIR} \
33+
--version ${config.version} \
34+
--release-notes "# ${config.version}\n\nSee [Werft job](https://werft.gitpod-dev.com/job/gitpod-build-${config.version}/logs) for notes" \
35+
--promote ${REPLICATED_CHANNEL}`);
36+
37+
werft.done(phases.PUBLISH_KOTS_UNSTABLE);
38+
}
39+
}

0 commit comments

Comments
 (0)