-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (156 loc) · 6.68 KB
/
deploy-dev.yml
File metadata and controls
186 lines (156 loc) · 6.68 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
181
182
183
184
185
186
# ─────────────────────────────────────────────────────────
# Deploy to Development Container
#
# Triggers when a release with tag 'dev-v*' is created
# SSHs into the dev container, pulls latest code,
# builds, restarts the systemd service, and verifies health.
#
# Tags: dev-v1.2.3 → deploys to dev container
# v1.2.3 → skipped (handled by other workflows)
# ─────────────────────────────────────────────────────────
name: Deploy to Development Container
on:
release:
types: [created]
permissions:
contents: write
jobs:
# ─────────────────────────────────────────────
# Gate: Only run for dev-v* tags
# ─────────────────────────────────────────────
check-tag:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.check.outputs.should_run }}
version: ${{ steps.check.outputs.version }}
tag_name: ${{ steps.check.outputs.tag_name }}
steps:
- name: Check tag pattern
id: check
run: |
TAG="${{ github.event.release.tag_name }}"
echo "tag_name=${TAG}" >> "$GITHUB_OUTPUT"
if [[ "$TAG" == dev-v* ]]; then
echo "should_run=true" >> "$GITHUB_OUTPUT"
VERSION="${TAG#dev-v}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "✅ Tag '${TAG}' matches dev-v* — deploying to development"
else
echo "should_run=false" >> "$GITHUB_OUTPUT"
echo "⏭️ Tag '${TAG}' does not match dev-v* — skipping"
fi
# ─────────────────────────────────────────────
# Build & test before deploying
# ─────────────────────────────────────────────
build-and-test:
needs: check-tag
if: needs.check-tag.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: dev
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build core package
run: npm run build:core
- name: Build server package
run: npm run build:server
- name: Generate test certificates
run: |
mkdir -p server/cert
openssl req -x509 -newkey rsa:2048 -nodes -sha256 \
-subj "/CN=localhost" \
-keyout server/cert/server.key \
-out server/cert/server.crt \
-days 1
- name: Run core tests
run: npm run test:core
- name: Run server tests
run: npm run test:server
# ─────────────────────────────────────────────
# Deploy to dev container via SSH
# ─────────────────────────────────────────────
deploy-dev:
needs: [check-tag, build-and-test]
if: needs.check-tag.outputs.should_run == 'true'
runs-on: ubuntu-latest
environment: development
env:
VERSION: ${{ needs.check-tag.outputs.version }}
TAG_NAME: ${{ needs.check-tag.outputs.tag_name }}
steps:
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEV_CONTAINER_SSH_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
# Add known hosts to prevent interactive prompt
if [ -n "${{ secrets.DEV_CONTAINER_SSH_KNOWN_HOSTS }}" ]; then
echo "${{ secrets.DEV_CONTAINER_SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
fi
- name: Deploy to development container
run: |
ssh -i ~/.ssh/deploy_key \
-p ${{ secrets.DEV_CONTAINER_PORT }} \
-o StrictHostKeyChecking=no \
${{ secrets.DEV_CONTAINER_USER }}@${{ secrets.DEV_CONTAINER_HOST }} << 'DEPLOY_SCRIPT'
set -e
echo "======================================"
echo "Deploying LDAP Gateway ${{ env.TAG_NAME }}"
echo "======================================"
echo "==> Pulling latest code from dev branch"
cd /opt/ldap-gateway
git fetch origin dev
git checkout dev
git reset --hard origin/dev
echo "==> Current commit:"
git log -1 --oneline
echo "==> Installing dependencies"
npm ci --production=false
echo "==> Building core package"
npm run build:core
echo "==> Building server package"
npm run build:server
echo "==> Restarting LDAP Gateway service"
sudo systemctl restart ldap-gateway
echo "==> Waiting for service to start"
sleep 5
echo "==> Health check"
if sudo systemctl is-active --quiet ldap-gateway; then
echo "✅ LDAP Gateway is running"
sudo systemctl status ldap-gateway --no-pager --lines=10
else
echo "❌ LDAP Gateway failed to start"
sudo journalctl -u ldap-gateway --no-pager -n 50
exit 1
fi
echo "======================================"
echo "✅ Deployment complete"
echo "======================================"
DEPLOY_SCRIPT
- name: Update release with deployment status
if: always()
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG_NAME }}
name: "LDAP Gateway Dev ${{ env.TAG_NAME }}"
body: |
## LDAP Gateway Development Release
**Version:** `${{ env.VERSION }}`
**Environment:** Development
**Status:** ${{ job.status == 'success' && '✅ Deployed' || '❌ Failed' }}
**Branch:** `dev`
### Deployment Details
- Build & Tests: ${{ needs.build-and-test.result == 'success' && '✅ Passed' || '❌ Failed' }}
- Container Deploy: ${{ job.status == 'success' && '✅ Completed' || '❌ Failed' }}
---
*Automated deployment via GitHub Actions*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}