This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
generated from IgrowkerTraining/template-express-ts
-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 changed file
with
35 additions
and
15 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 |
---|---|---|
|
@@ -62,7 +62,7 @@ jobs: | |
deploy-to-render: | ||
runs-on: ubuntu-latest | ||
needs: build-and-push-docker | ||
needs: build-and-test | ||
if: ${{ github.ref_name == 'develop' || github.event.inputs.environment == 'development' }} | ||
|
||
steps: | ||
|
@@ -75,31 +75,51 @@ jobs: | |
deploy-to-aws: | ||
runs-on: ubuntu-latest | ||
needs: build-and-test | ||
if: ${{ github.ref_name == 'main' || github.event.inputs.environment == 'production' }} | ||
|
||
steps: | ||
- name: Checkout Backend Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up SSH key | ||
- name: Set up SSH key for Public Instance | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ secrets.AWS_SSH_KEY }}" > ~/.ssh/backend_key.pem | ||
chmod 400 ~/.ssh/backend_key.pem | ||
echo "${{ secrets.AWS_SSH_KEY }}" > ~/.ssh/pawsome-front.pem | ||
chmod 400 ~/.ssh/pawsome-front.pem | ||
- name: Deploy Backend to AWS EC2 | ||
env: | ||
URI: ${{ secrets.URI }} | ||
PORT: ${{ secrets.PORT }} | ||
MAIL_HOST: ${{ secrets.MAIL_HOST }} | ||
MAIL_PORT: ${{ secrets.MAIL_PORT }} | ||
MAIL_USER: ${{ secrets.MAIL_USER }} | ||
MAIL_PASS: ${{ secrets.MAIL_PASS }} | ||
JWT_SECRET: ${{ secrets.JWT_SECRET }} | ||
run: | | ||
ssh -o StrictHostKeyChecking=no -i ~/.ssh/backend_key.pem [email protected] " | ||
cd /home/ec2-user || mkdir /home/ec2-user; | ||
ssh -o StrictHostKeyChecking=no -i ~/.ssh/pawsome-front.pem ec2-user@${{ secrets.EC2_PUBLIC_IP }} << EOF | ||
ssh -o StrictHostKeyChecking=no -i /home/ec2-user/private_instance_key.pem ec2-user@${{ secrets.EC2_PRIVATE_IP }} << 'INNER_SSH' | ||
cd /home/ec2-user || mkdir /home/ec2-user; | ||
if [ ! -d /home/ec2-user/i004-pawsome-back ]; then | ||
git clone https://github.com/igrowker/i004-pawsome-back /home/ec2-user/i004-pawsome-back; | ||
fi; | ||
cd /home/ec2-user/i004-pawsome-back; | ||
if [ ! -d /home/ec2-user/i004-pawsome-back ]; then | ||
git clone https://github.com/igrowker/i004-pawsome-back /home/ec2-user/i004-pawsome-back; | ||
fi; | ||
git pull; | ||
npm install; | ||
cd /home/ec2-user/i004-pawsome-back; | ||
export URI=${URI} | ||
export PORT=${PORT} | ||
export MAIL_HOST=${MAIL_HOST} | ||
export MAIL_PORT=${MAIL_PORT} | ||
export MAIL_USER=${MAIL_USER} | ||
export MAIL_PASS=${MAIL_PASS} | ||
export JWT_SECRET=${JWT_SECRET} | ||
git pull; | ||
npm install; | ||
npm run build; | ||
npm run build; | ||
pm2 reload ecosystem.config.js || pm2 start ecosystem.config.js --env production; | ||
" | ||
pm2 reload ecosystem.config.js || pm2 start ecosystem.config.js --env production; | ||
INNER_SSH | ||
EOF |