-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7402bab
commit 0e7d2ca
Showing
3 changed files
with
62 additions
and
28 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,28 +3,26 @@ env: | |
SERVER_USER: 'swissh' | ||
SERVER_IP: 'swis.sh' | ||
DEPLOY_PATH: '/home/swissh/swis.sh/' | ||
BACKUP_PATH: '/home/swissh/backup.swis.sh/' | ||
DOCKER_IMAGE: 'swissh-app' | ||
|
||
on: | ||
push: | ||
branches: | ||
- master # Adjust if your main branch is named differently | ||
- master | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Bun | ||
uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
|
||
- name: Install dependencies | ||
run: bun install | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Build project | ||
run: bun run build | ||
- name: Build Docker image | ||
run: | | ||
docker build -t ${{ env.DOCKER_IMAGE }} . | ||
- name: Set up SSH agent | ||
uses: webfactory/[email protected] | ||
|
@@ -35,22 +33,23 @@ jobs: | |
run: | | ||
echo "$(ssh-keyscan -t rsa ${{ env.SERVER_IP }} 2>/dev/null)" >> ~/.ssh/known_hosts | ||
- name: Deploy using rsync | ||
- name: Save Docker image | ||
run: docker save ${{ env.DOCKER_IMAGE }} | gzip > image.tar.gz | ||
|
||
- name: Copy Docker image to server | ||
run: | | ||
scp image.tar.gz ${{ env.SERVER_USER }}@${{ env.SERVER_IP }}:${{ env.DEPLOY_PATH }}/ | ||
- name: Deploy using Docker | ||
run: | | ||
ssh ${{ env.SERVER_USER }}@${{ env.SERVER_IP }} << EOF | ||
set -euo pipefail | ||
TIMESTAMP=\$(date +%Y%m%d%H%M%S) | ||
# Create backup directory if it doesn't exist | ||
mkdir -p ${{ env.BACKUP_PATH }} | ||
# Backup existing deployment if it exists | ||
if [ -d "${{ env.DEPLOY_PATH }}" ]; then | ||
mv ${{ env.DEPLOY_PATH }} ${{ env.BACKUP_PATH }}/backup-\$TIMESTAMP | ||
fi | ||
# Create new deployment directory | ||
mkdir -p ${{ env.DEPLOY_PATH }} | ||
ssh ${{ env.SERVER_USER }}@${{ env.SERVER_IP }} << 'EOF' | ||
cd ${{ env.DEPLOY_PATH }} | ||
docker load < image.tar.gz | ||
docker stop ${{ env.DOCKER_IMAGE }} || true | ||
docker rm ${{ env.DOCKER_IMAGE }} || true | ||
docker run -d --name ${{ env.DOCKER_IMAGE }} \ | ||
-p 80:80 \ | ||
--restart unless-stopped \ | ||
${{ env.DOCKER_IMAGE }} | ||
rm image.tar.gz | ||
EOF | ||
rsync -avz --delete .output/public/ ${{ env.SERVER_USER }}@${{ env.SERVER_IP }}:${{ env.DEPLOY_PATH }}/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Build stage | ||
FROM oven/bun:1 as builder | ||
WORKDIR /app | ||
COPY package.json bun.lockb ./ | ||
RUN bun install | ||
COPY . . | ||
RUN bun run build | ||
|
||
# Production stage | ||
FROM nginx:alpine | ||
COPY --from=builder /app/.output/public /usr/share/nginx/html | ||
COPY --from=builder /app/.output/server /app/server | ||
COPY nginx.conf /etc/nginx/conf.d/default.conf | ||
|
||
EXPOSE 80 | ||
CMD ["nginx", "-g", "daemon off;"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
server { | ||
listen 80; | ||
server_name localhost; | ||
root /usr/share/nginx/html; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.html; | ||
} | ||
|
||
# If you need to proxy to the Node server | ||
location /api { | ||
proxy_pass http://localhost:3000; | ||
proxy_http_version 1.1; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection 'upgrade'; | ||
proxy_set_header Host $host; | ||
proxy_cache_bypass $http_upgrade; | ||
} | ||
} |