Merge pull request #22 from UMC-8th-Hackathon-Team-Name/temp #7
This file contains hidden or 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: Check prisma has changes | |
| uses: dorny/paths-filter@v3 | |
| id: paths-filter | |
| with: | |
| filters: | | |
| prisma: ["prisma/**"] | |
| - name: Configure SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "$EC2_SSH_KEY" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| cat >>~/.ssh/config <<END | |
| Host dentistry | |
| 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 dentistry 'sudo mkdir -p /opt/app' | |
| ssh dentistry 'sudo chown ubuntu:ubuntu /opt/app' | |
| scp -r ./[!.]* dentistry:/opt/app | |
| - name: Install dependencies | |
| run: | | |
| ssh dentistry 'cd /opt/app; npm install' | |
| ssh dentistry 'cd /opt/app; npm exec prisma generate' | |
| - name: Apply prisma migrations | |
| if: steps.paths-filter.outputs.prisma == 'true' | |
| run: | | |
| ssh dentistry 'cd /opt/app; npm exec prisma migrate deploy' | |
| - name: Copy systemd service file | |
| run: | | |
| ssh dentistry ' | |
| echo "[Unit] | |
| Description=UMC 7th Project | |
| After=network.target | |
| [Service] | |
| User=${USER} | |
| ExecStart=/usr/bin/npm run start --prefix /opt/app/ | |
| Restart=always | |
| [Install] | |
| WantedBy=multi-user.target" | sudo tee /etc/systemd/system/app.service | |
| ' | |
| - name: Enable systemd service | |
| run: | | |
| ssh dentistry 'sudo systemctl daemon-reload' | |
| ssh dentistry 'sudo systemctl enable app' | |
| - name: Restart systemd service | |
| run: | | |
| ssh dentistry 'sudo systemctl restart app' |