Skip to content

Commit 2b9223c

Browse files
authored
Merge pull request #1979 from dannyprikaz/enforce-lowercase-db
Enforce that emails can only be stored in lowercase
2 parents 8fd5530 + a6ff776 commit 2b9223c

File tree

76 files changed

+5824
-2026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+5824
-2026
lines changed

.github/workflows/aws-backend-deploy.yml

Lines changed: 95 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ on:
44
inputs:
55
env:
66
type: choice
7-
description: 'AWS Incubator Env'
8-
options:
9-
- dev
10-
- prod
7+
description: "AWS Incubator Env"
8+
options:
9+
- dev
10+
- prod
1111
ref:
12-
description: 'Branch, Tag, or SHA'
12+
description: "Branch, Tag, or SHA"
1313
required: true
1414
env:
1515
AWS_SHARED_CLUSTER: incubator-prod
@@ -19,95 +19,108 @@ env:
1919
DOCKER_PATH: backend
2020
jobs:
2121
setup_env:
22-
name: Set-up environment
22+
name: Set-up environment
2323
runs-on: ubuntu-latest
2424
steps:
25-
- name: Debug Action
26-
uses: hmarr/debug-action@v1.0.0
27-
- name: Checkout
28-
uses: actions/checkout@v4
29-
with:
30-
ref: ${{ github.event.inputs.ref }}
31-
- name: Set AWS Env & Image Tag per workflow
32-
run: |
33-
SHORT_SHA=$(git rev-parse --short HEAD)
34-
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
35-
INPUT_ENV=${{ github.event.inputs.env }}; INPUT_REF=${{ github.event.inputs.ref }}
36-
echo AWS_APPENV="$AWS_APP_NAME"-$INPUT_ENV >> $GITHUB_ENV
37-
echo IMAGE_TAG=$SHORT_SHA >> $GITHUB_ENV
38-
fi
25+
- name: Debug Action
26+
uses: hmarr/debug-action@v1.0.0
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
with:
30+
ref: ${{ github.event.inputs.ref }}
31+
- name: Set AWS Env & Image Tag per workflow
32+
run: |
33+
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
34+
INPUT_ENV=${{ github.event.inputs.env }}; INPUT_REF=${{ github.event.inputs.ref }}
35+
echo AWS_APPENV="$AWS_APP_NAME"-$INPUT_ENV >> $GITHUB_ENV
36+
echo IMAGE_TAG=$(git rev-parse --short HEAD) >> $GITHUB_ENV
37+
echo BUILD_SHA=$(git rev-parse --short HEAD) >> $GITHUB_ENV
38+
fi
3939
outputs:
4040
AWS_APPENV: ${{ env.AWS_APPENV }}
4141
IMAGE_TAG: ${{ env.IMAGE_TAG }}
42+
BUILD_SHA: ${{ env.BUILD_SHA }}
4243
build:
4344
name: Build & Push Docker Image
4445
runs-on: ubuntu-latest
4546
needs: [setup_env]
4647
steps:
47-
- name: Checkout
48-
uses: actions/checkout@v4
49-
with:
50-
ref: ${{ github.event.inputs.ref }}
51-
- name: Configure AWS credentials
52-
uses: aws-actions/configure-aws-credentials@v1
53-
with:
54-
aws-access-key-id: ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
55-
aws-secret-access-key: ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
56-
aws-region: ${{ env.AWS_REGION }}
57-
- name: Login to Amazon ECR
58-
id: login-ecr
59-
uses: aws-actions/amazon-ecr-login@v1
60-
- name: Init Docker Cache
61-
uses: jpribyl/action-docker-layer-caching@v0.1.0
62-
with:
63-
key: ${{ github.workflow }}-2-{hash}
64-
restore-keys: |
65-
${{ github.workflow }}-2-
66-
- name: Build & Push Image to ECR
67-
uses: kciter/aws-ecr-action@v3
68-
with:
69-
access_key_id: ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
70-
secret_access_key: ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
71-
account_id: ${{ secrets.INCUBATOR_AWS_ACCOUNT_ID }}
72-
repo: ${{ needs.setup_env.outputs.AWS_APPENV }}
73-
region: ${{ env.AWS_REGION }}
74-
tags: latest,${{ needs.setup_env.outputs.IMAGE_TAG }}
75-
dockerfile: ${{ env.DOCKERFILE }}
76-
path: ${{ env.DOCKER_PATH }}
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
with:
51+
ref: ${{ github.event.inputs.ref }}
52+
- name: Configure AWS credentials
53+
uses: aws-actions/configure-aws-credentials@v4
54+
with:
55+
aws-access-key-id: ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
56+
aws-secret-access-key: ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
57+
aws-region: ${{ env.AWS_REGION }}
58+
- name: Login to Amazon ECR
59+
id: login-ecr
60+
uses: aws-actions/amazon-ecr-login@v2
61+
- name: Set up Docker Buildx
62+
uses: docker/setup-buildx-action@v3
63+
- name: Debug Build Variables
64+
env:
65+
BUILD_SHA: ${{ needs.setup_env.outputs.BUILD_SHA }}
66+
IMAGE_TAG: ${{ needs.setup_env.outputs.IMAGE_TAG }}
67+
run: |
68+
echo "=== Build Debug Information ==="
69+
echo "BUILD_SHA: $BUILD_SHA"
70+
echo "IMAGE_TAG: $IMAGE_TAG"
71+
echo "DOCKERFILE: ${{ env.DOCKERFILE }}"
72+
echo "DOCKER_PATH: ${{ env.DOCKER_PATH }}"
73+
echo "================================"
74+
- name: Build & Push Image to ECR
75+
env:
76+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
77+
ECR_REPOSITORY: ${{ needs.setup_env.outputs.AWS_APPENV }}
78+
IMAGE_TAG: ${{ needs.setup_env.outputs.IMAGE_TAG }}
79+
BUILD_SHA: ${{ needs.setup_env.outputs.BUILD_SHA }}
80+
run: |
81+
docker buildx build \
82+
--platform linux/amd64 \
83+
--cache-from type=gha \
84+
--cache-to type=gha,mode=max \
85+
--push \
86+
--build-arg BUILD_SHA=$BUILD_SHA \
87+
-f ${{ env.DOCKERFILE }} \
88+
-t $ECR_REGISTRY/$ECR_REPOSITORY:latest \
89+
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
90+
${{ env.DOCKER_PATH }}
7791
deploy:
7892
name: Deploy to AWS ECS
7993
runs-on: ubuntu-latest
8094
needs: [setup_env, build]
8195
steps:
82-
- name: Configure AWS credentials
83-
uses: aws-actions/configure-aws-credentials@v1
84-
with:
85-
aws-access-key-id: ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
86-
aws-secret-access-key: ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
87-
aws-region: ${{ env.AWS_REGION }}
88-
- name: Login to Amazon ECR
89-
id: login-ecr
90-
uses: aws-actions/amazon-ecr-login@v1
91-
- name: Pull Task Definition & write to file
92-
id: aws-task-definition
93-
run: |
94-
aws ecs describe-task-definition \
95-
--task-definition ${{ needs.setup_env.outputs.AWS_APPENV }} \
96-
--query taskDefinition | \
97-
jq 'del(.taskDefinitionArn,.revision,.status,.registeredBy,.registeredAt,.compatibilities,.requiresAttributes)' > task-def.json
98-
- name: Interpolate new Docker Image into Task Definition
99-
id: task-definition
100-
uses: aws-actions/amazon-ecs-render-task-definition@v1
101-
with:
102-
task-definition: task-def.json
103-
container-name: ${{ needs.setup_env.outputs.AWS_APPENV }}
104-
image: ${{ steps.login-ecr.outputs.registry }}/${{ needs.setup_env.outputs.AWS_APPENV }}:${{ needs.setup_env.outputs.IMAGE_TAG }}
105-
- name: Deploy Amazon ECS
106-
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
107-
with:
108-
task-definition: ${{ steps.task-definition.outputs.task-definition }}
109-
service: ${{ needs.setup_env.outputs.AWS_APPENV }}
110-
cluster: ${{ env.AWS_SHARED_CLUSTER }}
111-
wait-for-service-stability: true
112-
wait-for-minutes: 5 minutes
113-
96+
- name: Configure AWS credentials
97+
uses: aws-actions/configure-aws-credentials@v4
98+
with:
99+
aws-access-key-id: ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
100+
aws-secret-access-key: ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
101+
aws-region: ${{ env.AWS_REGION }}
102+
- name: Login to Amazon ECR
103+
id: login-ecr
104+
uses: aws-actions/amazon-ecr-login@v2
105+
- name: Pull Task Definition & write to file
106+
id: aws-task-definition
107+
run: |
108+
aws ecs describe-task-definition \
109+
--task-definition ${{ needs.setup_env.outputs.AWS_APPENV }} \
110+
--query taskDefinition | \
111+
jq 'del(.taskDefinitionArn,.revision,.status,.registeredBy,.registeredAt,.compatibilities,.requiresAttributes)' > task-def.json
112+
- name: Interpolate new Docker Image into Task Definition
113+
id: task-definition
114+
uses: aws-actions/amazon-ecs-render-task-definition@v1
115+
with:
116+
task-definition: task-def.json
117+
container-name: ${{ needs.setup_env.outputs.AWS_APPENV }}
118+
image: ${{ steps.login-ecr.outputs.registry }}/${{ needs.setup_env.outputs.AWS_APPENV }}:${{ needs.setup_env.outputs.IMAGE_TAG }}
119+
- name: Deploy Amazon ECS
120+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
121+
with:
122+
task-definition: ${{ steps.task-definition.outputs.task-definition }}
123+
service: ${{ needs.setup_env.outputs.AWS_APPENV }}
124+
cluster: ${{ env.AWS_SHARED_CLUSTER }}
125+
wait-for-service-stability: true
126+
wait-for-minutes: 5
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
---
2+
title: AWS Frontend Deploy Workflow
3+
---
4+
5+
# AWS Frontend Deploy Workflow
6+
7+
This document describes the purpose and structure of the GitHub Actions workflow defined in `.github/workflows/aws-frontend-deploy.yml`.
8+
9+
## Overview
10+
11+
This workflow automates the process of building, pushing, and deploying the frontend application to AWS. It is triggered manually via the GitHub Actions UI using `workflow_dispatch`:
12+
13+
```yaml
14+
on:
15+
workflow_dispatch: # Manual trigger from GitHub Actions UI
16+
inputs:
17+
env:
18+
type: choice
19+
description: "AWS Incubator Env"
20+
options: # Selectable environment options
21+
- dev
22+
- prod
23+
ref:
24+
description: "Branch, Tag, or SHA" # Code reference to deploy
25+
required: true
26+
```
27+
28+
Users can select the environment (`dev` or `prod`) and specify a branch, tag, or SHA to deploy.
29+
30+
## Environment Variables
31+
32+
The workflow sets several environment variables for use throughout the jobs:
33+
34+
```yaml
35+
env:
36+
AWS_SHARED_CLUSTER: incubator-prod # Target ECS cluster name
37+
AWS_APP_NAME: vrms-frontend # Application name for tagging and service
38+
AWS_REGION: us-west-2 # AWS region for deployment
39+
DOCKERFILE: Dockerfile.prod # Dockerfile used for build
40+
DOCKER_PATH: client # Path to frontend source and Dockerfile
41+
```
42+
43+
Each of these environment variables is set at the top level of the workflow and is available to all jobs and steps. Here is a description of each:
44+
45+
- `AWS_SHARED_CLUSTER`: The name of the AWS ECS cluster to which the frontend will be deployed. In this workflow, it is set to `incubator-prod`. _Might be sourced from your AWS infrastructure naming conventions or deployment environment._
46+
- `AWS_APP_NAME`: The application name used for tagging Docker images and identifying the service in AWS. Here, it is set to `vrms-frontend`. _Might be sourced from your project or repository name._
47+
- `AWS_REGION`: The AWS region where resources are deployed. Set to `us-west-2` (Oregon). _Might be sourced from your AWS account's preferred deployment region._
48+
- `DOCKERFILE`: The Dockerfile used for building the frontend image. Set to `Dockerfile.prod`, indicating a production-ready build. _Might be sourced from your repository's Docker configuration._
49+
- `DOCKER_PATH`: The path to the directory containing the Dockerfile and frontend source code. Set to `client`. _Might be sourced from your repository structure._
50+
51+
## Jobs
52+
53+
### 1. `setup_env`
54+
55+
This job checks out the code and sets up environment-specific variables for the deployment:
56+
57+
```yaml
58+
jobs:
59+
setup_env:
60+
name: Set-up environment
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Debug Action
64+
uses: hmarr/debug-action@v2 # Prints debug info to logs
65+
- name: Checkout
66+
uses: actions/checkout@v3 # Checks out code at specified ref
67+
with:
68+
ref: ${{ github.event.inputs.ref }} # Uses user-specified ref
69+
- name: Set AWS Env & Image Tag per workflow
70+
# Get short SHA of current commit
71+
# if -- action is triggered manually
72+
# Get environment input from workflow dispatch
73+
# Get ref input from workflow dispatch
74+
# Set AWS_APPENV for later steps
75+
# Set IMAGE_TAG for later steps
76+
# fi
77+
run: |
78+
SHORT_SHA=$(git rev-parse --short HEAD)
79+
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
80+
INPUT_ENV=${{ github.event.inputs.env }}
81+
INPUT_REF=${{ github.event.inputs.ref }}
82+
echo AWS_APPENV="$AWS_APP_NAME"-$INPUT_ENV >> $GITHUB_ENV
83+
echo IMAGE_TAG=$SHORT_SHA >> $GITHUB_ENV
84+
fi
85+
```
86+
87+
This job outputs the application environment and image tag for use in subsequent jobs.
88+
89+
### 2. `build`
90+
91+
This job builds the Docker image for the frontend and pushes it to Amazon ECR:
92+
93+
```yaml
94+
build:
95+
name: Build & Push Docker Image
96+
runs-on: ubuntu-latest
97+
permissions:
98+
id-token: write # Needed for OIDC authentication to AWS
99+
needs: [setup_env] # Waits for environment setup
100+
steps:
101+
- name: Checkout
102+
uses: actions/checkout@v3 # Checks out code at specified ref
103+
with:
104+
ref: ${{ github.event.inputs.ref }}
105+
- name: Setup Node.js
106+
uses: actions/setup-node@v3 # Sets up Node.js for build
107+
with:
108+
node-version: 18 # Uses Node.js v18
109+
cache: "npm" # Enables npm caching
110+
- name: Configure AWS credentials
111+
uses: aws-actions/configure-aws-credentials@v3 # Sets AWS credentials for CLI
112+
with:
113+
role-to-assume: arn:aws:iam::035866691871:role/incubator-cicd-vrms # IAM role for deploy
114+
role-session-name: incubator-cicd-vrms-gha # Session name for audit
115+
aws-region: us-west-2 # AWS region
116+
- name: Login to Amazon ECR
117+
id: login-ecr
118+
uses: aws-actions/amazon-ecr-login@v1 # Authenticates Docker to ECR
119+
- name: Build, tag, and push the image to Amazon ECR
120+
id: build-push-image
121+
env:
122+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} # ECR registry URL
123+
ECR_REPOSITORY: ${{ env.AWS_APP_NAME }} # ECR repo name
124+
run: |
125+
ls # List files for debug
126+
cd ./${{ env.DOCKER_PATH }} # Enter frontend directory
127+
docker build \
128+
-f ${{ env.DOCKERFILE }} \ # Use production Dockerfile
129+
-t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ needs.setup_env.outputs.IMAGE_TAG }} \ # Tag with image SHA
130+
-t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ github.event.inputs.env }} \ # Tag with environment
131+
.
132+
docker image push --all-tags ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }} # Push all tags
133+
```
134+
135+
### 3. `deploy`
136+
137+
This job deploys the new Docker image to AWS ECS by forcing a new deployment of the ECS service:
138+
139+
```yaml
140+
deploy:
141+
name: Deploy to AWS ECS
142+
runs-on: ubuntu-latest
143+
needs: [setup_env, build] # Waits for setup and build jobs
144+
permissions:
145+
id-token: write # Needed for OIDC authentication to AWS
146+
steps:
147+
- name: Configure AWS credentials
148+
uses: aws-actions/configure-aws-credentials@v3 # Sets AWS credentials for CLI
149+
with:
150+
role-to-assume: arn:aws:iam::035866691871:role/incubator-cicd-vrms # IAM role for deploy
151+
role-session-name: incubator-cicd-vrms-gha # Session name for audit
152+
aws-region: us-west-2 # AWS region
153+
- name: Restart ECS Service
154+
id: redeploy-service
155+
env:
156+
SERVICE_NAME: ${{env.AWS_APP_NAME}}-${{ github.event.inputs.env }} # ECS service name
157+
run: |
158+
aws ecs update-service --force-new-deployment --service $SERVICE_NAME --cluster $AWS_SHARED_CLUSTER # Triggers ECS redeploy
159+
```
160+
161+
## Repository Checkout and Working Directory
162+
163+
When this workflow runs, it uses the `actions/checkout@v3` action to clone the entire repository. The initial working directory for all steps is the root of the repository.
164+
165+
Before building the Docker image, the workflow explicitly changes into the `client` directory using:
166+
167+
```bash
168+
cd ./${{ env.DOCKER_PATH }}
169+
```
170+
171+
This means that for the Docker build step, the working directory is `client/`, and the Dockerfile path `Dockerfile.prod` refers to `client/Dockerfile.prod`.
172+
173+
**Summary:**
174+
175+
- The workflow clones the entire repository.
176+
- The working directory starts at the repo root.
177+
- The workflow changes into the `client` directory before building the Docker image.
178+
- The Docker build context and Dockerfile are both relative to the `client` directory.
179+
180+
## Summary
181+
182+
This workflow provides a manual, environment-aware deployment pipeline for the frontend application, leveraging Docker, Amazon ECR, and ECS. It ensures that only the specified code reference is built and deployed, and that deployments are traceable and auditable via GitHub Actions.

0 commit comments

Comments
 (0)