Skip to content

Commit 575956a

Browse files
authored
feat(deploy): Add scripts for simplified deployment (#1906)
* feat(deploy): Add scripts for simplified deployment Adds three new scripts to streamline the deployment process: - deploy-staging: Deploys the application to the staging environment. - deploy-production: Deploys the application to the production environment. - create-deployment-issue: Automates the creation of a GitHub release issue. These scripts are made available as commands within the dev container by adding their directory to the PATH in the Dockerfile. The scripts include robust checks to ensure they are run from the project root and handle GitHub authentication. This change simplifies the deployment workflow, reducing manual steps and potential for error, as outlined in the deployment runbook. * Remove debugging code. * Remove stray file and update DEPLOYMENT.md. * Use a way cleaner way to test if we're in the root of the project per review feedback from James. * Use more robust way of ensuring we're in the project root everywhere.
1 parent 62f9d9c commit 575956a

5 files changed

Lines changed: 172 additions & 62 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ RUN apt-get update && apt-get install -y netcat-traditional
4141
# Switch to the default user and append to PATH
4242
USER vscode
4343

44-
RUN echo 'PATH=${PATH}:/google-cloud-sdk/bin' >> ~/.bashrc
44+
RUN echo 'PATH=${PATH}:/google-cloud-sdk/bin:/workspaces/webstatus.dev/util/deployment' >> ~/.bashrc

DEPLOYMENT.md

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -111,67 +111,10 @@ Also, remove your domain from the allow-list of domains in the [console](https:/
111111
112112
## Deploy Staging
113113
114-
```sh
115-
make build
116-
cd infra
117-
gcloud auth login
118-
gcloud auth application-default login --project=web-compass-staging
119-
gcloud auth configure-docker europe-west1-docker.pkg.dev --quiet
120-
ENV_ID="staging"
121-
export TF_WORKSPACE=${ENV_ID}
122-
terraform init -reconfigure --var-file=.envs/staging.tfvars --backend-config=.envs/backend-staging.tfvars
123-
terraform plan \
124-
-var-file=".envs/staging.tfvars" \
125-
-var "env_id=${ENV_ID}"
126-
```
127-
128-
Migrate the tables if any schemas changed (assuming you already authenticated with `gcloud auth application-default login`):
129-
130-
```sh
131-
export SPANNER_PROJECT_ID=webstatus-dev-internal-staging
132-
export SPANNER_DATABASE_ID=${ENV_ID}-database
133-
export SPANNER_INSTANCE_ID=${ENV_ID}-spanner
134-
go tool wrench migrate up --directory ./storage/spanner/
135-
```
136-
137-
Assuming the plan output by the terraform plan command looks fine, run:
138-
139-
```sh
140-
terraform apply \
141-
-var-file=".envs/staging.tfvars" \
142-
-var "env_id=${ENV_ID}"
143-
```
114+
Run the script `deploy-staging` in the devcontainer and follow the output and
115+
prompts to complete the deployment.
144116
145117
## Deploy Prod
146118
147-
```sh
148-
make build
149-
cd infra
150-
gcloud auth login
151-
gcloud auth application-default login --project=web-compass-prod
152-
gcloud auth configure-docker europe-west1-docker.pkg.dev --quiet
153-
ENV_ID="prod"
154-
export TF_WORKSPACE=${ENV_ID}
155-
terraform init -reconfigure --var-file=.envs/prod.tfvars --backend-config=.envs/backend-prod.tfvars
156-
157-
terraform plan \
158-
-var-file=".envs/prod.tfvars" \
159-
-var "env_id=${ENV_ID}"
160-
```
161-
162-
Migrate the tables if any schemas changed (assuming you already authenticated with `gcloud auth application-default login`):
163-
164-
```sh
165-
export SPANNER_PROJECT_ID=webstatus-dev-internal-prod
166-
export SPANNER_DATABASE_ID=${ENV_ID}-database
167-
export SPANNER_INSTANCE_ID=${ENV_ID}-spanner
168-
go tool wrench migrate up --directory ./storage/spanner/
169-
```
170-
171-
Assuming the plan output by the terraform plan command looks fine, run:
172-
173-
```sh
174-
terraform apply \
175-
-var-file=".envs/prod.tfvars" \
176-
-var "env_id=${ENV_ID}"
177-
```
119+
Run the script `deploy-production` in the devcontainer and follow the output and
120+
prompts to complete the deployment.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Ensure we are in the project root
5+
if [ "$(git rev-parse --git-dir 2>/dev/null)" != ".git" ]; then
6+
echo "Please run this script from the root of the webstatus.dev repository."
7+
exit 1
8+
fi
9+
10+
echo "Checking GitHub CLI authentication status..."
11+
if ! gh auth status > /dev/null 2>&1; then
12+
echo "You are not logged into the GitHub CLI. Starting login process..."
13+
gh auth login
14+
# Re-check auth status after login attempt
15+
if ! gh auth status > /dev/null 2>&1; then
16+
echo "GitHub login failed. Please run 'gh auth login' manually and try again."
17+
exit 1
18+
fi
19+
fi
20+
echo "Authenticated."
21+
22+
echo "Creating GitHub release issue..."
23+
24+
PREVIOUS_SHORT_SHA=$(gh issue list --state=closed --label="release" --json title --repo "GoogleChrome/webstatus.dev" | jq -r '.[0].title' | awk '{print $NF}')
25+
if [ -z "$PREVIOUS_SHORT_SHA" ]; then
26+
echo "Could not determine the previous release SHA. Please check closed release issues."
27+
exit 1
28+
fi
29+
30+
CHANGELOG=$(git log --oneline "$PREVIOUS_SHORT_SHA..HEAD" --format="- %C(auto) %h %s")
31+
NEW_SHA=$(git rev-parse --short HEAD)
32+
33+
DIRTY_PREFIX=""
34+
if [[ -n $(git status --porcelain) ]]; then
35+
DIRTY_PREFIX="(contains uncommitted changes) "
36+
fi
37+
38+
ISSUE_TITLE="Deploy $DIRTY_PREFIX$NEW_SHA"
39+
ISSUE_BODY=$(cat << EOF
40+
Changelist $PREVIOUS_SHORT_SHA...$NEW_SHA
41+
42+
Changes:
43+
44+
$CHANGELOG
45+
46+
This push is happening as part of the regular weekly push.
47+
EOF
48+
)
49+
50+
echo "Creating issue with the following details:"
51+
echo "---"
52+
echo "Title: $ISSUE_TITLE"
53+
echo "Body:"
54+
echo "$ISSUE_BODY"
55+
echo "---"
56+
echo "Press enter to create the issue, or Ctrl+C to cancel."
57+
read
58+
59+
gh issue create --title "$ISSUE_TITLE" --body "$ISSUE_BODY" --label "release" -R "GoogleChrome/webstatus.dev"
60+
61+
if [[ $? != 0 ]]; then
62+
echo "GitHub issue creation failed."
63+
exit 1
64+
fi
65+
66+
echo "Successfully created GitHub issue."

util/deployment/deploy-production

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Starting production deployment..."
5+
6+
# Ensure we are in the project root
7+
if [ "$(git rev-parse --git-dir 2>/dev/null)" != ".git" ]; then
8+
echo "Please run this script from the root of the webstatus.dev repository."
9+
exit 1
10+
fi
11+
12+
echo "Building..."
13+
make build
14+
15+
cd infra
16+
17+
echo "Authenticating with gcloud..."
18+
gcloud auth login
19+
gcloud auth application-default login --project=web-compass-prod
20+
gcloud auth configure-docker europe-west1-docker.pkg.dev --quiet
21+
22+
ENV_ID="prod"
23+
export TF_WORKSPACE=${ENV_ID}
24+
25+
echo "Initializing Terraform..."
26+
terraform init -reconfigure --var-file=.envs/prod.tfvars --backend-config=.envs/backend-prod.tfvars
27+
28+
echo "Planning Terraform changes..."
29+
terraform plan \
30+
-var-file=".envs/prod.tfvars" \
31+
-var "env_id=${ENV_ID}"
32+
33+
echo
34+
echo "Review the plan above. If it looks correct, you will be prompted to apply the changes."
35+
echo "Press enter to continue, or Ctrl+C to cancel."
36+
read
37+
38+
echo "Migrating database schema (if needed)..."
39+
export SPANNER_PROJECT_ID=webstatus-dev-internal-prod
40+
export SPANNER_DATABASE_ID=${ENV_ID}-database
41+
export SPANNER_INSTANCE_ID=${ENV_ID}-spanner
42+
(cd .. && go tool wrench migrate up --directory ./infra/storage/spanner/)
43+
44+
echo "Applying Terraform changes..."
45+
terraform apply \
46+
-var-file=".envs/prod.tfvars" \
47+
-var "env_id=${ENV_ID}"
48+
49+
echo "Production deployment complete."
50+
echo "Please verify the deployment at https://webstatus.dev/ and https://api.webstatus.dev/v1/features"
51+
echo "Remember to close the GitHub release issue."

util/deployment/deploy-staging

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Starting staging deployment..."
5+
6+
# Ensure we are in the project root
7+
if [ "$(git rev-parse --git-dir 2>/dev/null)" != ".git" ]; then
8+
echo "Please run this script from the root of the webstatus.dev repository."
9+
exit 1
10+
fi
11+
12+
echo "Building..."
13+
make build
14+
15+
cd infra
16+
17+
echo "Authenticating with gcloud..."
18+
gcloud auth login
19+
gcloud auth application-default login --project=web-compass-staging
20+
gcloud auth configure-docker europe-west1-docker.pkg.dev --quiet
21+
22+
ENV_ID="staging"
23+
export TF_WORKSPACE=${ENV_ID}
24+
25+
echo "Initializing Terraform..."
26+
terraform init -reconfigure --var-file=.envs/staging.tfvars --backend-config=.envs/backend-staging.tfvars
27+
28+
echo "Planning Terraform changes..."
29+
terraform plan \
30+
-var-file=".envs/staging.tfvars" \
31+
-var "env_id=${ENV_ID}"
32+
33+
echo
34+
echo "Review the plan above. If it looks correct, you will be prompted to apply the changes."
35+
echo "Press enter to continue, or Ctrl+C to cancel."
36+
read
37+
38+
echo "Migrating database schema (if needed)..."
39+
export SPANNER_PROJECT_ID=webstatus-dev-internal-staging
40+
export SPANNER_DATABASE_ID=${ENV_ID}-database
41+
export SPANNER_INSTANCE_ID=${ENV_ID}-spanner
42+
(cd .. && go tool wrench migrate up --directory ./infra/storage/spanner/)
43+
44+
echo "Applying Terraform changes..."
45+
terraform apply \
46+
-var-file=".envs/staging.tfvars" \
47+
-var "env_id=${ENV_ID}"
48+
49+
echo "Staging deployment complete."
50+
echo "Please verify the deployment at https://website-webstatus-dev.corp.goog/ and https://api-webstatus-dev.corp.goog/v1/features"

0 commit comments

Comments
 (0)