Untitled

                Never    
YAML
       
stages:
  - Build
  - Sandbox
  - QA
  # - Dev
  # - Production

variables:
  HTTP_PROXY: http://proxy01.calories.local:3128
  HTTPS_PROXY: http://proxy01.calories.local:3128
  http_proxy: http://proxy01.calories.local:3128
  https_proxy: http://proxy01.calories.local:3128
  no_proxy: .calories.local,.calories.space

Build:
  stage: Build
  variables:
    GIT_SUBMODULE_STRATEGY: recursive
  script:
    - |-
      docker build \
        --build-arg "HTTP_PROXY=${HTTP_PROXY}"  \
        --build-arg "HTTPS_PROXY=${HTTPS_PROXY}" \
        --build-arg "http_proxy=${http_proxy}" \
        --build-arg "https_proxy=${https_proxy}" \
        -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG} .
    - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
    - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}

Lint:
  stage: Build
  image: node:10-alpine
  script:
    - yarn install
    - yarn run lint
  only:
    - branches
  except:
    - master

.deploy: &deploy
  tags: [ swarm-calories ]
  script:
    # oh, gitlab-ci-token's ttl :(
    # docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
    - docker login registry.calories.space -u infrastructure -p "3Z-_1T7Q29PZYyazxL8a"
    - |-
      docker stack deploy \
      	--with-registry-auth \
      	--compose-file ./stack.yml \
      	${CALORIES_ENVIRONMENT}

.destroy: &destroy
  tags: [ swarm-calories ]
  script:
    - docker stack rm ${CALORIES_ENVIRONMENT}
  when: manual


Deploy Sandbox:
  <<: *deploy
  stage: Sandbox
  environment:
    name: sandbox/${CI_COMMIT_REF_NAME}
    url: http://traefik.calories.space/dashboard
    on_stop: Destroy Sandbox
  variables:
    CALORIES_VERSION: ${CI_COMMIT_REF_SLUG}
    CALORIES_ENVIRONMENT: sandbox-${CI_COMMIT_REF_SLUG}
  only: [ branches ]
  except: [ master ]

Destroy Sandbox:
  <<: *destroy
  stage: Sandbox
  environment:
    name: sandbox/${CI_COMMIT_REF_NAME}
    action: stop
  variables:
    GIT_STRATEGY: none
    CALORIES_ENVIRONMENT: sandbox-${CI_COMMIT_REF_SLUG}
  only: [ branches ]
  except: [ master ]

Deploy QA:
  <<: *deploy
  stage: QA
  environment:
    name: qa
    url: http://traefik.calories.space/dashboard
  variables:
    CALORIES_VERSION: ${CI_COMMIT_REF_SLUG}
    CALORIES_ENVIRONMENT: qa
  only: [ master ]
  when: manual

Raw Text