This is a companion repository for the Modern Deployment course on Frontend Masters. The repository contains an example Go application that will be deployed to AWS.
This application is a social media platform for setting and sharing life goals and aspirations.
- User authentication with Google OAuth2
- Create and edit personal profiles (username, display name, bio, bio link, life aspirations, things I like to do)
- Share aspiration updates (create, edit, and delete)
- Leave nested comments on aspiration updates
- Like and unlike updates
- Follow and unfollow other users
- Browse recent users and updates
- User banning system (admin functionality)
- Go 1.24.2 or later
- Docker and Docker Compose
- PostgreSQL (if not using Docker)
- Google Cloud Console account for OAuth2 setup
- Ensure Docker and Docker Compose are installed
- Run
docker-compose up --detach
to start both the PostgreSQL database
- Go to the Google Cloud Console: https://console.cloud.google.com/
- Create a new project or select an existing one
- Navigate to "APIs & Services" > "Credentials"
- Click on "Create Credentials" and select "OAuth client ID"
- Set up the OAuth consent screen if prompted
- Choose "Web application" as the application type
- Set the name for your OAuth 2.0 client
- Add http://localhost:8080/auth/google/callback to "Authorized redirect URIs"
- Click "Create" and note down the Client ID and Client Secret
- Keep note of credentials to use in
.env
file later
docker compose exec postgres psql -U postgres -d postgres
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
bio TEXT,
bio_link VARCHAR(255),
username VARCHAR(50) UNIQUE NOT NULL,
display_name VARCHAR(100),
profile_image_url TEXT,
life_aspirations TEXT,
things_i_like_to_do TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
is_logged_in BOOLEAN DEFAULT FALSE,
is_banned BOOLEAN DEFAULT FALSE
);
CREATE TABLE administrators (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
username VARCHAR(255) UNIQUE NOT NULL
);
CREATE TABLE aspiration_updates (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
content TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE likes (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
update_id INTEGER REFERENCES aspiration_updates(id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
UNIQUE (user_id, update_id)
);
CREATE TABLE followers (
follower_id INTEGER REFERENCES users(id),
followed_id INTEGER REFERENCES users(id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (follower_id, followed_id)
);
CREATE TABLE comments (
id SERIAL PRIMARY KEY,
update_id INTEGER REFERENCES aspiration_updates(id),
user_id INTEGER REFERENCES users(id),
parent_id INTEGER REFERENCES comments(id),
content TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
Then once you login to the app, add yourself as admin
INSERT INTO administrators (email, username)
SELECT email, username
FROM users
WHERE email = '[email protected]';
- Copy
.env.example
to create new.env
file - Update
.env
file with OAuth credentials - Source
.env
withsource .env
- Start server with
go run main.go
- Navigate to http://localhost:8080
The resources and code snippets below are reference throughout the Fullstack Deployment: From Containers to Production AWS course.
To follow along with the course, you will need:
- Go version 1.24.2 or later
- Docker Desktop
- Download and install Docker Desktop
- Important: Check "Enable host networking" under
Settings > Resources > Network
- Google Cloud Console
- Log into the Google Cloud Console
- You'll create an OAuth Client during the course
- AWS
- Create an AWS Root User account and log into the AWS Console
- Install the AWS CLI
- In the course, you'll create an Administrator User in IAM for the CLI and set environment variables in your console to authenticate the CLI
- Terraform
- Install the Terraform CLI
- Supabase
- Create a Supabase account
In the AWS Parameter Store lesson, copy and paste this JSON code when you are creating the IAM policy for the AWS App Runner:
{
"Statement": [
{
"Action": ["ssm:GetParameters"],
"Effect": "Allow",
"Resource": ["arn:aws:ssm:us-west-2:<ACCOUNT_ID>:parameter/fem-fd-service/*"]
}
],
"Version": "2012-10-17"
}
In the App Runner IAM Role lesson, copy and paste this JSON code when you are creating the IAM Role for the AWS App Runner:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": ["tasks.apprunner.amazonaws.com"]
},
"Action": ["sts:AssumeRole"],
}
],
}
The application uses goose for database migrations. Install goose:
go install github.com/pressly/goose/v3/cmd/goose@latest
Then verify the installation by running goose -version
Note: If you see a command not found: goose
error when trying to run goose, it's because the $HOME/go/bin
directory is not added to your PATH. You can fix this temporarily by running export PATH=$HOME/go/bin:$PATH
, but this will not persist if you close your terminal. A permanent fix would require adding export PATH=$HOME/go/bin:$PATH
to your .zshrc or .bashrc.
When you are deploying the fm-fd-service with Terraform, Erik covers some troubleshooting tips throughout the lesson. Here are some additional troubleshooting tips:
Clean up your local docker images and push up a fresh image to ECR
# You first may need to log (Go to ECR > Click on your image > View Push Command)
# aws ecr get-login-password......
# Clean up your existing image builds
`docker system prune --all && docker buildx prune --all`
# Build a new image for staging and push it to ECR
make build-image
make BUILD_TAG="staging" build-image-promote
Destroy and Reapply the Terraform configuration If you visit ECS and your staging cluster has 0 Container Instances (or there are any other issues you can't resolve), you likely have an issue with your Terraform configuration. Firstly, tear down the existing infrastructure:
terraform destroy
Confirm your terraform configuration matches this commit on Erik's workshop branch. Then redeploy the infrastructure with the init, plan and apply commands:
terraform init
terraform plan -out "terraform.tfplan"
terraform apply "terraform.tfplan"
Once you complete the course, you'll need to remove all the AWS resources to avoid changes:
- Run
terraform destroy
to remove all resources created by Terraform - Navigate to AWS App Runner, click on your App Runner instance and choose
Actions > Delete
- Navigate to AWS Parameter Store and delete the
fm-fd-service
parameters (the others should have been removed by runningterraform destroy
) - Navigate to ECR and delete your container
- Delete your Supabase database
You can monitor your AWS changes in the Cost Explorer
This project is proprietary and closed source. All rights reserved. Unauthorized use, reproduction, or distribution of this software is strictly prohibited.