-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
100 additions
and
47 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,47 @@ | ||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
name: CI/CD (Blue-Green Deployment) | ||
|
||
jobs: | ||
ci-cd: | ||
name: CI/CD | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: Compress files | ||
env: | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: zip -r deploy-$IMAGE_TAG.zip ./appspec.yml ./scripts ./index.js ./package.json | ||
|
||
- name: Upload S3 bucket | ||
env: | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
aws s3 cp --region ${{ secrets.AWS_REGION }} --acl private deploy-$IMAGE_TAG.zip | | ||
s3://${{ secrets.AWS_S3_BUCKET_NAME }}/deploy-$IMAGE_TAG.zip | ||
- name: Trigger CodeDeploy | ||
env: | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
aws deploy create-deployment --application-name ${{ secrets.AWS_CODEDEPLOY_APPLICATION_NAME }} | | ||
--deployment-config-name CodeDeployDefault.AllAtOnce | | ||
--deployment-group-name ${{ secrets.AWS_CODEDEPLOY_DEPLOYMENT_GROUP_NAME }} | | ||
--s3-location bucket=${{ secrets.AWS_S3_BUCKET_NAME }},bundleType=zip,key=deploy-$IMAGE_TAG.zip | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
|
||
package-lock.json | ||
package-lock.json | ||
|
||
.DS_Store |
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,20 @@ | ||
version: 0.0 | ||
os: linux | ||
|
||
files: | ||
- source: / | ||
destination: /app | ||
overwrite: yes | ||
|
||
hooks: | ||
BeforeInstall: | ||
- location: scripts/before_install.sh | ||
timeout: 300 | ||
|
||
AfterInstall: | ||
- location: scripts/after_install.sh | ||
timeout: 300 | ||
|
||
ApplicationStart: | ||
- location: scripts/application_start.sh | ||
timeout: 300 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
# move to the server directory and install the node modules | ||
cd /app | ||
sudo npm install |
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,9 @@ | ||
#!/bin/bash | ||
|
||
# Mapport 80 to 3000 | ||
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080 | ||
|
||
# Stop all servers and start the server | ||
forever start /app/index.js | ||
|
||
|
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,15 @@ | ||
#!/bin/bash | ||
|
||
# install node 20.x | ||
sudo apt-get update | ||
sudo apt-get install build-essential | ||
sudo apt-get install curl -y | ||
curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -- | ||
sudo apt-get install nodejs -y | ||
|
||
# Install npm | ||
sudo apt install npm -y | ||
sudo npm install npm@latest -g | ||
|
||
# Install forever | ||
sudo npm install forever -g |