Skip to content

Commit

Permalink
Add KOTS unstable publish to werft
Browse files Browse the repository at this point in the history
When a build is run on the main branch, it publishes the latest
release to the unstable channel in KOTS.
  • Loading branch information
Simon Emms authored and roboquat committed Mar 28, 2022
1 parent eac94bc commit 543bcac
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .werft/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { deployToPreviewEnvironment } from './jobs/build/deploy-to-preview-envir
import { triggerIntegrationTests } from './jobs/build/trigger-integration-tests';
import { jobConfig } from './jobs/build/job-config';
import { typecheckWerftJobs } from './jobs/build/typecheck-werft-jobs';
import { publishKotsUnstable } from './jobs/build/publish-kots-unstable'

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

await deployToPreviewEnvironment(werft, config)
await triggerIntegrationTests(werft, config, context.Owner)
await publishKotsUnstable(werft, config)
}
39 changes: 39 additions & 0 deletions .werft/jobs/build/publish-kots-unstable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { exec } from '../../util/shell';
import { Werft } from "../../util/werft";
import { JobConfig } from "./job-config";

const phases = {
PUBLISH_KOTS_UNSTABLE: 'publish kots unstable',
};

const REPLICATED_SECRET = 'replicated';
const REPLICATED_CHANNEL = 'Unstable';
const REPLICATED_YAML_DIR = './install/kots/manifests';
const INSTALLER_JOB_IMAGE = 'spec.template.spec.containers[0].image';

export async function publishKotsUnstable(werft: Werft, config: JobConfig) {
if (config.mainBuild) {
werft.phase(phases.PUBLISH_KOTS_UNSTABLE, 'Publish unstable release to KOTS');

const imageAndTag = exec(`yq r ${REPLICATED_YAML_DIR}/gitpod-installer-job.yaml ${INSTALLER_JOB_IMAGE}`);
const [image] = imageAndTag.split(':');

// Set the tag to the current version
exec(`yq w -i ${REPLICATED_YAML_DIR}/gitpod-installer-job.yaml ${INSTALLER_JOB_IMAGE} ${image}:${config.version}`);

const app = exec(`kubectl get secret ${REPLICATED_SECRET} --namespace werft -o jsonpath='{.data.app}' | base64 -d`);
const token = exec(`kubectl get secret ${REPLICATED_SECRET} --namespace werft -o jsonpath='{.data.token}' | base64 -d`);

exec(`replicated release create \
--lint \
--ensure-channel \
--app ${app} \
--token ${token} \
--yaml-dir ${REPLICATED_YAML_DIR} \
--version ${config.version} \
--release-notes "# ${config.version}\n\nSee [Werft job](https://werft.gitpod-dev.com/job/gitpod-build-${config.version}/logs) for notes" \
--promote ${REPLICATED_CHANNEL}`);

werft.done(phases.PUBLISH_KOTS_UNSTABLE);
}
}

0 comments on commit 543bcac

Please sign in to comment.