Commit 6305740b authored by Eric Dieckman's avatar Eric Dieckman
Browse files

ci: improve pipeline with build stage and deployment hardening

- Add lint-and-build job (dotnet build) that runs on MRs and branch pushes
- Auto-deploy staging on_success after publish (was manual)
- Move EXTERNAL_PORT to per-job variables so environments can diverge
- Expand changes triggers to include docker-compose.yml, eng/**/* and nuget.config
- Add clarifying comment to DOCKER_VERSION
parent 0e9eff14
Loading
Loading
Loading
Loading
+34 −27
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@ variables:
  IMAGE_TAG: $CI_REGISTRY_IMAGE
  CONTAINER_NAME_PREFIX: visor
  CLOUDWATCH_LOG_GROUP: visor
  EXTERNAL_PORT: "5434"                           # define per environment if deploying prod/staging to same server
  DOCKER_VERSION: "28.3.2"
  DOCKER_VERSION: "28.3.2"                          # must match version installed on the runner host

stages:
  - build
  - publish
  - deploy

@@ -16,61 +16,66 @@ include:
  - project: 'cals/appdev/automation/configs'
    file: 'partials/deploy_docker_aspnet.yml'

# -----------------------   BUILD JOBS   ---------------------------
lint-and-build:
  stage: build
  image: mcr.microsoft.com/dotnet/sdk:10.0-alpine
  script:
    - dotnet build Cals.Visor.sln -c Release --no-incremental
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: '$CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
  tags:
    - cals-acs-net

# -----------------------   PUBLISH JOBS   ---------------------------
publish-docker:
  extends: .publish-docker-template
  rules:
    - if: '$CI_COMMIT_BRANCH == "staging" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
    - if: '$CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      changes:
        - src/**/*
        - Dockerfile
        - docker-compose.yml
        - "*.sln"
        - Directory.Build.*
        - eng/**/*
        - nuget.config
      when: on_success
    - if: '$CI_COMMIT_BRANCH != "staging" && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
      changes:
        - src/**/*
        - Dockerfile
        - "*.sln"
        - Directory.Build.*
      when: manual     
  tags:
    - cals-acs-net

# -----------------------   DEPLOY JOBS   ---------------------------
deploy-staging-docker:
  extends: .deploy-docker-aspnet-template
  when: manual
  needs: [publish-docker]
  tags:
    - cals-acs-net
  variables:
    EXTERNAL_PORT: "5434"
    DEPLOY_APP_SERVER: $STAGING_DOCKER_HOST
    AZURE_PFX_PASSWORD: $AZURE_PFXPASSWORD_STAGING
    DEPLOY_ENVIRONMENT: staging
    ASPNETCORE_ENVIRONMENT: Staging
    CLOUDWATCH_LOG_STREAM: api_staging
  rules:
    - if: $CI_COMMIT_BRANCH == "staging"
    - if: $CI_COMMIT_BRANCH == "dev"
      changes:
        - src/**/*
        - Dockerfile
        - "*.sln"
        - docker-compose.yml
        - Directory.Build.*  
    - if: $CI_COMMIT_BRANCH != "staging"
      changes:
        - src/**/*
        - Dockerfile
        - "*.sln"
        - docker-compose.yml
        - Directory.Build.*
      when: manual  
        - eng/**/*
        - nuget.config
      when: on_success

deploy-prod-docker:
  extends: .deploy-docker-aspnet-template
  tags:
    - cals-acs-net
  variables:
    EXTERNAL_PORT: "5434"                           # change to a different port if co-located with staging
    DEPLOY_APP_SERVER: $PRODUCTION_DOCKER_HOST
    AZURE_PFX_PASSWORD: $AZURE_PFXPASSWORD_PROD
    DEPLOY_ENVIRONMENT: prod
@@ -81,7 +86,9 @@ deploy-prod-docker:
      changes:
        - src/**/*
        - Dockerfile
        - "*.sln"
        - docker-compose.yml
        - "*.sln"
        - Directory.Build.*
        - eng/**/*
        - nuget.config
      when: manual