Skip to content

try to update known hosts #3

try to update known hosts

try to update known hosts #3

name: (Prod) Build and deploy
on:
push:
tags:
# Only build and deploy when a new tag is created matching a semantic version.
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
npm install
- name: Create .env file
run: |
echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} >> .env
echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} >> .env
echo AWS_DEFAULT_REGION=${{ secrets.AWS_REGION }} >> .env
echo NUXT_PUBLIC_GDOC_ENV=prod >> .env
- name: Build Nuxt.js application
run: |
npm run build
- name: Create a temporary directory for deployment artifacts
run: |
mkdir -p dist
- name: Copy generated files to dist directory
run: |
cp -r .output/* dist/
- name: Login to AWS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Add EC2 host key to known_hosts
run: |
ssh-keyscan -H ${{ secrets.EC2_HOSTNAME }} >> ~/.ssh/known_hosts
- name: Connect to EC2 instance
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOSTNAME }}
username: ec2-user
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
sudo systemctl stop gstream.service
sudo rm -rf /var/www/gstream/*
scp -r -P 22 dist/ ec2-user@${{ secrets.EC2_HOSTNAME }}:/var/www/gstream/
- name: Restart service
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOSTNAME }}
username: ec2-user
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
sudo systemctl daemon-reload
sudo systemctl start gstream.service
sudo systemctl enable gstream.service