Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit ba1da03

Browse files
committed
Try CI
1 parent 5604a4f commit ba1da03

File tree

4 files changed

+173
-21
lines changed

4 files changed

+173
-21
lines changed

.github/workflows/ci.yml

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,58 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14-
14+
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v4
1717
with:
1818
node-version: '20'
19-
19+
2020
- name: Install pnpm
2121
uses: pnpm/action-setup@v3
2222
with:
2323
version: 8
24-
24+
2525
- name: Get pnpm store directory
2626
id: pnpm-cache
2727
shell: bash
2828
run: |
2929
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
30-
30+
3131
- uses: actions/cache@v4
3232
with:
3333
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
3434
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
3535
restore-keys: |
3636
${{ runner.os }}-pnpm-store-
37-
37+
3838
- name: Install dependencies
3939
run: pnpm install
40-
40+
4141
- name: Install Playwright system dependencies
4242
run: |
4343
sudo apt-get update
4444
sudo apt-get install -y libgtk-4-1 libgraphene-1.0-0 libwoff1 libevent-2.1-7 libopus0 \
4545
libharfbuzz-icu0 libsecret-1-0 libhyphen0 libmanette-0.2-0 \
4646
libgles2 libx264-dev libavif-dev
47-
47+
4848
- name: Install Playwright
4949
run: pnpm exec playwright install --with-deps
50-
50+
5151
- name: Build shared package
5252
run: pnpm --filter shared build
53-
53+
5454
- name: Type check
5555
run: |
5656
# Skip type checking for now and just build
5757
pnpm --filter shared build
5858
pnpm --filter server build --skipLibCheck
59-
59+
6060
- name: Lint
6161
run: pnpm --filter client lint
62-
62+
6363
- name: End-to-end tests
6464
run: pnpm e2e
65-
65+
6666
- name: Build
6767
run: pnpm build
6868

@@ -75,37 +75,37 @@ jobs:
7575
packages: write
7676
steps:
7777
- uses: actions/checkout@v4
78-
78+
7979
- name: Set up Docker Buildx
8080
uses: docker/setup-buildx-action@v3
81-
81+
8282
- name: Log in to GitHub Container Registry
8383
uses: docker/login-action@v3
8484
with:
8585
registry: ghcr.io
8686
username: ${{ github.actor }}
8787
password: ${{ secrets.GITHUB_TOKEN }}
88-
88+
8989
- name: Set lowercase names
9090
id: lowercase
9191
run: |
9292
echo "owner=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
9393
echo "repo=$(echo ${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
94-
94+
9595
- name: Extract metadata for Docker
9696
id: meta
9797
uses: docker/metadata-action@v5
9898
with:
9999
images: ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ steps.lowercase.outputs.repo }}
100-
100+
101101
- name: Build and push client image
102102
uses: docker/build-push-action@v5
103103
with:
104104
context: .
105105
push: true
106106
tags: ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ steps.lowercase.outputs.repo }}/client:latest
107107
target: client
108-
108+
109109
- name: Build and push server image
110110
uses: docker/build-push-action@v5
111111
with:
@@ -114,6 +114,15 @@ jobs:
114114
tags: ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ steps.lowercase.outputs.repo }}/server:latest
115115
target: server
116116

117+
- name: Copy Nginx config to VPS
118+
uses: appleboy/scp-action@master
119+
with:
120+
host: ${{ secrets.VPS_HOST }}
121+
username: ${{ secrets.VPS_USERNAME }}
122+
key: ${{ secrets.VPS_SSH_KEY }}
123+
source: "nginx/hackops.dracodev.me.conf"
124+
target: "/tmp"
125+
117126
- name: Deploy to VPS
118127
uses: appleboy/ssh-action@master
119128
with:
@@ -124,7 +133,7 @@ jobs:
124133
# Create app directory if it doesn't exist
125134
mkdir -p ~/hackops-submission
126135
cd ~/hackops-submission
127-
136+
128137
# Create docker-compose file
129138
echo 'version: "3.8"' > docker-compose.yml
130139
echo '' >> docker-compose.yml
@@ -137,6 +146,7 @@ jobs:
137146
echo ' - NODE_ENV=production' >> docker-compose.yml
138147
echo ' depends_on:' >> docker-compose.yml
139148
echo ' - server' >> docker-compose.yml
149+
echo ' restart: unless-stopped' >> docker-compose.yml
140150
echo '' >> docker-compose.yml
141151
echo ' server:' >> docker-compose.yml
142152
echo ' image: ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ steps.lowercase.outputs.repo }}/server:latest' >> docker-compose.yml
@@ -145,9 +155,45 @@ jobs:
145155
echo ' environment:' >> docker-compose.yml
146156
echo ' - NODE_ENV=production' >> docker-compose.yml
147157
echo ' command: node /app/server/index.js' >> docker-compose.yml
148-
158+
echo ' restart: unless-stopped' >> docker-compose.yml
159+
149160
# Pull latest images and restart containers
150161
docker pull ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ steps.lowercase.outputs.repo }}/client:latest
151162
docker pull ghcr.io/${{ steps.lowercase.outputs.owner }}/${{ steps.lowercase.outputs.repo }}/server:latest
152163
docker-compose down
153164
docker-compose up -d
165+
166+
# Set up Nginx
167+
# Install Nginx if not already installed
168+
if ! command -v nginx &> /dev/null; then
169+
apt-get update
170+
apt-get install -y nginx
171+
fi
172+
173+
# Copy Nginx configuration
174+
cp /tmp/nginx/hackops.dracodev.me.conf /etc/nginx/sites-available/hackops.dracodev.me
175+
176+
# Create symbolic link if it doesn't exist
177+
if [ ! -f /etc/nginx/sites-enabled/hackops.dracodev.me ]; then
178+
ln -s /etc/nginx/sites-available/hackops.dracodev.me /etc/nginx/sites-enabled/
179+
fi
180+
181+
# Remove default site if it exists
182+
if [ -f /etc/nginx/sites-enabled/default ]; then
183+
rm /etc/nginx/sites-enabled/default
184+
fi
185+
186+
# Test Nginx configuration
187+
nginx -t
188+
189+
# Reload Nginx
190+
systemctl reload nginx
191+
192+
# Install Certbot for SSL if not already installed
193+
if ! command -v certbot &> /dev/null; then
194+
apt-get update
195+
apt-get install -y certbot python3-certbot-nginx
196+
fi
197+
198+
# Set up SSL certificate
199+
certbot --nginx -d hackops.dracodev.me --non-interactive --agree-tos --email [email protected]

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,36 @@ jobs:
213213

