Below is a single-file GitHub Actions workflow that
- Builds your Docker image.
- Pushes it to GitHub Container Registry (GHCR).
- Uses Render’s Update Service API ( PATCH
/services/{serviceId} ) exactly as documented at https://api-docs.render.com/reference/update-service.
- Polls the deploy until it turns
live or fails.
# .github/workflows/render-deploy.yml
name: Build & Deploy → Render
on:
push:
branches: [ main ] # change if you deploy another branch
workflow_dispatch: # allow manual trigger
###############################################################################
# GLOBAL ENV #
###############################################################################
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
# Needed so the job can push to GHCR
permissions:
contents: read
packages: write
steps:
# ----------------------------------------------------------------------- #
# 1) CHECKOUT #
# ----------------------------------------------------------------------- #
- name: 🛎️ Checkout code
uses: actions/checkout@v4
# ----------------------------------------------------------------------- #
# 2) SET UP BUILDX #
# ----------------------------------------------------------------------- #
- name: 🔧 Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# ----------------------------------------------------------------------- #
# 3) LOGIN TO GHCR #
# ----------------------------------------------------------------------- #
- name: 🔐 Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} # provided automatically
# ----------------------------------------------------------------------- #
# 4) EXTRACT IMAGE TAG METADATA #
# ----------------------------------------------------------------------- #
- name: 🏷️ Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=short # <commit-sha>
type=raw,value=latest,enable={{is_default_branch}}
# ----------------------------------------------------------------------- #
# 5) BUILD + PUSH #
# ----------------------------------------------------------------------- #
- name: 📦 Build & push image to GHCR
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
# ----------------------------------------------------------------------- #
# 6) DEPLOY THROUGH RENDER *UPDATE SERVICE* API #
# ----------------------------------------------------------------------- #
- name: 🚀 Deploy image on Render
env:
RENDER_API_KEY : ${{ secrets.RENDER_API_KEY }} # personal or team API key
SERVICE_ID : ${{ secrets.RENDER_SERVICE_ID }} # e.g. srv-c1ru0hnd****
# use the *sha* tag we built above
IMAGE_URL : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
TIMEOUT_SEC : 1800 # 30-minute max
run: |
set -euo pipefail
echo "Updating Render service $SERVICE_ID with image:"
echo " $IMAGE_URL"
echo
# -------------------------------------------------------------------
# A) PATCH /services/{serviceId} (Update Service)
# Only field we need is imageUrl
# -------------------------------------------------------------------
RESPONSE_JSON=$(curl -sSL -X PATCH \
"https://api.render.com/v1/services/${SERVICE_ID}" \
-H "Authorization: Bearer ${RENDER_API_KEY}" \
-H "Content-Type: application/json" \
--data '{"imageUrl":"'"${IMAGE_URL}"'"}')
# Basic error check
ERROR_MSG=$(echo "$RESPONSE_JSON" | jq -r '.error.message? // empty')
if [[ -n "$ERROR_MSG" ]]; then
echo "❌ Render API error: $ERROR_MSG"
exit 1
fi
# A successful response returns both the updated service
# *and* the deploy object that was kicked off:
DEPLOY_ID=$(echo "$RESPONSE_JSON" | jq -r '.deploy.id')
if [[ "$DEPLOY_ID" == "null" || -z "$DEPLOY_ID" ]]; then
echo "❌ No deploy ID in response:"
echo "$RESPONSE_JSON"
exit 1
fi
echo "✅ Deploy created: $DEPLOY_ID"
echo
# -------------------------------------------------------------------
# B) POLL /deploys/{deployId} UNTIL STATUS = live | failed | canceled
# -------------------------------------------------------------------
START_TIME=$(date +%s)
while true; do
DEPLOY_JSON=$(curl -sSL \
"https://api.render.com/v1/deploys/${DEPLOY_ID}" \
-H "Authorization: Bearer ${RENDER_API_KEY}")
STATUS=$(echo "$DEPLOY_JSON" | jq -r '.status')
LOG_URL=$(echo "$DEPLOY_JSON" | jq -r '.logsUrl')
printf "⏳ Status: %-20s (logs: %s)\n" "$STATUS" "$LOG_URL"
case "$STATUS" in
live)
echo "🎉 Deployment finished and is live!"
break
;;
failed|canceled)
echo "❌ Deployment $STATUS"
exit 1
;;
esac
# Timeout watchdog
NOW=$(date +%s)
ELAPSED=$((NOW - START_TIME))
if (( ELAPSED > TIMEOUT_SEC )); then
echo "⌛ Timed-out after $ELAPSED seconds."
exit 1
fi
sleep 15
done
What changed vs. the previous attempt
- Using the correct endpoint: PATCH
/v1/services/{serviceId} (Update Service) instead of POST /deploys.
- Request body matches the docs: only
imageUrl is supplied when you’re switching the image.
- The response already contains a
deploy object → we pull deploy.id from there.
- Polling endpoint is GET
/v1/deploys/{deployId} (again per docs).
clearCache removed (not part of update-service call).
Required repository secrets
• RENDER_API_KEY – your Render API token
• RENDER_SERVICE_ID – the “srv-…” id of the service you’re deploying
No extra credentials are needed for GHCR; GitHub provides GITHUB_TOKEN automatically.