|
1 | 1 | name: deploy relay |
2 | 2 |
|
3 | 3 | # Ops controls for the CI relay (moqx-main.ci.openmoq.org + moqx-000 alias). |
4 | | -# Restart, redeploy with a specific image tag, or change verbose level. |
| 4 | +# Restart, redeploy with a specific image tag, or change the log level. |
5 | 5 |
|
6 | 6 | on: |
7 | 7 | workflow_dispatch: |
|
12 | 12 | type: boolean |
13 | 13 | default: false |
14 | 14 | image_tag: |
15 | | - description: "Docker image tag (default: derived from branch — main→latest, release/X→X)" |
| 15 | + description: "Image tag (default derived from branch)" |
16 | 16 | required: false |
17 | 17 | default: "" |
18 | 18 | type: string |
19 | 19 | domain: |
20 | | - description: "DNS hostname (default: derived from branch — main→moqx-main, release/X→moqx-X)" |
| 20 | + description: "Hostname (default derived from branch)" |
21 | 21 | required: false |
22 | 22 | default: "" |
23 | 23 | type: string |
24 | | - verbose: |
25 | | - description: "GLOG verbose level (0=off, 1-3=increasing detail)" |
| 24 | + logging: |
| 25 | + description: "Log level (default INFO)" |
26 | 26 | required: false |
27 | | - default: "0" |
| 27 | + default: "default" |
28 | 28 | type: choice |
29 | 29 | options: |
30 | | - - "0" |
31 | | - - "1" |
32 | | - - "2" |
33 | | - - "3" |
| 30 | + - "default" |
| 31 | + - "WARN" |
| 32 | + - "DBG1" |
| 33 | + - "DBG2" |
| 34 | + - "DBG3" |
| 35 | + - "DBG4" |
| 36 | + enable_stats: |
| 37 | + description: "Enable stats dashboard (default enabled)" |
| 38 | + required: false |
| 39 | + type: boolean |
| 40 | + default: true |
34 | 41 |
|
35 | 42 | permissions: |
36 | 43 | contents: read |
|
65 | 72 |
|
66 | 73 | DOMAIN="${{ inputs.domain }}" |
67 | 74 | DOMAIN="${DOMAIN:-moqx-${LABEL}.ci.openmoq.org}" |
| 75 | + # Qualify a bare label (no dot) into the CI zone, so an explicit |
| 76 | + # `domain=moqx-main` works the same as the full FQDN. |
| 77 | + if [[ "$DOMAIN" != *.* ]]; then |
| 78 | + DOMAIN="${DOMAIN}.ci.openmoq.org" |
| 79 | + fi |
68 | 80 |
|
69 | 81 | echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT" |
70 | 82 | echo "domain=$DOMAIN" >> "$GITHUB_OUTPUT" |
@@ -126,73 +138,52 @@ jobs: |
126 | 138 | working-directory: docker |
127 | 139 | env: |
128 | 140 | RESTART_ONLY: ${{ inputs.restart_only }} |
129 | | - VERBOSE: ${{ inputs.verbose }} |
| 141 | + LOGGING: ${{ inputs.logging }} |
130 | 142 | DOMAIN: ${{ steps.target.outputs.domain }} |
131 | 143 | IMAGE_TAG: ${{ steps.target.outputs.image_tag }} |
132 | 144 | AWS_ACCESS_KEY_ID: ${{ secrets.OMOQ_CERTBOT_ACCESS_KEY_ID }} |
133 | 145 | AWS_SECRET_ACCESS_KEY: ${{ secrets.OMOQ_CERTBOT_SECRET_ACCESS_KEY }} |
| 146 | + ENABLE_STATS: ${{ inputs.enable_stats }} |
| 147 | + STATS_USER: ${{ secrets.STATS_USER }} |
| 148 | + STATS_PASSWORD: ${{ secrets.STATS_PASSWORD }} |
| 149 | + GRAFANA_ADMIN_PASSWORD: ${{ secrets.GRAFANA_ADMIN_PASSWORD }} |
134 | 150 | run: | |
135 | 151 | if [ "$RESTART_ONLY" = "true" ]; then |
136 | 152 | echo "==> Restarting relay..." |
137 | 153 | docker compose restart moqx |
| 154 | + for i in $(seq 1 30); do |
| 155 | + curl -sf "http://127.0.0.1:${ADMIN_PORT}/info" >/dev/null 2>&1 && break |
| 156 | + sleep 1 |
| 157 | + [ "$i" -eq 30 ] && { echo "::error::relay did not respond after restart"; docker compose logs moqx; exit 1; } |
| 158 | + done |
| 159 | + echo "==> Relay restarted: $(curl -sf http://127.0.0.1:${ADMIN_PORT}/info)" |
| 160 | + exit 0 |
| 161 | + fi |
| 162 | +
|
| 163 | + # folly XLOG override ("default" from the dialog = no override). |
| 164 | + LOGGING_CFG="" |
| 165 | + [ "${LOGGING}" != "default" ] && LOGGING_CFG="${LOGGING}" |
| 166 | +
|
| 167 | + # Ensure TLS cert |
| 168 | + CERT="/etc/letsencrypt/live/${DOMAIN}/fullchain.pem" |
| 169 | + if [ ! -f "$CERT" ]; then |
| 170 | + echo "::warning::No cert for ${DOMAIN} — provisioning via Route53" |
| 171 | + sudo -E certbot certonly --dns-route53 \ |
| 172 | + -d "$DOMAIN" --non-interactive --agree-tos \ |
| 173 | + --email gmarzot@openmoq.org |
| 174 | + elif ! sudo openssl x509 -in "$CERT" -noout -checkend 2592000 2>/dev/null; then |
| 175 | + echo "::warning::Cert for ${DOMAIN} expires within 30 days — renewing" |
| 176 | + sudo -E certbot renew --cert-name "$DOMAIN" |
138 | 177 | else |
139 | | - # Write .env |
140 | | - cat > .env <<EOF |
141 | | - DOMAIN=${DOMAIN} |
142 | | - CERTBOT_EMAIL=gmarzot@openmoq.org |
143 | | - MOQX_PORT=${RELAY_PORT} |
144 | | - MOQX_ADMIN_PORT=${ADMIN_PORT} |
145 | | - MOQX_LOG_LEVEL=0 |
146 | | - MOQX_VERBOSE=${VERBOSE} |
147 | | - EOF |
148 | | - sed -i 's/^[[:space:]]*//' .env |
149 | | -
|
150 | | - # Ensure TLS cert |
151 | | - CERT="/etc/letsencrypt/live/${DOMAIN}/fullchain.pem" |
152 | | - if [ ! -f "$CERT" ]; then |
153 | | - echo "::warning::No cert for ${DOMAIN} — provisioning via Route53" |
154 | | - sudo -E certbot certonly --dns-route53 \ |
155 | | - -d "$DOMAIN" --non-interactive --agree-tos \ |
156 | | - --email gmarzot@openmoq.org |
157 | | - elif ! sudo openssl x509 -in "$CERT" -noout -checkend 2592000 2>/dev/null; then |
158 | | - echo "::warning::Cert for ${DOMAIN} expires within 30 days — renewing" |
159 | | - sudo -E certbot renew --cert-name "$DOMAIN" |
160 | | - else |
161 | | - echo "Cert for ${DOMAIN} is valid" |
162 | | - fi |
163 | | -
|
164 | | - # Pull and deploy |
165 | | - docker pull "ghcr.io/${{ github.repository }}:${IMAGE_TAG}" |
166 | | -
|
167 | | - IMAGE="ghcr.io/${{ github.repository }}:${IMAGE_TAG}" |
168 | | - if [ "$IMAGE_TAG" != "latest" ]; then |
169 | | - docker tag "$IMAGE" "ghcr.io/${{ github.repository }}:latest" |
170 | | - fi |
171 | | -
|
172 | | - echo "==> Stopping existing container (if any)..." |
173 | | - docker compose down --remove-orphans 2>/dev/null || true |
174 | | - docker rm -f moqx logmon 2>/dev/null || true |
175 | | -
|
176 | | - echo "==> Starting relay on ${DOMAIN}:${RELAY_PORT}..." |
177 | | - docker compose up -d |
| 178 | + echo "Cert for ${DOMAIN} is valid" |
178 | 179 | fi |
179 | 180 |
|
180 | | - # Health check (both paths) |
181 | | - echo "==> Waiting for admin endpoint..." |
182 | | - for i in $(seq 1 30); do |
183 | | - if curl -sf http://127.0.0.1:${ADMIN_PORT}/info >/dev/null 2>&1; then |
184 | | - break |
185 | | - fi |
186 | | - sleep 1 |
187 | | - if [ "$i" -eq 30 ]; then |
188 | | - echo "::error::Admin endpoint did not respond within 30s" |
189 | | - docker compose logs moqx |
190 | | - exit 1 |
191 | | - fi |
192 | | - done |
193 | | -
|
194 | | - RESP=$(curl -sf http://127.0.0.1:${ADMIN_PORT}/info) |
195 | | - echo "==> Relay running: $RESP" |
| 181 | + # Deploy via the shared core (same script ci-main uses): writes .env, |
| 182 | + # pulls IMAGE_TAG (retagged :latest for compose), brings up the relay |
| 183 | + # + stats + public dashboard when ENABLE_STATS, health check, publish. |
| 184 | + PULL_IMAGE="ghcr.io/${{ github.repository }}:${IMAGE_TAG}" \ |
| 185 | + MOQX_LOGGING="$LOGGING_CFG" \ |
| 186 | + bash relay-deploy.sh |
196 | 187 |
|
197 | 188 | - name: Notify Slack |
198 | 189 | if: always() |
|
0 commit comments