-
Notifications
You must be signed in to change notification settings - Fork 5
Create GitHub Actions for auto deployment to AWS #66
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7793c74
Create github workflow to deploy frontend and backend to AWS
McNaBry 63bb304
Add conditional trigger for backend workflow
McNaBry 57e3e74
Update frontend workflow
McNaBry c0b9e6d
Add cloudfront cache invalidation to frontend workflow
McNaBry d4358d4
Merge branch 'main' into ci-cd-aws-deploy
samuelim01 862b5bd
Include collab in backend workflow
samuelim01 ef9d448
Add workflow scripts that can only be triggered manually for frontend…
McNaBry f44412f
Merge branch 'main' into ci-cd-aws-deploy
McNaBry 25e98cf
Rename frontend force workflow
McNaBry 88af582
Change frontend and backend workflows to trigger only on production b…
McNaBry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Deploy Backend Services | ||
|
||
on: | ||
push: | ||
branches: [ 'production' ] | ||
|
||
workflow_dispatch: | ||
|
||
permissions: | ||
id-token: write # This is required for requesting the JWT | ||
contents: read # This is required for actions/checkout | ||
|
||
env: | ||
AWS_REGION: ap-southeast-1 | ||
ECS_CLUSTER: backend-cluster | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy Backend Service | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
strategy: | ||
matrix: | ||
service: [ 'question', 'user', 'match', 'collaboration' ] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
id: aws-configure | ||
uses: aws-actions/[email protected] | ||
with: | ||
role-to-assume: ${{ secrets.AWS_BACKEND_ROLE }} | ||
role-session-name: GitHub_to_AWS_via_FederatedOIDC | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to AWS ECR | ||
id: login-ecr | ||
uses: aws-actions/[email protected] | ||
|
||
- name: Build and push ${{ matrix.service }} image to AWS ECR | ||
id: build-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: ${{ matrix.service }} | ||
IMAGE_TAG: latest | ||
run: | | ||
echo "Building $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./services/${{ matrix.service }} | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
|
||
- name: Update AWS Service (${{ matrix.service }}) # Trigger re-deployment with latest image | ||
id: update-service | ||
env: | ||
ECS_SERVICE: ${{ matrix.service }}-service | ||
run: | | ||
echo "Updating $ECS_SERVICE for $ECS_CLUSTER" | ||
aws ecs update-service \ | ||
--cluster $ECS_CLUSTER \ | ||
--service $ECS_SERVICE \ | ||
--force-new-deployment \ | ||
--region $AWS_REGION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Deploy Frontend | ||
|
||
on: | ||
push: | ||
branches: [ 'production' ] | ||
|
||
workflow_dispatch: | ||
|
||
permissions: | ||
id-token: write # This is required for requesting the JWT | ||
contents: read # This is required for actions/checkout | ||
|
||
env: | ||
AWS_REGION: ap-southeast-1 | ||
S3_BUCKET_NAME: app.peerprep.org | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy Frontend | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
id: aws-configure | ||
uses: aws-actions/[email protected] | ||
with: | ||
role-to-assume: ${{ secrets.AWS_FRONTEND_ROLE }} | ||
role-session-name: GitHub_to_AWS_via_FederatedOIDC | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Build frontend distribution | ||
working-directory: frontend | ||
run: npm ci && npm run build | ||
|
||
- name: Sync distribution to S3 | ||
run: | | ||
aws s3 sync ./frontend/dist/frontend/browser/ s3://$S3_BUCKET_NAME --delete | ||
|
||
- name: Invalidate Cloudfront Cache | ||
run: | | ||
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/*" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.