Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions .github/workflows/deploy-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: deploy-main

on:
push:
branches:
- main
workflow_dispatch:

defaults:
run:
working-directory: 도얏/week10

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "24"
cache: "npm"
cache-dependency-path: 도얏/week10/package-lock.json

- name: Install dependencies
run: npm ci

- name: Inject environment variables
run: |
cat > .env <<'EOF'
${{ secrets.EC2_DOT_ENV }}
EOF

- name: Generate and build
run: npm run build

- name: Keep production dependencies only
run: npm prune --omit=dev

- name: Package artifact
run: tar -czf app.tar.gz dist package.json package-lock.json node_modules prisma prismaConfig.ts tsoa.json

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: week10-app
path: 도얏/week10/app.tar.gz

deploy:
runs-on: ubuntu-latest
needs: build

steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: week10-app
path: 도얏/week10

- name: Configure SSH
run: |
mkdir -p ~/.ssh
echo "$EC2_SSH_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
cat > ~/.ssh/config <<EOF
Host deploy-server
HostName $EC2_HOST
Port $EC2_PORT
User $EC2_USER
StrictHostKeyChecking no
EOF
env:
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_PORT: ${{ secrets.EC2_PORT }}
EC2_USER: ${{ secrets.EC2_USER }}

- name: Copy artifact to EC2
run: scp app.tar.gz deploy-server:/tmp/week10-app.tar.gz

- name: Deploy on EC2
run: |
ssh deploy-server <<'EOF'
set -e

APP_DIR="$HOME/UMC_10th"
RELEASE_DIR="$HOME/UMC_10th_release"

rm -rf "$RELEASE_DIR"
mkdir -p "$RELEASE_DIR"
tar -xzf /tmp/week10-app.tar.gz -C "$RELEASE_DIR"

rm -rf "$APP_DIR"
mv "$RELEASE_DIR" "$APP_DIR"

cat > "$APP_DIR/.env" <<'ENVEOF'
${{ secrets.EC2_DOT_ENV }}
ENVEOF

sudo tee /etc/systemd/system/UMC_10th.service > /dev/null <<SERVICEEOF
[Unit]
Description=UMC 10th Node API
After=network.target

[Service]
Type=simple
User=$USER
WorkingDirectory=$APP_DIR
ExecStart=$(command -v node) $APP_DIR/dist/src/index.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target
SERVICEEOF

sudo systemctl daemon-reload
sudo systemctl enable UMC_10th
sudo systemctl restart UMC_10th
sudo systemctl status UMC_10th --no-pager
EOF
48 changes: 0 additions & 48 deletions README.md

This file was deleted.

22 changes: 22 additions & 0 deletions 도얏/week10/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# dependency directories
node_modules/

# build output
dist/

# dotenv environment variable files
.env
.env.local
.env.development
.env.production
.env.*
.claude*

# macOS
.DS_Store

# logs
*.log
npm-debug.log*

/src/generated/prisma
1 change: 1 addition & 0 deletions 도얏/week10/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# umc-node-study
Loading