-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from zayman2045/auto-deploy
Enhance CI/CD Pipeline, Backend Error Handling, and Configuration Updates
- Loading branch information
Showing
9 changed files
with
202 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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,143 @@ | ||
name: CI/CD Pipeline | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
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-1 | ||
|
||
- 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" \ | ||
--region us-east-2 | ||
- 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 \ | ||
--region us-east-2 | ||
- 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" \ | ||
--region us-east-2 | ||
- 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 \ | ||
--region us-east-2 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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
Binary file not shown.