Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 9772bc5

Browse files
committed
deploy xmem-go to aws
1 parent d853d98 commit 9772bc5

5 files changed

Lines changed: 100 additions & 6 deletions

File tree

.github/workflows/deploy-go.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Deploy xmem-go to the PRODUCTION AWS EC2 instance when Go code changes land on main.
2+
#
3+
# Mirrors the Python deploy workflow: SSHes into EC2, pulls latest main,
4+
# builds the Go binary on-server, and restarts the xmem-go systemd service.
5+
#
6+
# Re-uses the same EC2 secrets as the Python deploy workflow:
7+
# EC2_HOST, EC2_USER, EC2_SSH_KEY, EC2_SSH_KEY_PASSPHRASE
8+
9+
name: Deploy xmem-go
10+
11+
on:
12+
push:
13+
branches: [main]
14+
paths:
15+
- 'xmem-go/**'
16+
workflow_dispatch:
17+
18+
concurrency:
19+
group: deploy-xmem-go
20+
cancel-in-progress: false
21+
22+
jobs:
23+
deploy:
24+
runs-on: ubuntu-latest
25+
environment:
26+
name: production
27+
url: ${{ vars.PRODUCTION_URL }}
28+
permissions:
29+
contents: read
30+
deployments: write
31+
32+
steps:
33+
- name: Create deployment
34+
uses: chrnorm/deployment-action@v2
35+
id: deployment
36+
with:
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
environment: production
39+
40+
- name: Deploy over SSH
41+
uses: appleboy/ssh-action@v1.2.2
42+
with:
43+
host: ${{ secrets.EC2_HOST }}
44+
username: ${{ secrets.EC2_USER }}
45+
key: ${{ secrets.EC2_SSH_KEY }}
46+
passphrase: ${{ secrets.EC2_SSH_KEY_PASSPHRASE }}
47+
command_timeout: 20m
48+
script: |
49+
set -euo pipefail
50+
export PATH=$PATH:/usr/local/go/bin
51+
cd "${{ secrets.EC2_DEPLOY_PATH }}"
52+
53+
echo "── Pulling latest main ──"
54+
git fetch origin main
55+
git checkout main
56+
git pull origin main
57+
58+
echo "── Building xmem-go ──"
59+
cd xmem-go
60+
go build -o xmem-go ./cmd/xmem
61+
62+
echo "── Restarting xmem-go service ──"
63+
sudo systemctl restart xmem-go
64+
65+
echo "── Waiting for health endpoint ──"
66+
for i in $(seq 1 30); do
67+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8002/health || true)
68+
if [ "$HTTP_CODE" = "200" ]; then
69+
echo "Health check passed (attempt $i)"
70+
exit 0
71+
fi
72+
echo "Health check attempt $i: HTTP $HTTP_CODE — retrying in 10s"
73+
sleep 10
74+
done
75+
echo "FATAL: Health check never returned 200 after 300s"
76+
exit 1
77+
78+
- name: Deployment succeeded
79+
if: success()
80+
uses: chrnorm/deployment-status@v2
81+
with:
82+
token: ${{ secrets.GITHUB_TOKEN }}
83+
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
84+
state: success
85+
environment-url: ${{ vars.PRODUCTION_URL }}
86+
87+
- name: Deployment failed
88+
if: failure()
89+
uses: chrnorm/deployment-status@v2
90+
with:
91+
token: ${{ secrets.GITHUB_TOKEN }}
92+
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
93+
state: failure

xmem-go/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# XMem Go runs separately from the production Python service.
22
API_HOST=0.0.0.0
3-
API_PORT=8081
3+
API_PORT=8002
44
API_KEYS='["dev-xmem-go-key"]'
55
CORS_ORIGINS='["http://localhost:3000","http://localhost:5173"]'
66
RATE_LIMIT=60

xmem-go/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
!.env.example
44
coverage.out
55
tmp/
6+
xmem-go
67

xmem-go/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ go test ./...
3030
go run ./cmd/xmem
3131
```
3232

33-
The server listens on `http://localhost:8081` by default. Use the dev API key from `.env.example`:
33+
The server listens on `http://localhost:8002` by default. Use the dev API key from `.env.example`:
3434

3535
```bash
36-
curl http://localhost:8081/health
36+
curl http://localhost:8002/health
3737

38-
curl -X POST http://localhost:8081/v1/memory/ingest \
38+
curl -X POST http://localhost:8002/v1/memory/ingest \
3939
-H 'Authorization: Bearer dev-xmem-go-key' \
4040
-H 'Content-Type: application/json' \
4141
-d '{"user_query":"My name is Alice and I work at XMem.","user_id":"alice"}'
4242

4343
# The ingest response returns a durable job_id immediately. Poll the returned
4444
# status_url until status is "succeeded" before retrieving the newly written memory.
4545

46-
curl -X POST http://localhost:8081/v1/memory/retrieve \
46+
curl -X POST http://localhost:8002/v1/memory/retrieve \
4747
-H 'Authorization: Bearer dev-xmem-go-key' \
4848
-H 'Content-Type: application/json' \
4949
-d '{"query":"Where do I work?","user_id":"alice","top_k":5}'

xmem-go/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ FROM alpine:3.21
88
WORKDIR /app
99
COPY --from=build /out/xmem-go /app/xmem-go
1010
COPY .env.example /app/.env.example
11-
EXPOSE 8081
11+
EXPOSE 8002
1212
CMD ["/app/xmem-go"]
1313

0 commit comments

Comments
 (0)