stages:
    - build-dev
    - deploy-dev

workflow:
    rules:
        - if: $CI_COMMIT_MESSAGE =~ /\A(?i)-wip/
          when: never
        - if: '$CI_PIPELINE_SOURCE == "push"'

image: docker:19.03.12

variables:
    # Docker Variables
    DOCKER_TLS_CERTDIR: "/certs"

services:
    - name: docker:19.03.12-dind

before_script:
    - echo "$HARBOR_PASSWORD" | docker login -u "$HARBOR_USER" --password-stdin $HARBOR_URL

# Build
build dev workflow:
    stage: build-dev
    script:
        - docker build -t marconi.aoc.nrao.edu/workspaces/workflow:$CI_COMMIT_BRANCH -f services/workflow/Dockerfile.dev .
        - docker tag marconi.aoc.nrao.edu/workspaces/workflow:$CI_COMMIT_BRANCH marconi.aoc.nrao.edu/workspaces/workflow:$CI_COMMIT_SHORT_SHA
        - docker push marconi.aoc.nrao.edu/workspaces/workflow:$CI_COMMIT_SHORT_SHA
        - docker push marconi.aoc.nrao.edu/workspaces/workflow:$CI_COMMIT_BRANCH

build dev capability:
    stage: build-dev
    script:
        - docker build -t marconi.aoc.nrao.edu/workspaces/capability:$CI_COMMIT_BRANCH -f services/capability/Dockerfile.dev .
        - docker tag marconi.aoc.nrao.edu/workspaces/capability:$CI_COMMIT_BRANCH marconi.aoc.nrao.edu/workspaces/capability:$CI_COMMIT_SHORT_SHA
        - docker push marconi.aoc.nrao.edu/workspaces/capability:$CI_COMMIT_SHORT_SHA
        - docker push marconi.aoc.nrao.edu/workspaces/capability:$CI_COMMIT_BRANCH

# Tests


# Deploy
deploy dev:
    stage: deploy-dev
    script:
        - apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
        - curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
        - chmod +x /usr/local/bin/docker-compose
        - ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
        - docker-compose --version
