Newer
Older

Andrew Kapuscinski
committed
- build-base
- push-base

Andrew Kapuscinski
committed
- build
- unit-test

Andrew Kapuscinski
committed
- push

Andrew Kapuscinski
committed
- deploy

Andrew Kapuscinski
committed
# - deploy-test
variables:
PROJECT_NAME: "workspaces"

Andrew Kapuscinski
committed
DEPLOY_ENV: "dev"
# Postgres Service Variables
POSTGRES_DB: archive
POSTGRES_USER: "archive"
POSTGRES_PASSWORD: "docker"
# CI Postgres Service
services:
- name: marconi.aoc.nrao.edu/ops/ci/db:workspaces
alias: db
image: docker:19.03.12

Andrew Kapuscinski
committed
workflow:
rules:
- if: $CI_MERGE_REQUEST_TITLE =~ /^WIP:|^Draft:/
when: never

Andrew Kapuscinski
committed
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Import Templates
include:
- '/ci/build.template.yml'
- '/ci/push.template.yml'
- '/ci/cleanup.template.yml'
- '/ci/unit-test.template.yml'

Andrew Kapuscinski
committed
# Build Base Image

Andrew Kapuscinski
committed
build base image:
stage: build-base
script:
- docker build -t ${REGISTRY_URL}/ops/base:${PROJECT_NAME} -f Dockerfile.base .
- docker tag ${REGISTRY_URL}/ops/base:${PROJECT_NAME} ${REGISTRY_URL}/ops/base:${CI_COMMIT_SHORT_SHA}

Andrew Kapuscinski
committed
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE =~ /\A(?i)-ops/'
changes:

Andrew Kapuscinski
committed

Andrew Kapuscinski
committed
# Push Base Image Stage
push base image:
stage: push-base
script:
- echo "$HARBOR_PASSWORD" | docker login -u "$HARBOR_USER" --password-stdin $REGISTRY_URL
- docker push ${REGISTRY_URL}/ops/base:${PROJECT_NAME}
- docker push ${REGISTRY_URL}/ops/base:${CI_COMMIT_SHORT_SHA}

Andrew Kapuscinski
committed
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /\A(?i)-ops/'

Andrew Kapuscinski
committed
changes:

Andrew Kapuscinski
committed
# Run Schema
run schema:
stage: run-schema
image: ${REGISTRY_URL}/ops/base:${PROJECT_NAME}
script:
- export PGPASSWORD=$POSTGRES_PASSWORD
- cd schema && ./bin/run-migrations.sh "docker"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: always

Andrew Kapuscinski
committed
build workflow:
stage: build
variables:
SERVICE_NAME: "workflow"
PATH_PREFIX: "services/"

Andrew Kapuscinski
committed
build capability:
stage: build
variables:
SERVICE_NAME: "capability"
PATH_PREFIX: "services/"

Andrew Kapuscinski
committed
build notification:
stage: build
variables:
SERVICE_NAME: "notification"
PATH_PREFIX: "services/"

Andrew Kapuscinski
committed
build web:
stage: build
variables:
SERVICE_NAME: "web"
PATH_PREFIX: "apps/"
extends: .build
## Test Stages ##
# Unit Tests

Andrew Kapuscinski
committed
unit test workflow:
stage: unit-test
variables:
SERVICE_NAME: "workflow"
extends: .unit-test

Andrew Kapuscinski
committed
- build workflow

Andrew Kapuscinski
committed
unit test capability:
stage: unit-test
variables:
SERVICE_NAME: "capability"
extends: .unit-test

Andrew Kapuscinski
committed
- build capability

Andrew Kapuscinski
committed

Andrew Kapuscinski
committed
unit test notification:
stage: unit-test
variables:
SERVICE_NAME: "notification"
extends: .unit-test

Andrew Kapuscinski
committed
- build notification

Andrew Kapuscinski
committed
unit test coverage:
- pip install pytest pytest-cov

Andrew Kapuscinski
committed
- coverage combine --append
- coverage report
- coverage xml
artifacts:
reports:
cobertura: coverage.xml
paths:
- coverage.xml

Andrew Kapuscinski
committed
- unit test workflow
- unit test capability
- unit test notification
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

Andrew Kapuscinski
committed
push workflow:
stage: push

Andrew Kapuscinski
committed
variables:
SERVICE_NAME: "workflow"
extends: .push
needs:

Andrew Kapuscinski
committed
- unit test workflow

Andrew Kapuscinski
committed

Andrew Kapuscinski
committed
push capability:
stage: push

Andrew Kapuscinski
committed
variables:
SERVICE_NAME: "capability"
extends: .push
needs:

Andrew Kapuscinski
committed
- unit test capability

Andrew Kapuscinski
committed

Andrew Kapuscinski
committed
push notification:
stage: push
variables:
SERVICE_NAME: "notification"
extends: .push
needs:

Andrew Kapuscinski
committed
- unit test notification

Andrew Kapuscinski
committed
push web:
stage: push
variables:
SERVICE_NAME: "web"
extends: .push
# UI tests coming soon!
# needs:
# - unit test dev ui
stage: .post
variables:
SERVICE_NAME: "workflow"
extends: .cleanup

Andrew Kapuscinski
committed
allow_failure: true
stage: .post
variables:
SERVICE_NAME: "capability"
extends: .cleanup

Andrew Kapuscinski
committed
allow_failure: true
clean build notification:
stage: .post
variables:
SERVICE_NAME: "notification"
extends: .cleanup

Andrew Kapuscinski
committed
allow_failure: true
clean build web:
stage: .post
variables:
SERVICE_NAME: "web"
extends: .cleanup
allow_failure: true
stage: deploy-coverage-page
image: python:3.8-slim
dependencies:
- unit test coverage
script:
- mkdir public
artifacts:
paths:
- public
expire_in: 2 weeks
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Andrew Kapuscinski
committed
deploy:
stage: deploy
# Docker doesn't allow variable interpolation when declaring Docker Secret names
# This sed command finds and replaces "dsoc_ENV_secrets:" with "dsoc_${DEPLOY_ENV}_secrets:"
- sed -i "s/dsoc_ENV_secrets:/dsoc_${DEPLOY_ENV}_secrets:/g" docker-compose.dev.yml
- ENV=$DEPLOY_ENV TAG=$IMAGE_TAG docker stack deploy --compose-file docker-compose.dev.yml workspaces-${DEPLOY_ENV}
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Andrew Kapuscinski
committed
variables:
IMAGE_TAG: ${CI_DEFAULT_BRANCH}
- if: '$CI_COMMIT_TAG =~ /^test_[0-9]+\.[0-9]+.[0-9]+$/'
variables:
IMAGE_TAG: $CI_COMMIT_TAG
# override DEPLOY_ENV
DEPLOY_ENV: "test"