forked from gitpod-io/gitpod
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This relaxes the branch name restriction from 20 characters to 45. This is achieved by constructing the preview name based on the first 10 characters of the branch name and then the first 10 characters of the hashed value of the branch name. All places that (to my knowledge) rely on the preview name has been updated. Fixes gitpod-io/ops#1252
- Loading branch information
1 parent
c10b2c9
commit afa2bd1
Showing
12 changed files
with
94 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createHash } from "crypto"; | ||
|
||
/** | ||
* Based on the current branch name this will compute the name of the associated | ||
* preview environment. | ||
* | ||
* NOTE: This needs to produce the same result as the function in dev/preview/util/preview-name-from-branch.sh | ||
*/ | ||
export function previewNameFromBranchName(branchName: string): string { | ||
// Due to various limitations we have to ensure that we only use 20 characters | ||
// for the preview environment name. | ||
// | ||
// We use the first 10 chars of the sanitized branch name | ||
// and then the 10 first chars of the hash of the sanitized branch name | ||
// | ||
// That means collisions can happen. If they do, two jobs would try to deploy to the same | ||
// environment. | ||
// | ||
// see https://github.com/gitpod-io/ops/issues/1252 for details. | ||
const sanitizedBranchName = branchName.replace(/^refs\/heads\//, "").toLocaleLowerCase().replace(/[^-a-z0-9]/g, "-") | ||
const hashed = createHash('sha256').update(sanitizedBranchName).digest('hex') | ||
return `${sanitizedBranchName.substring(0, 10)}${hashed.substring(0,10)}` | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Based on the name of the current branch this will compute the name of the associated | ||
# preview environment. | ||
# | ||
# NOTE: This needs to produce the same result as the function in .werft/util/preview.ts | ||
# See the file for implementation notes. | ||
# | ||
function preview-name-from-branch { | ||
branch_name=$(git symbolic-ref HEAD 2>&1) || error "Cannot get current branch" | ||
sanitizedd_branch_name=$(echo "$branch_name" | awk '{ sub(/^refs\/heads\//, ""); $0 = tolower($0); gsub(/[^-a-z0-9]/, "-"); print }') | ||
hashed=$(echo -n "${sanitizedd_branch_name}" | sha256sum) | ||
echo "${sanitizedd_branch_name:0:10}${hashed:0:10}" | ||
} |
This file contains 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,8 +1,9 @@ | ||
#!/bin/bash | ||
|
||
branch=$(git symbolic-ref HEAD 2>&1) || error "cannot set kubectl namespace: no branch" | ||
source ./dev/preview/util/preview-name-from-branch.sh | ||
|
||
currentContext=$(kubectl config current-context 2>&1) || error "cannot set kubectl namespace: no current context" | ||
namespace=staging-$(echo "$branch" | awk '{ sub(/^refs\/heads\//, ""); $0 = tolower($0); gsub(/[^-a-z0-9]/, "-"); print }') | ||
namespace="staging-$(preview-name-from-branch)" | ||
|
||
echo "Setting kubectl namespace: $namespace" | ||
kubectl config set-context "$currentContext" --namespace "$namespace" |