Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request Preview Environments #456

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MelissaAutumn
Copy link
Member

@MelissaAutumn MelissaAutumn commented Jul 1, 2023

Woah! I finished this? Wild.

You can see a preview of this on my local repo:
MelissaAutumn#1

This PR brings preview environments to thunderbird-website! Simply attach the preview environment label to a PR, and in like 7 minutes you'll have a live instance of that PR. If the PR is updated, the workflow will re-run and generate two new instances and clean up the old ones. If you unattach the label or delete the PR it should also clean up.

Cleaning up is powered by tagging everything in AWS. I create a unique id derived from a particular PR, and use that to lookup specific resources to nuke before generating new instances (or not depending on if we're closing a PR.)

I may have overlooked a specific resource to be cleaned up but we can fix that later. The repository should clean up any images older than 7 days automatically.

I setup our preview.thunderbird.dev to wildcard to the load balancer used. And the target groups for that load balancer directs the user to the correct fargate instance. (That was a pain to setup.)

There should be a user setup with the required permissions, but I may have missed one here or there. The task definitions should be created on upload, so don't worry about that.

Most importantly, this artfully crafts artisanal subdomains via a random name library, and a custom list of bird species I've scoured wikipedia for. (Do we need to attribute that?)

I believe I've updated all the hardcoded references, apologies if I didn't.

You'll need to setup the following secrets:

  • AWS_ACCESS_KEY_ID - Access key of the IAM user
  • AWS_SECRET_ACCESS_KEY - The secret access key for the IAM user
  • AWS_AVAIL_REGION - This one is dumb, it's the availability region, so probably us-west-2a or 2b. This lives in the load balancer
  • AWS_LISTENER_ARN - The HTTPS:443 listener on the load balancer's arn
  • AWS_LOAD_BALANCER_ARN - The load balancer arn
  • AWS_SUBNETS - The subnets to use, I was lazy and put this in a secret. This needs to be a list of strings, so grab the two subnets and enter them as "subnet-arn-1","subnet-arn-2" (Use double quotes)
  • AWS_SECURITY_GROUPS - Similar to subnets: "security-group-1","security-group-2", if there's only one then just put one string value. (Use double quotes)
  • AWS_VPC_ID - VPC ID
  • PREVIEW_HOST_URL - preview.thunderbird.dev.
  • PREVIEW_IS_SECURE - 1

I've named everything with preview-env, so look for those 😄

I'll answer any particular questions when I'm able to, but it may be a bit.


// Reference: https://docs.aws.amazon.com/cli/latest/reference/elbv2/register-targets.html
const target = await waitFor(
`aws elbv2 register-targets --target-group-arn ${target_group} --targets Id=${private_ip},Port=80,AvailabilityZone=${aws_avail_region} --output json`, (value) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`aws elbv2 register-targets --target-group-arn ${target_group} --targets Id=${private_ip},Port=80,AvailabilityZone=${aws_avail_region} --output json`, (value) => {
`aws elbv2 register-targets --target-group-arn ${target_group} --targets Id=${private_ip},Port=${port},AvailabilityZone=${aws_avail_region} --output json`, (value) => {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, missed this. I didn't have a SSL cert to play around with, so I'm hoping that part works :^)

@bogomil
Copy link
Contributor

bogomil commented Jan 25, 2024

That's a pure gold. Can we have this merged please! Thanks @MelissaAutumn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants