|
| 1 | +import * as semver from 'semver'; |
| 2 | +import { exec } from '../../util/shell'; |
| 3 | +import { Werft } from '../../util/werft'; |
| 4 | +import { GCLOUD_SERVICE_ACCOUNT_PATH } from './const'; |
| 5 | +import { JobConfig } from './job-config'; |
| 6 | + |
| 7 | + |
| 8 | +export async function buildAndPublish(werft: Werft, jobConfig: JobConfig) { |
| 9 | + |
| 10 | + const { |
| 11 | + publishRelease, |
| 12 | + dontTest, |
| 13 | + withContrib, |
| 14 | + retag, |
| 15 | + version, |
| 16 | + localAppVersion, |
| 17 | + publishToJBMarketplace, |
| 18 | + publishToNpm, |
| 19 | + coverageOutput |
| 20 | + } = jobConfig |
| 21 | + |
| 22 | + const releaseBranch = jobConfig.repository.ref; |
| 23 | + |
| 24 | + werft.phase("build", "build running"); |
| 25 | + const imageRepo = publishRelease ? "gcr.io/gitpod-io/self-hosted" : "eu.gcr.io/gitpod-core-dev/build"; |
| 26 | + |
| 27 | + exec(`LICENCE_HEADER_CHECK_ONLY=true leeway run components:update-license-header || { echo "[build|FAIL] There are some license headers missing. Please run 'leeway run components:update-license-header'."; exit 1; }`) |
| 28 | + exec(`leeway vet --ignore-warnings`); |
| 29 | + exec(`leeway build --docker-build-options network=host --werft=true -c remote ${dontTest ? '--dont-test' : ''} --dont-retag --coverage-output-path=${coverageOutput} --save /tmp/dev.tar.gz -Dversion=${version} -DimageRepoBase=eu.gcr.io/gitpod-core-dev/dev dev:all`); |
| 30 | + |
| 31 | + if (publishRelease) { |
| 32 | + exec(`gcloud auth activate-service-account --key-file "/mnt/secrets/gcp-sa-release/service-account.json"`); |
| 33 | + } |
| 34 | + if (withContrib || publishRelease) { |
| 35 | + exec(`leeway build --docker-build-options network=host --werft=true -c remote ${dontTest ? '--dont-test' : ''} -Dversion=${version} -DimageRepoBase=${imageRepo} contrib:all`); |
| 36 | + } |
| 37 | + exec(`leeway build --docker-build-options network=host --werft=true -c remote ${dontTest ? '--dont-test' : ''} ${retag} --coverage-output-path=${coverageOutput} -Dversion=${version} -DremoveSources=false -DimageRepoBase=${imageRepo} -DlocalAppVersion=${localAppVersion} -DSEGMENT_IO_TOKEN=${process.env.SEGMENT_IO_TOKEN} -DnpmPublishTrigger=${publishToNpm ? Date.now() : 'false'} -DjbMarketplacePublishTrigger=${publishToJBMarketplace ? Date.now() : 'false'}`); |
| 38 | + if (publishRelease) { |
| 39 | + try { |
| 40 | + werft.phase("publish", "checking version semver compliance..."); |
| 41 | + if (!semver.valid(version)) { |
| 42 | + // make this an explicit error as early as possible. Is required by helm Charts.yaml/version |
| 43 | + throw new Error(`'${version}' is not semver compliant and thus cannot used for Self-Hosted releases!`) |
| 44 | + } |
| 45 | + |
| 46 | + werft.phase("publish", "publishing Helm chart..."); |
| 47 | + publishHelmChart(werft, "gcr.io/gitpod-io/self-hosted", version); |
| 48 | + |
| 49 | + werft.phase("publish", `preparing GitHub release files...`); |
| 50 | + const releaseFilesTmpDir = exec("mktemp -d", { silent: true }).stdout.trim(); |
| 51 | + const releaseTarName = "release.tar.gz"; |
| 52 | + exec(`leeway build --docker-build-options network=host --werft=true chart:release-tars -Dversion=${version} -DimageRepoBase=${imageRepo} --save ${releaseFilesTmpDir}/${releaseTarName}`); |
| 53 | + exec(`cd ${releaseFilesTmpDir} && tar xzf ${releaseTarName} && rm -f ${releaseTarName}`); |
| 54 | + |
| 55 | + werft.phase("publish", `publishing GitHub release ${version}...`); |
| 56 | + const prereleaseFlag = semver.prerelease(version) !== null ? "-prerelease" : ""; |
| 57 | + const tag = `v${version}`; |
| 58 | + const description = `Gitpod Self-Hosted ${version}<br/><br/>Docs: https://www.gitpod.io/docs/self-hosted/latest/self-hosted/`; |
| 59 | + exec(`github-release ${prereleaseFlag} gitpod-io/gitpod ${tag} ${releaseBranch} '${description}' "${releaseFilesTmpDir}/*"`); |
| 60 | + |
| 61 | + werft.done('publish'); |
| 62 | + } catch (err) { |
| 63 | + werft.fail('publish', err); |
| 64 | + } finally { |
| 65 | + exec(`gcloud auth activate-service-account --key-file "${GCLOUD_SERVICE_ACCOUNT_PATH}"`); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +/** |
| 71 | + * Publish Charts |
| 72 | + */ |
| 73 | +async function publishHelmChart(werft: Werft, imageRepoBase: string, version: string) { |
| 74 | + werft.phase("publish-charts", "Publish charts"); |
| 75 | + [ |
| 76 | + "gcloud config set project gitpod-io", |
| 77 | + `leeway build --docker-build-options network=host -Dversion=${version} -DimageRepoBase=${imageRepoBase} --save helm-repo.tar.gz chart:helm`, |
| 78 | + "tar xzfv helm-repo.tar.gz", |
| 79 | + "mkdir helm-repo", |
| 80 | + "cp gitpod*tgz helm-repo/", |
| 81 | + "gsutil cp gs://charts-gitpod-io-public/index.yaml old-index.yaml", |
| 82 | + "cp gitpod*.tgz helm-repo/", |
| 83 | + "helm3 repo index --merge old-index.yaml helm-repo", |
| 84 | + "gsutil -m rsync -r helm-repo/ gs://charts-gitpod-io-public/" |
| 85 | + ].forEach(cmd => { |
| 86 | + exec(cmd, { slice: 'publish-charts' }); |
| 87 | + }); |
| 88 | +} |
0 commit comments