.gitlab-ci.yml 3.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
---
image: docker:18.01.0-ce-git
services:
  - docker:18.01.0-ce-dind
stages:
  - build
  - deploy

variables:
  DJANGO_RELEASE_IMAGE: $CI_REGISTRY_IMAGE/django:$CI_BUILD_REF_NAME
  NGINX_RELEASE_IMAGE: $CI_REGISTRY_IMAGE/nginx:$CI_BUILD_REF_NAME

#############
## Production
#############
build to production:
  stage: build
  script:
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
    - docker build -f compose/production/Dockerfile --target django -t $DJANGO_RELEASE_IMAGE .
    - docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:latest"
    - docker push $DJANGO_RELEASE_IMAGE
    - docker push "$CI_REGISTRY_IMAGE/django:latest"
    - docker build -f compose/production/Dockerfile --target nginx -t $NGINX_RELEASE_IMAGE .
    - docker tag $NGINX_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/nginx:latest"
    - docker push $NGINX_RELEASE_IMAGE
    - docker push "$CI_REGISTRY_IMAGE/nginx:latest"
  only:
    - tags
  environment: production
  tags:
    - docker

deploy to production:
  stage: deploy
  image: cdrx/rancher-gitlab-deploy
  script:
Laury Bueno's avatar
Laury Bueno committed
38
    - upgrade --environment <env_name> --stack <stack_name> --service <service_name> --no-finish-upgrade
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  only:
    - tags
  environment: production
  tags:
    - docker

##########
## Homolog
##########
build to homolog:
  stage: build
  script:
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
    - docker build -f compose/production/Dockerfile --target django -t $DJANGO_RELEASE_IMAGE .
    - docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:master"
    - docker push $DJANGO_RELEASE_IMAGE
    - docker push "$CI_REGISTRY_IMAGE/django:master"
    - docker build -f compose/production/Dockerfile --target nginx -t $NGINX_RELEASE_IMAGE .
    - docker tag $NGINX_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/nginx:master"
    - docker push $NGINX_RELEASE_IMAGE
    - docker push "$CI_REGISTRY_IMAGE/nginx:master"
  only:
    - /master/
  environment: homolog
  tags:
    - docker

# test to homolog:
#   stage: test
#   script:
#     - docker build -f compose/dev/django/Dockerfile -t $DJANGO_RELEASE_IMAGE .
#     - docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:test"
#     - docker run -d --env-file=./compose/dev/test_env --name=postgres postgres:9.6
#     - docker run --env-file=./compose/dev/test_env --link=postgres:postgres "$CI_REGISTRY_IMAGE/django:test" /test.sh
#   only:
#     - /master/
#   environment: homolog
#   tags:
#     - docker

deploy to homolog:
  stage: deploy
  image: cdrx/rancher-gitlab-deploy
  script:
Laury Bueno's avatar
Laury Bueno committed
83
    - upgrade --environment <env_name> --stack <stack_name> --service <service_name> --no-finish-upgrade
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  only:
    - /master/
  environment: homolog
  tags:
    - docker

##########
## Develop
##########
build to develop:
  stage: build
  script:
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
    - docker build -f compose/dev/django/Dockerfile -t $DJANGO_RELEASE_IMAGE .
    - docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:develop"
    - docker push "$CI_REGISTRY_IMAGE/django:develop"
  only:
    - /develop/
  environment: development
  tags:
    - docker

# test to develop:
#   stage: test
#   script:
#     - docker run -d --env-file=./compose/dev/test_env --name=postgres postgres:9.6
#     - docker run --env-file=./compose/dev/test_env --link=postgres:postgres "$CI_REGISTRY_IMAGE/django:develop" /test.sh
#   only:
#     - /develop/
#   environment: development
#   tags:
#     - docker