Skip to content

Commit 8b3a7dc

Browse files
committed
ci: enhance deployment workflow to include file transfer and container management on VPS
1 parent 6eb1266 commit 8b3a7dc

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

.github/workflows/deploy.yml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,48 @@ jobs:
107107
NODE_VERSION=${{ env.NODE_VERSION }}
108108
109109
- name: Deploy to VPS
110+
uses: appleboy/[email protected]
111+
with:
112+
host: ${{ secrets.VPS_HOST }}
113+
username: ${{ secrets.VPS_USER }}
114+
key: ${{ secrets.VPS_SSH_KEY }}
115+
source: "docker-compose.yml"
116+
target: "~/webdev-bot-deploy"
117+
strip_components: 0
118+
119+
- name: Start containers on VPS
110120
uses: appleboy/[email protected]
111121
with:
112122
host: ${{ secrets.VPS_HOST }}
113123
username: ${{ secrets.VPS_USER }}
114124
key: ${{ secrets.VPS_SSH_KEY }}
115125
script: |
126+
cd ~/webdev-bot-deploy
127+
128+
# Create .env.local file with secrets
129+
cat > .env.local << EOF
130+
DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}
131+
CLIENT_ID=${{ secrets.CLIENT_ID }}
132+
EOF
133+
134+
# Set NODE_VERSION for docker-compose
135+
export NODE_VERSION=${{ env.NODE_VERSION }}
136+
116137
# Login to GitHub Container Registry
117138
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
118139
119-
# Pull the latest image
120-
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
121-
122-
# Stop and remove old container if it exists
123-
docker stop webdev-bot-prod 2>/dev/null || true
124-
docker rm webdev-bot-prod 2>/dev/null || true
140+
# Update docker-compose.yml to use the pre-built image
141+
cat > docker-compose.override.yml << EOF
142+
version: '3.8'
143+
services:
144+
bot-prod:
145+
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
146+
build: null
147+
EOF
125148
126-
# Run new container
127-
docker run -d \
128-
--name webdev-bot-prod \
129-
--restart unless-stopped \
130-
-e DISCORD_TOKEN="${{ secrets.DISCORD_TOKEN }}" \
131-
-e CLIENT_ID="${{ secrets.CLIENT_ID }}" \
132-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
149+
# Pull the latest image and start
150+
docker compose --profile prod pull
151+
docker compose --profile prod up -d
133152
134153
# Clean up old images
135154
docker image prune -af --filter "until=24h"

0 commit comments

Comments
 (0)