From 2a93de138f13af084d9cdd925c1435237c8520c2 Mon Sep 17 00:00:00 2001 From: SennayT Date: Thu, 28 May 2026 13:33:09 +0300 Subject: [PATCH] move pipelines to one file --- .github/workflows/deploy-freight.yml | 78 ------------------- .../{deploy-passenger.yml => deploy.yml} | 63 ++++++++++++++- scripts/deploy/sync-env-from-server.sh | 2 +- 3 files changed, 60 insertions(+), 83 deletions(-) delete mode 100644 .github/workflows/deploy-freight.yml rename .github/workflows/{deploy-passenger.yml => deploy.yml} (53%) diff --git a/.github/workflows/deploy-freight.yml b/.github/workflows/deploy-freight.yml deleted file mode 100644 index 778ad4067..000000000 --- a/.github/workflows/deploy-freight.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: Deploy Freight - -on: - push: - branches: - - main - - develop - - staging - - feat/improve-buid-pipeline - paths: - - "apps/edr-freight-api/**" - - "apps/edr-freight-web/**" - - "packages/**" - - "infrastructure/docker/Dockerfile.web" - - "infrastructure/nginx/**" - - "docker-compose.yaml" - - "pnpm-lock.yaml" - - "scripts/deploy/**" - - ".github/workflows/deploy-freight.yml" - workflow_dispatch: - -concurrency: - group: deploy-freight-${{ github.ref_name }} - cancel-in-progress: true - -jobs: - deploy: - name: Build and deploy freight stack - runs-on: self-hosted - env: - PROJECT: edr-freight - BRANCH: ${{ github.ref_name }} - DEPLOY_USER: user - BUILD_ENV_FILE: freight-web.build.env - DOCKER_BUILDKIT: "1" - COMPOSE_DOCKER_CLI_BUILD: "1" - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Sync environment from server - run: | - chmod +x scripts/deploy/*.sh - ./scripts/deploy/sync-env-from-server.sh \ - freight-api \ - freight-portal \ - freight-backoffice - - - name: Set compose project name - run: | - set -euo pipefail - branch_slug=$(echo "${BRANCH}" | tr "[:upper:]" "[:lower:]" | sed -E "s/[^a-z0-9]+/-/g; s/^-+//; s/-+$//") - echo "COMPOSE_PROJECT_NAME=${PROJECT}-${branch_slug}" >> "${GITHUB_ENV}" - - - name: Configure npm auth for Docker builds - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: ./scripts/deploy/create-npmrc.sh - - - name: Build images - run: | - set -euo pipefail - docker compose --project-name "${COMPOSE_PROJECT_NAME}" build \ - freight-api \ - freight-portal \ - freight-backoffice - - # - name: Deploy containers - # run: | - # set -euo pipefail - # docker compose --project-name "${COMPOSE_PROJECT_NAME}" up -d \ - # freight-api \ - # freight-portal \ - # freight-backoffice - - - name: Remove npm credentials from workspace - if: always() - run: rm -f .npmrc .npmrc_temp diff --git a/.github/workflows/deploy-passenger.yml b/.github/workflows/deploy.yml similarity index 53% rename from .github/workflows/deploy-passenger.yml rename to .github/workflows/deploy.yml index c282fd9d5..c3b40f659 100644 --- a/.github/workflows/deploy-passenger.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy Passenger +name: Deploy Stacks on: push: @@ -8,6 +8,8 @@ on: - staging - feat/improve-buid-pipeline paths: + - "apps/edr-freight-api/**" + - "apps/edr-freight-web/**" - "apps/edr-passenger-api/**" - "apps/edr-passenger-web/**" - "packages/**" @@ -16,15 +18,68 @@ on: - "docker-compose.yaml" - "pnpm-lock.yaml" - "scripts/deploy/**" - - ".github/workflows/deploy-passenger.yml" + - ".github/workflows/deploy.yml" workflow_dispatch: concurrency: - group: deploy-passenger-${{ github.ref_name }} + group: deploy-${{ github.ref_name }} cancel-in-progress: true jobs: - deploy: + deploy-freight: + name: Build and deploy freight stack + runs-on: self-hosted + env: + PROJECT: edr-freight + BRANCH: ${{ github.ref_name }} + DEPLOY_USER: user + BUILD_ENV_FILE: freight-web.build.env + DOCKER_BUILDKIT: "1" + COMPOSE_DOCKER_CLI_BUILD: "1" + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Sync environment from server + run: | + chmod +x scripts/deploy/*.sh + ./scripts/deploy/sync-env-from-server.sh \ + freight-api \ + freight-portal \ + freight-backoffice + + - name: Set compose project name + run: | + set -euo pipefail + branch_slug=$(echo "${BRANCH}" | tr "[:upper:]" "[:lower:]" | sed -E "s/[^a-z0-9]+/-/g; s/^-+//; s/-+$//") + echo "COMPOSE_PROJECT_NAME=${PROJECT}-${branch_slug}" >> "${GITHUB_ENV}" + + - name: Configure npm auth for Docker builds + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: ./scripts/deploy/create-npmrc.sh + + - name: Build images + run: | + set -euo pipefail + docker compose --project-name "${COMPOSE_PROJECT_NAME}" build \ + freight-api \ + freight-portal \ + freight-backoffice + + # - name: Deploy containers + # run: | + # set -euo pipefail + # docker compose --project-name "${COMPOSE_PROJECT_NAME}" up -d \ + # freight-api \ + # freight-portal \ + # freight-backoffice + + - name: Remove npm credentials from workspace + if: always() + run: rm -f .npmrc .npmrc_temp + + deploy-passenger: name: Build and deploy passenger stack runs-on: self-hosted env: diff --git a/scripts/deploy/sync-env-from-server.sh b/scripts/deploy/sync-env-from-server.sh index b1fa54af6..52c4a1aec 100644 --- a/scripts/deploy/sync-env-from-server.sh +++ b/scripts/deploy/sync-env-from-server.sh @@ -14,7 +14,7 @@ set -euo pipefail DEPLOY_USER="${DEPLOY_USER:-tria}" BRANCH="${BRANCH:?BRANCH is required}" BRANCH_SLUG="${BRANCH_SLUG:-$(echo "${BRANCH}" | tr "[:upper:]" "[:lower:]" | sed -E "s/[^a-z0-9]+/-/g; s/^-+//; s/-+$//")}" -ENV_ROOT="${ENV_ROOT:-/home/${DEPLOY_USER}/environment/edr/${PROJECT:?PROJECT is required}/${BRANCH_SLUG}}" +ENV_ROOT="${ENV_ROOT:-/home/${DEPLOY_USER}/environment/edr/${BRANCH_SLUG}/${PROJECT:?PROJECT is required}}" if [[ ! -d "${ENV_ROOT}" ]]; then echo "Environment directory not found: ${ENV_ROOT}" >&2