This project mainly utilises Google Cloud Platform products to achieve high scalability and availability. Cloudflare Registrar and proxied DNS are also used on top of Google Cloud services to protect the site and APIs from DDoS attacks and to optimize images.
- Frontend (Next.js): https://github.com/Christian-007/fit-forge-nextjs
- Core API (Go): https://github.com/Christian-007/fit-forge
- Notification API (Go): https://github.com/Christian-007/fit-forge-notification
- Scheduler (Go): https://github.com/Christian-007/fit-forge-scheduler
- Language:
Go - Event-driven library:
Watermill - Cloud:
Cloudflare,Cloud Run,API Gateway,Pub/Sub,Load Balancer,GCS Bucket,Secret Manager,Artifact Registry - Email testing:
Mailtrap - DB:
Redis,PostgreSQL
Before getting started, ensure you have done the following things:
- Install
Go - Install
Docker - Register for a Mailtrap account for sending test emails
To start this repo on your machine, do the following:
- Clone this repo
- Go to the repo directory on your machine
- Execute
go mod tidy && go mod vendor - Setup the environment variables in
./.envfile (see below for details) - Start
Dockeron your machine - Run
docker compose up -d - Run
make migrate_up_allfor running the DB migrations - Run
make generate_jwksto generate the necessary secrets - Finally,
make runto run the Go app with.envfile
This project is deployed to GCP Artifact Registry, Cloud Run and API Gateway using a combination of gcloud CLI and GCP Console. Before start deploying the app, do the following step:
- Authenticate a user using
gcloud auth application-default login --no-launch-browser(using--no-launch-browsersomehow that works)
- Login to GCP Console (https://console.cloud.google.com/)
- Select "Artifact Registry" menu
- Click "+ Create repository" button
- Name a repository (e.g.
my-app-prod-repo) - Ensure the format is
Dockerand useus-central1as the region or other regions that are within the Free tier - Click 'Create'
- Go back to the terminal and dockerize the app using
docker buildx build -t us-central1-docker.pkg.dev/{project-id}/{repository-name}/{app-name}:1.0.0 .command (note that the command ends with.) - Once the Docker image is created, we push it using
docker push us-central1-docker.pkg.dev/{project-id}/{repository-name}/{app-name}:1.0.0command
Note: project-id is the GCP project ID, repository-name is what you created on Step 1.4, app-name is the name of the app (can be anything)
- Go back to GCP Console and select or find "Cloud Run" menu
- Click "Services" > "+ Deploy Container"
- Choose "Artifact Registry | Docker Hub"
- Select the Docker image you just pushed as the "Container image URL"
- Pick a name for the Cloud Run service (e.g.
core-api) - Choose
us-central1as the region or any other region as long as it's the same region you choose for the Artifact Registry's repository - Setup the corresponding environment variables on "Containers, Volumes, Networking, Security" > "Containers" > "Variables & Secrets"
- Click "Create"
- Create an OpenAPI specification named
openapi.yamlin the repository (all of routes and their HTTP methods need to be defined in API Gateway) - Go to GCP Console and select "API Gateway" menu
- Create an API Gateway using the
openapi.yamlfile
That's the gist of deploying this repository on GCP.
Setup the following environment variables in ./.env file:
ENV=localhost
ROOT_DIR=/Users/folder/to/project
DB_USER=dbUser
POSTGRES_USER=someusername
POSTGRES_PASSWORD=somepassword
POSTGRES_MULTIPLE_DATABASES=main_dv,main_db_test
POSTGRES_URL=postgresql://someusername:somepassword@localhost:5433/fit_forge?sslmode=disable
POSTGRES_TEST_DB_URL=postgresql://root:password@localhost:5433/fit_forge_test?sslmode=disable
AUTH_SECRET_KEY=sup3rs3cr3t
REDIS_DSN=localhost:6379
REDIS_USERNAME=username
REDIS_PASSWORD=secret
EMAIL_HOST=https://sandbox.api.mailtrap.io
MAILTRAP_API_KEY=API_KEY
SUBSCRIPTION_INTERVAL_MINUTES=1
PUBSUB_PROJECT_ID=local-project
PUBSUB_EMULATOR_HOST=localhost:8085
JWT_ISSUER_CLAIM=your-app-url
JWT_AUDIENCE_CLAIM=your-app-audience
JWK_KEY_ID=your-app-jwk-key-id
GCP_SECRET_DIR=your-secrets-dir-on-gcp
FRONTEND_URL=http://localhost:3000
