.gitlab-ci.yml 2.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
---
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
Bruno Martin's avatar
Bruno Martin committed
12 13 14
  DJANGO_HOMOLOG_IMAGE: $CI_REGISTRY_IMAGE/django:$CI_BUILD_REF_NAME-$CI_COMMIT_SHORT_SHA
  NGINX_hOMOLOG_IMAGE: $CI_REGISTRY_IMAGE/nginx:$CI_BUILD_REF_NAME-$CI_COMMIT_SHORT_SHA
  KUBECONFIG: /etc/k8s-config
15

Bruno Martin's avatar
Bruno Martin committed
16 17 18 19
##########
## Homolog
##########
build to homolog:
20 21 22
  stage: build
  script:
    - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
Bruno Martin's avatar
Bruno Martin committed
23 24 25 26
    - docker build -f compose/production/Dockerfile --target django -t $DJANGO_HOMOLOG_IMAGE .
    - docker push $DJANGO_HOMOLOG_IMAGE
    - docker build -f compose/production/Dockerfile --target nginx -t $NGINX_HOMOLOG_IMAGE .
    - docker push $NGINX_HOMOLOG_IMAGE
27
  only:
Bruno Martin's avatar
Bruno Martin committed
28 29
    - /master/
  environment: homolog
30 31 32
  tags:
    - docker

Bruno Martin's avatar
Bruno Martin committed
33 34 35 36 37 38 39 40 41 42 43 44 45
deploy to homolog:
  stage: deploy
  image: hacklab/kubectl:latest
  script:
    - echo ${kube_config} | base64 -d > ${KUBECONFIG}
    - kubectl -n ctb-escola-dev --record deployment.apps/django set image deployment.v1.apps/django django=$DJANGO_HOMOLOG_IMAGE nginx=$NGINX_HOMOLOG_IMAGE
  only:
    - /master/
  environment: homolog
  variables:
    GIT_STRATEGY: none
  tags:
    - docker
46

Bruno Martin's avatar
Bruno Martin committed
47 48 49 50
#############
## Production
#############
build to production:
51 52 53 54
  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 .
Bruno Martin's avatar
Bruno Martin committed
55
    - docker tag $DJANGO_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/django:latest"
56
    - docker push $DJANGO_RELEASE_IMAGE
Bruno Martin's avatar
Bruno Martin committed
57
    - docker push "$CI_REGISTRY_IMAGE/django:latest"
58
    - docker build -f compose/production/Dockerfile --target nginx -t $NGINX_RELEASE_IMAGE .
Bruno Martin's avatar
Bruno Martin committed
59
    - docker tag $NGINX_RELEASE_IMAGE "$CI_REGISTRY_IMAGE/nginx:latest"
60
    - docker push $NGINX_RELEASE_IMAGE
Bruno Martin's avatar
Bruno Martin committed
61
    - docker push "$CI_REGISTRY_IMAGE/nginx:latest"
62
  only:
Bruno Martin's avatar
Bruno Martin committed
63 64
    - tags
  environment: production
65 66 67
  tags:
    - docker

Bruno Martin's avatar
Bruno Martin committed
68 69 70
deploy to production:
  stage: deploy
  image: hacklab/kubectl:latest
71
  script:
Bruno Martin's avatar
Bruno Martin committed
72 73
    - echo ${kube_config} | base64 -d > ${KUBECONFIG}
    - kubectl -n ctb-escola-prod --record deployment.apps/django set image deployment.v1.apps/django django=$DJANGO_RELEASE_IMAGE nginx=$NGINX_RELEASE_IMAGE
74
  only:
Bruno Martin's avatar
Bruno Martin committed
75 76
    - tags
  environment: production
77
  variables:
Bruno Martin's avatar
Bruno Martin committed
78
    GIT_STRATEGY: none
79 80
  tags:
    - docker