-
Notifications
You must be signed in to change notification settings - Fork 1.3k
werft/build/prepare: Cleanup code #8643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,52 @@ | ||
import * as shell from 'shelljs'; | ||
import { exec } from '../../util/shell'; | ||
import { Werft } from "../../util/werft"; | ||
import { GCLOUD_SERVICE_ACCOUNT_PATH } from "./const"; | ||
|
||
const phaseName = "prepare"; | ||
|
||
export async function prepare(werft: Werft) { | ||
werft.phase("prepare"); | ||
werft.phase(phaseName); | ||
try { | ||
compareWerftAndGitpodImage() | ||
activateCoreDevServiceAccount() | ||
configureDocker() | ||
configureCoreDevAccess() | ||
} catch (err) { | ||
werft.fail(phaseName, err); | ||
} | ||
werft.done(phaseName); | ||
} | ||
|
||
const werftImg = shell.exec("cat .werft/build.yaml | grep dev-environment").trim().split(": ")[1]; | ||
const devImg = shell.exec("yq r .gitpod.yml image").trim(); | ||
// TODO: The reasoning behind this step should be clarified | ||
function compareWerftAndGitpodImage() { | ||
const werftImg = exec("cat .werft/build.yaml | grep dev-environment", { silent: true }).trim().split(": ")[1]; | ||
const devImg = exec("yq r .gitpod.yml image", { silent: true }).trim(); | ||
if (werftImg !== devImg) { | ||
werft.fail('prep', `Werft job image (${werftImg}) and Gitpod dev image (${devImg}) do not match`); | ||
throw new Error(`Werft job image (${werftImg}) and Gitpod dev image (${devImg}) do not match`); | ||
} | ||
} | ||
|
||
try { | ||
exec(`gcloud auth activate-service-account --key-file "${GCLOUD_SERVICE_ACCOUNT_PATH}"`); | ||
exec("gcloud auth configure-docker --quiet"); | ||
exec("gcloud auth configure-docker europe-docker.pkg.dev --quiet"); | ||
exec('gcloud container clusters get-credentials core-dev --zone europe-west1-b --project gitpod-core-dev'); | ||
werft.done('prep'); | ||
} catch (err) { | ||
werft.fail('prep', err); | ||
function activateCoreDevServiceAccount() { | ||
const rc = exec(`gcloud auth activate-service-account --key-file "${GCLOUD_SERVICE_ACCOUNT_PATH}"`, { slice: phaseName }).code; | ||
|
||
if (rc != 0) { | ||
throw new Error("Failed to activate core-dev service account.") | ||
} | ||
} | ||
|
||
function configureDocker() { | ||
const rcDocker = exec("gcloud auth configure-docker --quiet", { slice: phaseName }).code; | ||
const rcDockerRegistry = exec("gcloud auth configure-docker europe-docker.pkg.dev --quiet", { slice: phaseName }).code; | ||
|
||
if (rcDocker != 0 || rcDockerRegistry != 0) { | ||
throw new Error("Failed to configure docker with gcloud.") | ||
} | ||
} | ||
|
||
function configureCoreDevAccess() { | ||
const rc = exec('gcloud container clusters get-credentials core-dev --zone europe-west1-b --project gitpod-core-dev', { slice: phaseName }).code; | ||
|
||
if (rc != 0) { | ||
throw new Error("Failed to get core-dev kubeconfig credentials.") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's because both images need to be updated separately and letting them go out of sync may cause weird follow-up errors.