mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
add deployment pipeline
This commit is contained in:
80
.github/workflows/deploy.yaml
vendored
Normal file
80
.github/workflows/deploy.yaml
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
name: Automatic Deployment
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
environment:
|
||||
name: 🌍 Setup Environment
|
||||
runs-on: [self-hosted]
|
||||
outputs:
|
||||
target: ${{ steps.dev.outputs.target || steps.staging.outputs.target }}
|
||||
steps:
|
||||
- name: 🛠️ Set Development Environment
|
||||
id: dev
|
||||
if: ${{github.ref_name == 'dev'}}
|
||||
run: |
|
||||
echo "target=dev" >> $GITHUB_OUTPUT
|
||||
- name: 🚀 Set Staging Environment
|
||||
id: staging
|
||||
if: ${{github.ref_name == 'staging'}}
|
||||
run: |
|
||||
echo "target=staging" >> $GITHUB_OUTPUT
|
||||
|
||||
build-base-image:
|
||||
name: 🏗️ Build Base Image
|
||||
runs-on: [self-hosted, dev]
|
||||
needs: [environment]
|
||||
steps:
|
||||
- name: 🔍 Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 🐳 Build Docker Image
|
||||
run: docker build -t edr-${{needs.environment.outputs.target}} .
|
||||
|
||||
deploy-service:
|
||||
name: ${{ matrix.display_name }}
|
||||
runs-on: [self-hosted, dev]
|
||||
needs: [build-base-image, environment]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- service: freight-api
|
||||
env_file: .env.freight-api
|
||||
display_name: 🚚 Deploy Freight API Service
|
||||
- service: passenger-api
|
||||
env_file: .env.passenger-api
|
||||
display_name: 🧑🦲 Deploy Passenger API Service
|
||||
|
||||
steps:
|
||||
- name: 🔍 Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 📋 Copy ${{ matrix.service }} Environment
|
||||
run: cp ~/environment/edr/${{needs.environment.outputs.target}}/${{ matrix.env_file }} .env
|
||||
|
||||
- name: 🚀 Start ${{ matrix.service }} Service
|
||||
run: docker compose --project-name="edr-${{needs.environment.outputs.target}}" up -d --force-recreate ${{ matrix.service }} --build
|
||||
|
||||
cleanup:
|
||||
name: 🧹 Cleanup Docker Resources
|
||||
runs-on: [self-hosted]
|
||||
needs:
|
||||
- deploy-service
|
||||
if: always() # Run even if previous jobs fail
|
||||
steps:
|
||||
- name: 🗑️ Remove unused Docker resources
|
||||
run: |
|
||||
echo "🧹 Cleaning up Docker resources..."
|
||||
# Remove all stopped containers
|
||||
docker container prune -f
|
||||
# Remove unused images (both dangling and unreferenced)
|
||||
docker image prune -a -f
|
||||
|
||||
echo "✅ Docker cleanup completed!"
|
||||
21
docker-compose.yaml
Normal file
21
docker-compose.yaml
Normal file
@@ -0,0 +1,21 @@
|
||||
services:
|
||||
freight-api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Dockerfile
|
||||
target: freight-api
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
- ${PORT}:${PORT}
|
||||
restart: unless-stopped
|
||||
passenger-api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Dockerfile
|
||||
target: passenger-api
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
- ${PORT}:${PORT}
|
||||
restart: unless-stopped
|
||||
Reference in New Issue
Block a user