Skip to content

Commit

Permalink
Push to KOTS on each branch
Browse files Browse the repository at this point in the history
It either pushes to the "unstable" channel if on the main branch, or
the branch name if not.
  • Loading branch information
Simon Emms committed Mar 30, 2022
1 parent 60a9c55 commit ebbcef2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .werft/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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'
import { publishKots } from './jobs/build/publish-kots';

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

await deployToPreviewEnvironment(werft, config)
await triggerIntegrationTests(werft, config, context.Owner)
await publishKotsUnstable(werft, config)
await publishKots(werft, config)
}
39 changes: 0 additions & 39 deletions .werft/jobs/build/publish-kots-unstable.ts

This file was deleted.

38 changes: 38 additions & 0 deletions .werft/jobs/build/publish-kots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { exec } from '../../util/shell';
import { Werft } from "../../util/werft";
import { JobConfig } from "./job-config";

const phases = {
PUBLISH_KOTS: 'publish kots',
};

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

export async function publishKots(werft: Werft, config: JobConfig) {
werft.phase(phases.PUBLISH_KOTS, 'Publish 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`);

const replicatedChannel = config.mainBuild ? 'Unstable' : config.repository.branch;

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 ${replicatedChannel}`);

werft.done(phases.PUBLISH_KOTS);
}

0 comments on commit ebbcef2

Please sign in to comment.