Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5
- name: Check out repository
uses: actions/checkout@v5

- uses: actions/setup-node@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

steps:
- name: Check out repository
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
Expand All @@ -44,7 +44,7 @@ jobs:
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v4

- name: Build and push image
uses: docker/build-push-action@v7
Expand All @@ -62,7 +62,6 @@ jobs:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
image: ${{ env.IMAGE_URI }}:${{ github.sha }}
service_account: ${{ env.CLOUD_RUN_SERVICE_ACCOUNT }}
env_vars: |
NODE_ENV=production
DB_CONNECTION_TYPE=cloud-sql-iam
Expand All @@ -73,6 +72,7 @@ jobs:
REDIS_PORT=6379
REDIS_TTL_SECONDS=60
flags: |
--service-account=${{ env.CLOUD_RUN_SERVICE_ACCOUNT }}
--network=default
--subnet=default
--vpc-egress=private-ranges-only
Expand Down
51 changes: 10 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,48 +249,9 @@ USE student_progress;
SHOW TABLES;
```

### 3. First deployment
### 3. GitHub Actions Authentication (OIDC)

1. Authenticate Docker with Artifact Registry

```bash
gcloud auth configure-docker europe-west3-docker.pkg.dev
```

2. Build and tag the image

```bash
docker buildx build \
--platform linux/amd64 \
-t europe-west3-docker.pkg.dev/student-progress-staging/student-progress-api/student-progress-api:latest \
.
```

3. Push to the Artifact Registry

```bash
docker push europe-west3-docker.pkg.dev/student-progress-staging/student-progress-api/student-progress-api:latest
```

4. Deploy to Cloud Run (with CloudSQL & Redis)

```bash
gcloud run deploy student-progress-api \
--image europe-west3-docker.pkg.dev/student-progress-staging/student-progress-api/student-progress-api:latest \
--region europe-west3 \
--service-account=student-progress-app-sa@student-progress-staging.iam.gserviceaccount.com \
--network default \
--subnet default \
--vpc-egress private-ranges-only \
--allow-unauthenticated \
--set-env-vars "NODE_ENV=production,DB_CONNECTION_TYPE=cloud-sql-iam,DB_INSTANCE_CONNECTION_NAME=student-progress-staging:europe-west3:student-progress-mysql-staging,DB_USER=student-progress-app-sa,DB_NAME=student_progress,REDIS_HOST=<REDIS_HOST>,REDIS_PORT=6379,REDIS_TTL_SECONDS=60"
```

Note: Replace `<REDIS_HOST>` with the Memorystore private IP.

Subsequent deployments are handled with GitHub Actions.

### 4. GitHub Actions Authentication (OIDC)
Deployments are handled automatically via GitHub Actions.

GitHub Actions authenticates to GCP using Workload Identity Federation (OIDC) instead of long-lived JSON service account keys.

Expand All @@ -310,6 +271,14 @@ Add these Terraform outputs as GitHub Actions repository secrets:
| GCP_WORKLOAD_IDENTITY_PROVIDER | github_workload_identity_provider_name |
| GCP_SERVICE_ACCOUNT | github_deployer_service_account_email |

## Deployment

Deployments are handled automatically via GitHub Actions.

Push to the `dev` branch to deploy to staging.

Push to the `main` branch to deploy to production.

## One-off Local Development Setup

### 1. **Install Auth Proxy & update dev script**
Expand Down