This application can be deployed to both Heroku and Google Cloud Platform (GCP).
- Install the Google Cloud SDK
- Authenticate with GCP:
gcloud auth login gcloud config set project YOUR_PROJECT_ID - Enable required APIs:
gcloud services enable cloudbuild.googleapis.com gcloud services enable run.googleapis.com gcloud services enable containerregistry.googleapis.com
This method uses Cloud Build to build the Docker image and deploy to Cloud Run:
# Submit build to Cloud Build and deploy
npm run gcp:buildThe cloudbuild.yaml configuration will:
- Install dependencies
- Build a Docker image
- Push to Google Container Registry
- Deploy to Cloud Run
Deploy directly from source code (Cloud Run will build the container):
npm run gcp:deployThis command will:
- Build the container using the Dockerfile
- Deploy to Cloud Run in us-central1 region
- Make the service publicly accessible
For more control over the deployment process:
# Build the Docker image locally
docker build -t gcr.io/YOUR_PROJECT_ID/l0175:latest .
# Push to Container Registry
docker push gcr.io/YOUR_PROJECT_ID/l0175:latest
# Deploy to Cloud Run
gcloud run deploy l0175 \
--image gcr.io/YOUR_PROJECT_ID/l0175:latest \
--platform managed \
--region us-central1 \
--port 50175 \
--allow-unauthenticated \
--set-env-vars AUTH_URL=https://auth.graffiticode.orgConfigure environment variables in Cloud Run:
PORT: Automatically set by Cloud Run (the app defaults to 50175)AUTH_URL: Authentication service URL (default: https://auth.graffiticode.org)NODE_ENV: Set toproductionin the Dockerfile
To update environment variables:
gcloud run services update l0175 \
--region us-central1 \
--set-env-vars AUTH_URL=https://your-auth-url.comView application logs:
npm run gcp:logsOr use the GCP Console to monitor:
- Cloud Run: https://console.cloud.google.com/run
- Cloud Build: https://console.cloud.google.com/cloud-build
- Logs: https://console.cloud.google.com/logs
After deployment with --no-traffic flag in Cloud Build, you need to route traffic:
# Route 100% traffic to the latest revision
gcloud run services update-traffic l0175 \
--region us-central1 \
--to-latest
# Or gradually roll out (canary deployment)
gcloud run services update-traffic l0175 \
--region us-central1 \
--to-revisions REVISION_NAME=10To map a custom domain:
gcloud run domain-mappings create \
--service l0175 \
--domain your-domain.com \
--region us-central1For Heroku deployment, the application uses the default Node.js buildpack:
-
Create a Heroku app:
heroku create your-app-name
-
Deploy:
git push heroku main
The application will use the npm start script defined in package.json.
The Dockerfile is configured for production deployment:
- Uses Node.js Alpine for smaller image size
- Installs only production dependencies
- Builds the application during image creation
- Exposes port 50175
The cloudbuild.yaml file defines the CI/CD pipeline:
- Installs dependencies
- Runs tests (when enabled)
- Builds and tags Docker image with commit SHA
- Deploys to Cloud Run with appropriate labels
The .gcloudignore file excludes:
- Node modules (rebuilt in container)
- Test files
- Development configuration
- Documentation files
- Build artifacts
- Port Configuration: Ensure the app uses
process.env.PORTand falls back to 50175 - Memory Limits: Cloud Run defaults to 256MB. Increase if needed:
gcloud run services update l0175 --memory 512Mi --region us-central1
- Cold Starts: Cloud Run may have cold starts. Consider minimum instances:
gcloud run services update l0175 --min-instances 1 --region us-central1
To roll back to a previous revision:
# List revisions
gcloud run revisions list --service l0175 --region us-central1
# Route traffic to specific revision
gcloud run services update-traffic l0175 \
--region us-central1 \
--to-revisions REVISION_NAME=100