mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
97 lines
3.1 KiB
YAML
97 lines
3.1 KiB
YAML
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: Verify NPM Token
|
|
env:
|
|
# We map the secret here to check its existence
|
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
run: |
|
|
if [ -z "$NPM_TOKEN" ]; then
|
|
echo "::error::The NPM_TOKEN secret is missing or empty. Please add it to your GitHub Secrets."
|
|
exit 1
|
|
fi
|
|
echo "NPM_TOKEN is present, proceeding with build..."
|
|
|
|
- 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
|
|
env:
|
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
# Create the multi-line file
|
|
cat <<EOF > .npmrc_temp
|
|
@tria-plc:registry=https://npm.pkg.github.com
|
|
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
|
|
always-auth=true
|
|
EOF
|
|
|
|
# Build using the file
|
|
docker build --secret id=npmrc,src=.npmrc_temp -t edr-${{needs.environment.outputs.target}} .
|
|
docker build --secret id=npmrc,src=.npmrc_temp --target passenger-migration -t edr-passenger-migration-${{needs.environment.outputs.target}} .
|
|
|
|
# Shred/Remove the sensitive file
|
|
rm .npmrc_temp
|
|
|
|
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: 🧪 Run Passenger API migrations
|
|
if: ${{ matrix.service == 'passenger-api' }}
|
|
run: |
|
|
docker run --rm --env-file .env edr-passenger-migration-${{needs.environment.outputs.target}}
|
|
|
|
- name: 🚀 Start ${{ matrix.service }} Service
|
|
run: docker compose --project-name="edr-${{needs.environment.outputs.target}}" up -d --force-recreate ${{ matrix.service }} --build
|