214214
1. Merge code into `main`
215215
2. GitHub Actions pipeline runs tests, builds images, pushes to registry
216-
3. SSH into VPS: pulls images, updates `docker-compose.yml`, restarts services
216+
3. GitHub Actions deploys to VPS:
217+
- Pulls latest images
218+
- Updates `docker-compose.yml`
219+
- Restarts services
220+
- Configures Nginx as a reverse proxy
221+
- Sets up SSL with Let's Encrypt
222+
223+
### Setting Up GitHub Secrets for Deployment
224+
225+
To enable automatic deployment to your VPS, you need to set up the following GitHub secrets:
226+
227+
1. `VPS_HOST`: Your VPS IP address
228+
2. `VPS_USERNAME`: The username to connect to your VPS (usually `root`)
229+
3. `VPS_SSH_KEY`: Your SSH private key for connecting to the VPS
230+
231+
You can use the provided script to set up these secrets:
232+
233+
```bash
234+
# Make sure you have the GitHub CLI installed
235+
# https://cli.github.com/
236+
237+
# Run the setup script
238+
./scripts/setup-github-secrets.sh
239+
```
240+
241+
### Domain Configuration
242+
243+
The deployment is configured to work with the domain `hackops.dracodev.me`. Make sure your domain's DNS records point to your VPS IP address:
244+
245+
- Create an A record for `hackops.dracodev.me` pointing to your VPS IP address
217246

218247

219248
## Configuration Files

nginx/hackops.dracodev.me.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
server {
2+
listen 80;
3+
server_name hackops.dracodev.me;
4+
5+
location / {
6+
proxy_pass http://localhost:3000;
7+
proxy_http_version 1.1;
8+
proxy_set_header Upgrade $http_upgrade;
9+
proxy_set_header Connection 'upgrade';
10+
proxy_set_header Host $host;
11+
proxy_cache_bypass $http_upgrade;
12+
}
13+
14+
location /api {
15+
proxy_pass http://localhost:3001;
16+
proxy_http_version 1.1;
17+
proxy_set_header Upgrade $http_upgrade;
18+
proxy_set_header Connection 'upgrade';
19+
proxy_set_header Host $host;
20+
proxy_cache_bypass $http_upgrade;
21+
}
22+
23+
location /socket.io {
24+
proxy_pass http://localhost:3001;
25+
proxy_http_version 1.1;
26+
proxy_set_header Upgrade $http_upgrade;
27+
proxy_set_header Connection 'upgrade';
28+
proxy_set_header Host $host;
29+
proxy_cache_bypass $http_upgrade;
30+
}
31+
}

scripts/setup-github-secrets.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# This script helps you set up GitHub secrets for your CI/CD workflow
4+
# You'll need the GitHub CLI (gh) installed: https://cli.github.com/
5+
6+
# Check if GitHub CLI is installed
7+
if ! command -v gh &> /dev/null; then
8+
echo "GitHub CLI is not installed. Please install it first: https://cli.github.com/"
9+
exit 1
10+
fi
11+
12+
# Check if logged in to GitHub
13+
if ! gh auth status &> /dev/null; then
14+
echo "You're not logged in to GitHub. Please run 'gh auth login' first."
15+
exit 1
16+
fi
17+
18+
# Get the repository name
19+
REPO=$(git config --get remote.origin.url | sed 's/.*github.com[:\/]\(.*\)\.git/\1/')
20+
21+
if [ -z "$REPO" ]; then
22+
echo "Could not determine repository name. Please make sure you're in a git repository with a GitHub remote."
23+
exit 1
24+
fi
25+
26+
echo "Setting up secrets for repository: $REPO"
27+
28+
# Set VPS_HOST secret
29+
echo "Setting VPS_HOST secret..."
30+
gh secret set VPS_HOST --body "142.93.160.146" --repo "$REPO"
31+
32+
# Set VPS_USERNAME secret
33+
echo "Setting VPS_USERNAME secret..."
34+
gh secret set VPS_USERNAME --body "root" --repo "$REPO"
35+
36+
# Set VPS_SSH_KEY secret
37+
echo "Setting VPS_SSH_KEY secret..."
38+
# Read the SSH key from the file
39+
if [ -f "vps.key" ]; then
40+
gh secret set VPS_SSH_KEY --body "$(cat vps.key)" --repo "$REPO"
41+
else
42+
echo "SSH key file 'vps.key' not found. Please create this file with your SSH private key."
43+
exit 1
44+
fi
45+
46+
echo "GitHub secrets have been set up successfully!"

0 commit comments

Comments
 (0)