Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/scripts/deploy-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -o pipefail
set -u

VERBOSE="${VERBOSE:-0}"
if [[ "${VERBOSE}" -ne "0" ]]; then
set -x
fi

# List of required environment variables
required_vars=(
"GCLOUD_API_KEY"
"GCLOUD_PROD_DEPLOY_SECRET"
"GCLOUD_DEV_DEPLOY_SECRET"
)

# Check if each required variable is set
for var in "${required_vars[@]}"; do
if [[ -z "${!var:-}" ]]; then
echo "Error: Environment variable '$var' is not set."
exit 1
fi
done

# Trigger a build for dev
# DONT EVER SET ANY FLAGS THAT MIGHT PRINT THE URL, AS IT HAS SECRETS IN IT
curl -X POST "https://cloudbuild.googleapis.com/v1/projects/coder-registry-1/triggers/http-build-registry-v2-dev:webhook?key=${GCLOUD_API_KEY}&secret=${GCLOUD_DEV_DEPLOY_SECRET}" \
-H "Content-Type: application/json" \
-d '{}' \
--fail
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely convinced about this approach. We could maybe instead trigger a build using the gcloud CLI (ref: https://cloud.google.com/sdk/gcloud/reference/builds/triggers/run) in combination with the setup-gcloud action (https://github.com/google-github-actions/setup-gcloud)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @deansheather for some additional eyes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely would prefer to use gcloud CLI rather than calling googleapis from curl. We also should not be using service account credentials as actions secrets, and should use workload identity instead. I can help you set that up with a new SA for this repo @bcpeinhardt

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secrets deleted, will update to use the gcloud cli, and yes some help with a service account would be great haha 😎

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll message you on Slack


# Trigger a build for prod
# DONT EVER SET ANY FLAGS THAT MIGHT PRINT THE URL, AS IT HAS SECRETS IN IT
curl -X POST "https://cloudbuild.googleapis.com/v1/projects/coder-registry-1/triggers/http-build-registry-v2-trigger:webhook?key=${GCLOUD_API_KEY}&secret=${GCLOUD_PROD_DEPLOY_SECRET}" \
-H "Content-Type: application/json" \
-d '{}' \
--fail
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this perhaps be a separate step in the workflow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I would even consider removing it from the workflow. Since we have a dev environment now a little delay to review there might not be the worst thing.

25 changes: 25 additions & 0 deletions .github/workflows/deploy-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: deploy-registry

on:
push:
branches:
- main

pull_request:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to deploy on each PR too?

Copy link
Collaborator Author

@bcpeinhardt bcpeinhardt Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I should pull that out, was moving too quickly, good catch 🙏

workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run deploy-registry.sh
run: |
./.github/scripts/deploy-registry.sh
env:
GCLOUD_API_KEY: ${{ secrets.GCLOUD_API_KEY }}
GCLOUD_PROD_DEPLOY_SECRET: ${{ secrets.GCLOUD_PROD_DEPLOY_SECRET }}
GCLOUD_DEV_DEPLOY_SECRET: ${{ secrets.GCLOUD_DEV_DEPLOY_SECRET }}

Loading