-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (124 loc) · 4.12 KB
/
Copy pathrelay-deploy.yaml
File metadata and controls
142 lines (124 loc) · 4.12 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
name: Deploy Relay Server
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches:
- main
release:
types:
- created
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/rxcode-relay
jobs:
build:
name: Build Relay Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
if: github.event_name == 'release'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.IMAGE }}
tags: |
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
type=sha,prefix=sha-
# Push / pull-request: build only, then smoke-test the binary boots in
# single-node mode (no REDIS_URL) and serves /healthz. No image is
# pushed and no deploy happens — that is release-gated below.
- name: Build Docker image (test only)
if: github.event_name != 'release'
uses: docker/build-push-action@v7
with:
context: relay-server
push: false
load: true
tags: rxcode-relay:ci
cache-from: type=gha,scope=rxcode-relay
cache-to: type=gha,mode=max,scope=rxcode-relay
- name: Health check (single-node)
if: github.event_name != 'release'
run: |
docker run -d --name relay-test -p 8787:8787 rxcode-relay:ci
for i in $(seq 1 30); do
if curl -sf http://localhost:8787/healthz > /dev/null 2>&1; then
echo "Health check passed"
curl -s http://localhost:8787/healthz
docker rm -f relay-test
exit 0
fi
sleep 1
done
echo "Health check failed"
docker logs relay-test
docker rm -f relay-test
exit 1
- name: Build and push Docker image
if: github.event_name == 'release'
uses: docker/build-push-action@v7
with:
context: relay-server
platforms: linux/amd64
push: true
build-args: |
VERSION=${{ github.ref_name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=rxcode-relay
cache-to: type=gha,mode=max,scope=rxcode-relay
deploy:
name: Deploy to Kubernetes
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'release'
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up kubectl
uses: azure/setup-kubectl@v5
with:
version: "latest"
- name: Configure kubectl
run: |
mkdir -p ~/.kube
echo "${{ secrets.K8S_CONFIG_FILE_B64 }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- name: Verify kubectl connection
run: kubectl cluster-info
- name: Deploy with kustomize
run: kubectl kustomize relay-server/k8s/ | kubectl apply -f -
- name: Pin deployment to this release
run: |
VERSION="${{ github.ref_name }}"
kubectl set image daemonset/rxcode-relay \
relay=${{ env.IMAGE }}:${VERSION} \
-n rxcode-relay
- name: Wait for rollout
run: kubectl rollout status daemonset/rxcode-relay -n rxcode-relay --timeout=300s
- name: Verify deployment
run: |
echo "=== Pods ==="
kubectl get pods -n rxcode-relay
echo "=== Service ==="
kubectl get service -n rxcode-relay
echo "=== Ingress ==="
kubectl get ingress -n rxcode-relay