|
| 1 | +--- |
| 2 | +title: " GCP Quickstart" |
| 3 | +--- |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +Before starting, ensure you have the following: |
| 14 | + |
| 15 | +### 1. Google Cloud Setup |
| 16 | +- **gcloud CLI installed**: [Install the gcloud CLI](https://cloud.google.com/sdk/docs/install) |
| 17 | +- **Authenticated with Google Cloud**: Run `gcloud auth login` to authenticate |
| 18 | +- **Project ID configured**: Set your project with `gcloud config set project YOUR_PROJECT_ID` |
| 19 | +- **Billing enabled**: Ensure billing is enabled for your GCP project |
| 20 | + |
| 21 | +### 2. Docker |
| 22 | +- **Docker daemon running**: Ensure Docker is installed and running on your machine |
| 23 | +- **Docker authenticated**: You'll need to authenticate with both Docker Hub and Google Artifact Registry |
| 24 | + |
| 25 | +### 3. AWS Resources |
| 26 | +- **S3 bucket created**: Create an S3 bucket for storing Terraform state and artifacts |
| 27 | +- **AWS credentials**: Have your AWS Access Key ID and Secret Access Key ready |
| 28 | +- **IAM permissions**: Ensure your AWS credentials have permissions to read/write to the S3 bucket |
| 29 | + |
| 30 | +### 4. Auth0 Setup |
| 31 | +- **Auth0 application**: Create an Auth0 application and note your domain, client ID, and client secret. You should follow the guide in [Configure SSO](./sso), you won't have the server url until the server is up but you don't need to set that right away. |
| 32 | + |
| 33 | + |
| 34 | +## Configuration |
| 35 | + |
| 36 | +For GCP, you'll need to set up environment variables and then deploy to Cloud Run. |
| 37 | + |
| 38 | +First, create a `cloud-run.env.yaml` file with your configuration: |
| 39 | + |
| 40 | +```yaml |
| 41 | +# S3 Storage Configuration |
| 42 | +OPENTACO_S3_BUCKET: "your-s3-bucket-name" |
| 43 | +OPENTACO_S3_REGION: "us-east-1" |
| 44 | +OPENTACO_S3_PREFIX: "your-prefix" |
| 45 | + |
| 46 | +# Auth0 Authentication Configuration |
| 47 | +OPENTACO_AUTH_ISSUER: "https://your-auth0-domain.auth0.com/" |
| 48 | +OPENTACO_AUTH_CLIENT_ID: "your_auth0_client_id" |
| 49 | +OPENTACO_AUTH_CLIENT_SECRET: "your_auth0_client_secret" |
| 50 | +OPENTACO_AUTH_AUTH_URL: "https://your-auth0-domain.auth0.com/authorize" |
| 51 | +OPENTACO_AUTH_TOKEN_URL: "https://your-auth0-domain.auth0.com/oauth/token" |
| 52 | + |
| 53 | +# AWS Credentials |
| 54 | +AWS_ACCESS_KEY_ID: "your_aws_access_key_id" |
| 55 | +AWS_SECRET_ACCESS_KEY: "your_aws_secret_access_key" |
| 56 | +AWS_REGION: "us-east-1" |
| 57 | + |
| 58 | +# Additional Statesman Configuration |
| 59 | +OPENTACO_PORT: "8080" |
| 60 | +OPENTACO_STORAGE: "s3" |
| 61 | +OPENTACO_AUTH_DISABLE: "false" |
| 62 | +``` |
| 63 | +
|
| 64 | +Then, use the following script to set up Artifact Registry and deploy to Cloud Run from the same directory as your cloud-run.env.yaml |
| 65 | +
|
| 66 | +```bash |
| 67 | +#!/bin/bash |
| 68 | +set -e |
| 69 | + |
| 70 | +# Set your project ID |
| 71 | +PROJECT_ID="YOUR_GCP_REPO" |
| 72 | +GCP_REPO_NAME="STATESMAN_ARTEFACT_NAME" |
| 73 | +GCP_REGION="us-central1" |
| 74 | + |
| 75 | +echo "Setting up Artifact Registry for Statesman..." |
| 76 | + |
| 77 | +# Enable all required APIs |
| 78 | +echo "Enabling required GCP APIs..." |
| 79 | +gcloud services enable artifactregistry.googleapis.com |
| 80 | +gcloud services enable run.googleapis.com |
| 81 | +gcloud services enable cloudbuild.googleapis.com |
| 82 | +gcloud services enable containerregistry.googleapis.com |
| 83 | + |
| 84 | +# Check if repository exists, create if it doesn't |
| 85 | +if ! gcloud artifacts repositories describe $GCP_REPO_NAME --location=$GCP_REGION >/dev/null 2>&1; then |
| 86 | + echo "Creating repository..." |
| 87 | + gcloud artifacts repositories create $GCP_REPO_NAME \ |
| 88 | + --repository-format=docker \ |
| 89 | + --location=$GCP_REGION \ |
| 90 | + --description="Repository for OpenTaco Statesman images" |
| 91 | +else |
| 92 | + echo "Repository already exists $GCP_REPO_NAME, skipping creation..." |
| 93 | +fi |
| 94 | + |
| 95 | +# Configure Docker auth |
| 96 | +gcloud auth configure-docker $GCP_REGION-docker.pkg.dev |
| 97 | + |
| 98 | +# Pull, tag, and push image |
| 99 | +docker pull --platform linux/amd64 ghcr.io/diggerhq/digger/taco-statesman:latest |
| 100 | +docker tag ghcr.io/diggerhq/digger/taco-statesman:latest \ |
| 101 | + $GCP_REGION-docker.pkg.dev/$PROJECT_ID/$GCP_REPO_NAME/taco-statesman:latest |
| 102 | +docker push $GCP_REGION-docker.pkg.dev/$PROJECT_ID/$GCP_REPO_NAME/taco-statesman:latest |
| 103 | + |
| 104 | +echo "Deploying to Cloud Run..." |
| 105 | +gcloud run deploy statesman \ |
| 106 | + --image $GCP_REGION-docker.pkg.dev/$PROJECT_ID/$GCP_REPO_NAME/taco-statesman:latest \ |
| 107 | + --region $GCP_REGION \ |
| 108 | + --platform managed \ |
| 109 | + --allow-unauthenticated \ |
| 110 | + --env-vars-file cloud-run.env.yaml |
| 111 | + |
| 112 | +echo "Artifact Registry and Cloud Run setup complete!" |
| 113 | +echo "Your image is now at: $GCP_REGION-docker.pkg.dev/$PROJECT_ID/$GCP_REPO_NAME/taco-statesman:latest" |
| 114 | +SERVICE_URL=$(gcloud run services describe statesman --region $GCP_REGION --format="value(status.url)") |
| 115 | +echo "Service URL: $SERVICE_URL" |
| 116 | +echo "Health check: $SERVICE_URL/readyz" |
| 117 | +``` |
| 118 | +
|
| 119 | +
|
| 120 | +Once this service is up you can configure Auth0 with its cloud run url. Go to your application, and add the GCP url like so: `[GCP URL]/oauth/oidc-callback`. |
| 121 | + |
| 122 | +Mine looks like this: https://statesman-1234567890.us-central1.run.app/oauth/oidc-callback |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +Then run `taco login`. If you have not setup taco before it will prompt you for a server url. If you have run taco login before, you can do `taco setup` to configure the server url. In either case you would set the cloud run url as the server url. |
| 127 | + |
| 128 | +When the CLI asked me to enter my OpenTaco server url I pasted in: https://statesman-1234567890.us-central1.run.app |
0 commit comments