Skip to content

Deploy App

Deploy App #88

Workflow file for this run

name: Deploy App
on:
push:
branches: [main]
workflow_dispatch:
env:
NODE_VERSION: '22'
JAVA_VERSION: '21'
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Build Frontend
working-directory: frontend
run: |
npm ci
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
- uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: temurin
cache: maven
- name: Build with Maven
run: mvn -B -DskipTests clean package --file backend/pom.xml
- name: Verify JAR
run: |
if [ ! -f backend/target/app.jar ]; then
echo "Error: app.jar not found!"
exit 1
fi
ls -lh backend/target/app.jar
- uses: actions/upload-artifact@v4
with:
name: app.jar
path: backend/target/app.jar
retention-days: 1
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
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: |
${{ secrets.DOCKERHUB_IMAGE }}:latest
${{ secrets.DOCKERHUB_IMAGE }}:${{ github.sha }}
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_IMAGE }}:buildcache,mode=max
deploy:
needs: push-to-docker-hub
runs-on: ubuntu-latest
steps:
- name: Trigger Coolify Deployment
run: |
response=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: Bearer ${{ secrets.COOLIFY_API_TOKEN }}" \
"${{ secrets.COOLIFY_API_URL }}")
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" -ne 200 ] && [ "$http_code" -ne 201 ]; then
echo "Deployment failed with HTTP $http_code"
exit 1
fi
echo "Deployment triggered successfully"
- name: Summary
run: |
echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Triggered by**: @${{ github.actor }}" >> $GITHUB_STEP_SUMMARY