-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (154 loc) · 5.82 KB
/
deploy-dev.yml
File metadata and controls
180 lines (154 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Development MCP Server Deployment
#
# Deploys the remote MCP server to mcp-dev.digitalsamba.com
# Triggers automatically on push to develop branch
#
# GitHub Secrets Required:
# Repository secrets:
# - DOCKER_REGISTRY: Registry hostname
# - REGISTRY_USERNAME: Docker registry username
# - REGISTRY_PASSWORD: Docker registry password
# - DEPLOYMENT_USER: SSH user for deployment
# - DEPLOYMENT_SSH_KEY: SSH private key
#
# Environment secrets (development):
# - DEPLOYMENT_SERVER: Target server hostname
# - DEPLOYMENT_PATH: Server path for deployment files
# - MCP_URL: Public URL for health checks
name: Deploy Dev MCP Server
on:
push:
branches:
- develop
workflow_dispatch:
env:
IMAGE_NAME: digitalsamba-mcp-server
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Run tests
run: npm run test:ci
continue-on-error: true
build-and-deploy:
name: Build and Deploy to Dev
needs: test
runs-on: ubuntu-latest
environment: development
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Calculate commits ahead of latest tag
id: commits
run: |
# Get the latest tag by date (works even if tag is on different branch)
LATEST_TAG=$(git tag --sort=-creatordate | head -1)
if [ -n "$LATEST_TAG" ]; then
# Find merge base between tag and HEAD, then count commits since
MERGE_BASE=$(git merge-base $LATEST_TAG HEAD 2>/dev/null || echo "")
if [ -n "$MERGE_BASE" ]; then
COMMITS_AHEAD=$(git rev-list ${MERGE_BASE}..HEAD --count)
else
COMMITS_AHEAD=0
fi
else
COMMITS_AHEAD=0
fi
echo "ahead=$COMMITS_AHEAD" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST_TAG, Merge base: $MERGE_BASE, Commits ahead: $COMMITS_AHEAD"
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ secrets.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ secrets.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
build-args: |
GIT_COMMIT=${{ github.sha }}
GIT_REF=${{ github.ref_name }}
BUILD_TIME=${{ github.event.head_commit.timestamp }}
COMMITS_AHEAD=${{ steps.commits.outputs.ahead }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Copy deployment files to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOYMENT_SERVER }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_SSH_KEY }}
source: "deployment/docker-compose.yml"
target: ${{ secrets.DEPLOYMENT_PATH }}
strip_components: 1
- name: Deploy to server
uses: appleboy/ssh-action@v1.0.3
env:
REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
with:
host: ${{ secrets.DEPLOYMENT_SERVER }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_SSH_KEY }}
envs: REGISTRY,IMAGE_NAME
script: |
cd ${{ secrets.DEPLOYMENT_PATH }}
# Login to registry
echo "${{ secrets.REGISTRY_PASSWORD }}" | sudo docker login ${{ secrets.DOCKER_REGISTRY }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
# Pull latest image
sudo docker pull ${REGISTRY}/${IMAGE_NAME}:latest
# Stop and remove old container
sudo docker compose down --remove-orphans || true
# Start new container
sudo docker compose up -d
# Wait for service to be healthy
echo "Waiting for service to be healthy..."
sleep 10
# Cleanup old images
sudo docker image prune -f
- name: Verify deployment
run: |
echo "Waiting for service startup..."
sleep 15
# Health check
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" ${{ secrets.MCP_URL }}/health || echo "000")
if [ "$HTTP_STATUS" = "200" ]; then
echo "✅ Health check passed (HTTP $HTTP_STATUS)"
else
echo "⚠️ Health check returned HTTP $HTTP_STATUS"
curl -v ${{ secrets.MCP_URL }}/health || true
fi
- name: Deployment summary
run: |
echo "## 🚀 Dev MCP Server Deployed!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Item | Value |" >> $GITHUB_STEP_SUMMARY
echo "|------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| **Environment** | development |" >> $GITHUB_STEP_SUMMARY
echo "| **URL** | ${{ secrets.MCP_URL }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Commit** | ${{ github.sha }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Branch** | ${{ github.ref_name }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Triggered by** | ${{ github.actor }} |" >> $GITHUB_STEP_SUMMARY