sudo apt-get update
sudo apt-get install -y nodejs npm nginx
sudo npm install -g pm2
git clone repo
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 16
cd your-sveltekit-app
yarn
yarn build
pm2 start npm --name "app-name" -- start
sudo nano /etc/nginx/conf.d/your-domain-name.conf
Paste the following content into the file, replacing your-domain-name.com with your actual domain name or your EC2 instance's public IP address:
server {
listen 80;
server_name your-domain-name.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo service nginx restart
sudo apt update
sudo apt install certbot
Run Certbot with the certonly command to obtain the SSL certificate. For example, to obtain a certificate for the domain xyz.com, you would run:
sudo certbot certonly --webroot -w /var/www/html -d xyz.com
server {
listen 443 ssl;
server_name xyz.com;
ssl_certificate /etc/letsencrypt/live/adsv2.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/adsv2.com/privkey.pem;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo service nginx restart
name: Deployment
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use node js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install and build
run: npm install
env:
CI: true
deploy:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: SSH deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST}}
username: ${{ secrets.USER}}
key: ${{ secrets.KEY}}
port: ${{ secrets.PORT}}
script: |
set -e
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install 16
cd $HOME/node-deploy-cicd-aws
git fetch --all
git reset --hard origin/develop
pm2 restart 0
-
SSH Private Key : ssh-keygen on instance and set that private key in repo secrets. And public key to ~/.ssh/authorized_keys file
-
HOST : public IP of instance
-
USER : ubuntu
-
PORT : 22 ( for ssh )