Prerequisites

  • Trieve credentials (cloud or selfhosted)
  • Supabase credentials (cloud or selfhosted)
  • An AWS account
  • An S3 bucket to store the .tfstate file
  • An EC2 key pair
  • Your domain
  • An AWS CodeStar connection to the Duckie self-host repo
  • A registered domain with a valid certificate in AWS Certificate Manager
  • Terraform installed locally

S3 Bucket

Before configuring the Terraform repository, you must create an S3 bucket in the AWS Management Console to store your repository’s .tfstate file.
  1. Navigate to the AWS Console, use the search bar to find “S3”, and then click on Buckets.
  2. Next, click the Create bucket button.
  3. Specify a name for your bucket. This name will be referenced later in your Terraform configuration.

Key Pair

  1. To create the key pair, navigate to the EC2 dashboard > Network & Security > Key Pairs. Then click the Create key pair button.
  2. Create your key pair and provide a name. This name will be used later in the Terraform configuration.

Domain and Certificate

Navigate to AWS Certificate Manager. Request a new public certificate for the following:
  1. duckie.yourdomain.com
  2. *.duckie.yourdomain.com
Add the created CNAME values to your domain’s DNS configuration.

CodeStar Connection

  1. Navigate to Developer Tools > Settings > Connections.
  2. Click the Create connection button.
  3. Fill in the required fields and click Connect to GitHub.

Supabase Setup

Seeding

  1. Go to Supabase > SQL Editor
  2. Paste the .sql files in the seed folder and click “Run”

Create Buckets

  1. Go to seed/supabase_buckets.py
  2. Fill in the Supabase credentials
  3. Run pip install supabase
  4. Run python seed/supabase_buckets.py

3rd Party Integretions

In order to connect Duckie to 3rd party integrations (e.g. Slack, Zendesk, etc), you’ll need to create Apps on the respective services. To do so, follow the instructions in our selfhost integrations docs and add the Client IDs, Client Secrets, etc to the Secrets Manager described below.

Repository Setup and Deployment

After provisioning all prerequisite resources, proceed with the repository configuration and deployment steps.
  1. Clone the Repository Access the repository’s link and clone it to your local machine.
  2. Create a New Branch It is recommended to create a new branch for your environment changes (e.g., feature/my-new-environment).
  3. Create the Environment Directory In your IDE, copy an existing environment directory (e.g., prod or stg) to use as a template. Rename the copied folder to match your new environment. For this example, we will use selfhost.
  4. Configure the Provider Open the selfhost/providers.tf file and update the bucket attribute in the backend “s3” block with the name of the S3 bucket you created earlier.
  5. Create the Variables File Next, create a new file named selfhost.tfvars. This file will hold the specific variable values for your environment. Populate it with the following variables, adjusting the values for your scenario. Reach out to the Duckie team for important variables.
  6. Go to AWS Secrets Manager and create duckie-selfhost-backend and duckie-selfhost-frontend secrets. Fill out the environment variables using the templates in the secrests-templates folder.
  7. Update the proxy_pass values in docker/selfhost/frontend/nginx.conf
  8. Initialize Terraform Open your terminal, navigate to your new environment directory (e.g., duckie-selfhost-tf/selfhost/), and run the initialization command: terraform init
  9. Plan the Changes Run the plan command to preview the resources that will be created. Make sure you are referencing the correct variable file(s). terraform plan -var-file="secret.tfvars"
  10. Apply the Changes Run the apply command to deploy the infrastructure. Review the plan carefully and, when prompted, type yes to confirm. terraform apply -var-file="secret.tfvars"
  11. Once created, go to EC2 > Load balancers > your-project-alb, copy the DNS and create the following CNAME records:
    1. CNAME | duckie | ALB DNS
    2. CNAME | *.duckie | ALB DNS