Merge pull request #35 from Romantic-Yeojido/feature/#33-add-deploy-p… #2
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
name: deploy-main | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "$EC2_SSH_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
cat >>~/.ssh/config <<END | |
Host romactic-yeojido | |
HostName $EC2_HOST | |
User $EC2_USER | |
IdentityFile ~/.ssh/id_rsa | |
StrictHostKeyChecking no | |
END | |
env: | |
EC2_USER: ubuntu | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }} | |
- name: Copy Workspace | |
run: | | |
ssh romactic-yeojido 'sudo mkdir -p /opt/app' | |
ssh romactic-yeojido 'sudo chown ubuntu:ubuntu /opt/app/' | |
scp -r ./[!.]* romactic-yeojido:/opt/app | |
- name: Install dependencies | |
run: | | |
ssh romactic-yeojido 'npm install --prefix /opt/app/' | |
- name: Copy systemd service file | |
run: | | |
ssh romactic-yeojido ' | |
echo "[Unit] | |
Description=UMC 7th Project | |
After=network.target | |
[Service] | |
User=${USER} | |
ExecStart=/usr/bin/npm run dev --prefix /opt/app/ | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/app.service | |
' | |
- name: Enable systemd service | |
run: | | |
ssh romactic-yeojido 'sudo systemctl daemon-reload' | |
ssh romactic-yeojido 'sudo systemctl enable app' | |
- name: Restart systemd service | |
run: | | |
ssh romactic-yeojido 'sudo systemctl restart app' |