Skip to content

Update AWS region in CI/CD workflow from us-east-1 to us-east-2 #5

Update AWS region in CI/CD workflow from us-east-1 to us-east-2

Update AWS region in CI/CD workflow from us-east-1 to us-east-2 #5

Workflow file for this run

name: CI/CD Pipeline
on:
pull_request:
branches:
- main
push:
branches:
- main
- auto-deploy
permissions:
id-token: write
contents: read
jobs:
test-frontend:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: wasm32-unknown-unknown
- name: Install wasm-pack
uses: jetli/wasm-pack-action@v0.4.0
- name: Setup Chrome and ChromeDriver
uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable
install-chromedriver: true
install-dependencies: true
- name: Build and test frontend
working-directory: ./frontend
run: wasm-pack test --chrome --headless
test-backend:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build and test backend
working-directory: ./backend
run: cargo test
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
deploy-to-aws:
runs-on: ubuntu-20.04
needs: [test-frontend, test-backend]
env:
FRONTEND_IMAGE: public.ecr.aws/m8r7m6j8/portfolio-frontend-1:latest
BACKEND_IMAGE: public.ecr.aws/m8r7m6j8/portfolio-backend-1:latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::637423446384:role/github-actions-role
aws-region: us-east-2
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Build, tag, and push frontend Docker image
run: |
docker buildx build --platform linux/amd64 -t $FRONTEND_IMAGE --push frontend
- name: Build, tag, and push backend Docker image
run: |
docker buildx build --platform linux/amd64 -t $BACKEND_IMAGE --push backend
- name: Upload Frontend Dockerrun.aws.json.zip to S3
run: |
aws s3 cp frontend/Dockerrun.aws.json.zip s3://elasticbeanstalk-us-east-2-637423446384/PortfolioWebsite-Frontend-env/Dockerrun.aws.json.zip
- name: Generate version labels
run: |
echo "FRONTEND_VERSION_LABEL=frontend-$(date +%s)" >> $GITHUB_ENV &&
echo "BACKEND_VERSION_LABEL=backend-$(date +%s)" >> $GITHUB_ENV
- name: Create application version for frontend
env:
FRONTEND_VERSION_LABEL: ${{ env.FRONTEND_VERSION_LABEL }}
run: |
aws elasticbeanstalk create-application-version \
--application-name "Portfolio Website" \
--version-label $FRONTEND_VERSION_LABEL \
--source-bundle S3Bucket="elasticbeanstalk-us-east-2-637423446384",S3Key="PortfolioWebsite-Frontend-env/Dockerrun.aws.json.zip"
- name: Update environment for frontend
env:
FRONTEND_VERSION_LABEL: ${{ env.FRONTEND_VERSION_LABEL }}
run: |
aws elasticbeanstalk update-environment \
--application-name "Portfolio Website" \
--environment-name "PortfolioWebsite-Frontend-env" \
--version-label $FRONTEND_VERSION_LABEL
- name: Upload Backend Dockerrun.aws.json.zip to S3
run: |
aws s3 cp backend/Dockerrun.aws.json.zip s3://elasticbeanstalk-us-east-2-637423446384/PortfolioWebsite-Backend-env/Dockerrun.aws.json.zip
- name: Create application version for backend
env:
BACKEND_VERSION_LABEL: ${{ env.BACKEND_VERSION_LABEL }}
run: |
aws elasticbeanstalk create-application-version \
--application-name "Portfolio Website" \
--version-label $BACKEND_VERSION_LABEL \
--source-bundle S3Bucket="elasticbeanstalk-us-east-2-637423446384",S3Key="PortfolioWebsite-Backend-env/Dockerrun.aws.json.zip"
- name: Update environment for backend
env:
BACKEND_VERSION_LABEL: ${{ env.BACKEND_VERSION_LABEL }}
run: |
aws elasticbeanstalk update-environment \
--application-name "Portfolio Website" \
--environment-name "PortfolioWebsite-Backend-env" \
--version-label $BACKEND_VERSION_LABEL