Skip to content

Add wait for deployment to finish #7

Add wait for deployment to finish

Add wait for deployment to finish #7

Workflow file for this run

name: "Deploy App"
on:
push:
branches:
- main
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Build Frontend
working-directory: frontend
run: |
npm install
npm run build
- uses: actions/upload-artifact@v4
with:
name: frontend-build
path: frontend/dist/
build-backend:
runs-on: ubuntu-latest
needs: build-frontend
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: frontend-build
path: backend/src/main/resources/static
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21' # must match the version in the pom.xml
distribution: 'temurin'
cache: 'maven'
- name: Build with maven
run: mvn -B package --file backend/pom.xml
- uses: actions/upload-artifact@v4
with:
name: app.jar
path: backend/target/app.jar # must match the finalName in the pom.xml
push-to-docker-hub:
runs-on: ubuntu-latest
needs: build-backend
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: app.jar
path: backend/target
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }} # must match the name of the Dockerhub account
password: ${{ secrets.DOCKERHUB_PASSWORD }} # must match the password of the Dockerhub account
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ secrets.DOCKERHUB_TAG }} # Example: username/project:latest
context: .
deploy:
name: deploy-to-render
runs-on: ubuntu-latest
needs: push-to-docker-hub
environment:
name: Capstone Project # Capstone Project name
url: https://fullstack-v15z.onrender.com # Link to deployment
steps:
- name: Trigger Render.com Deployment
id: trigger-deploy
run: |
response=$(curl --request POST \
--url https://api.render.com/v1/services/${{ secrets.RENDER_SERVICE_ID }}/deploys \
--header 'accept: application/json' \
--header 'authorization: Bearer ${{ secrets.RENDER_API_KEY }}' \
--header 'content-type: application/json')
id=$(echo "$response" | jq -r '.id')
echo "deploy_id=$id" >> $GITHUB_ENV
- name: Wait for Deployment to finish
run: |
curl=$(curl --request GET \
--url https://api.render.com/v1/services/${{ secrets.RENDER_SERVICE_ID }}/deploys/${{ env.deploy_id }} \
--header 'accept: application/json' \
--header 'authorization: Bearer ${{ secrets.RENDER_API_KEY }}')
status=$(echo "$curl" | jq -r '.status')
maxTries=10
while [ "$status" != "live" ] && [ $maxTries -gt 0 ]; do
maxTries=$((maxTries - 1))
sleep 10
curl=$(curl --request GET \
--url https://api.render.com/v1/services/${{ secrets.RENDER_SERVICE_ID }}/deploys/${{ env.deploy_id }} \
--header 'accept: application/json' \
--header 'authorization: Bearer ${{ secrets.RENDER_API_KEY }}')
status=$(echo "$curl" | jq -r '.status')
done