.gitlab-ci.yml 7.08 KB
Newer Older
David Mendez's avatar
David Mendez committed
1 2 3
variables:
  DOCKER_TLS_CERTDIR: ""
  GIT_STRATEGY: clone
4 5
  REGISTRY_USER: chembl/research
  APPLICATION: lina-web
David Mendez's avatar
David Mendez committed
6 7 8
  RELEASE_IMAGE: $CI_REGISTRY/$REGISTRY_USER/$APPLICATION:$CI_BUILD_REF_NAME
  DOCKER_IMAGE: $CI_REGISTRY/$REGISTRY_USER/$APPLICATION
  DOCKER_DRIVER: overlay
9 10
  CONFIGS_FOLDER: run_config
  # Config staging
11
  ENV_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/staging/.env
12
  INGRESS_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/staging/ingress.yml
13 14 15 16 17 18
  # Config prod hx
  ENV_PROD_HX_FILE_PATH: ${CONFIGS_FOLDER}/prod_hx/.env
  INGRESS_PROD_HX_FILE_PATH: ${CONFIGS_FOLDER}/prod_hx/ingress.yml
  # Config prod hh
  ENV_PROD_HH_FILE_PATH: ${CONFIGS_FOLDER}/prod_hh/.env
  INGRESS_PROD_HH_FILE_PATH: ${CONFIGS_FOLDER}/prod_hh/ingress.yml
David Mendez's avatar
David Mendez committed
19 20 21

stages:
  - build
David Mendez's avatar
David Mendez committed
22
  - test
23
  - prepare_config
David Mendez's avatar
David Mendez committed
24
  - deploy
David Mendez's avatar
David Mendez committed
25

26
build:
27 28 29 30 31
  image:
    name: docker/compose:1.25.5
    entrypoint: ["/bin/sh", "-c"]
  stage: build
  only:
David Mendez's avatar
David Mendez committed
32
    - staging
33 34 35 36
  services:
    - docker:dind
  tags:
    - dind
37 38
  variables:
    DOCKER_HOST: tcp://docker:2375
David Mendez's avatar
David Mendez committed
39
  script:
40 41 42 43 44
    - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
    - echo Building ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
    - docker-compose build development
    - echo Deploying ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
    - docker push ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
David Mendez's avatar
David Mendez committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

# build-prod:
#   image:
#     name: docker/compose:1.25.5
#     entrypoint: ["/bin/sh", "-c"]
#   stage: build
#   only:
#     - master
#     # - master
#   variables:
#     DOCKER_HOST: tcp://docker:2375
#   script:
#     - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
#     - echo Building ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
#     - docker-compose build production
#     - echo Deploying ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
#     - docker push ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}    

David Mendez's avatar
David Mendez committed
63 64 65 66
unit-tests:
  stage: test
  script:
    - echo "ToDo UNIT TESTS"
David Mendez's avatar
David Mendez committed
67

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
prepare_config_staging:
  stage: prepare_config
  image:
    name: alpine/git
    entrypoint: ["/bin/sh", "-c"]
  only:
    - staging
  script:
    - set -x
    - rm -rf ${CONFIGS_FOLDER} || true
    - mkdir -p ${CONFIGS_FOLDER}
    - git clone https://${CONFIG_DEPLOY_GITLAB_USERNAME}:${CONFIG_DEPLOY_GITLAB_TOKEN}@${CONFIGURATIONS_REPO} ${CONFIGS_FOLDER}
  tags:
    - docker
  artifacts:

    paths:
85
      - ${ENV_STAGING_FILE_PATH}
86 87 88
      - ${INGRESS_STAGING_FILE_PATH}
      

David Mendez's avatar
David Mendez committed
89 90 91 92 93 94 95 96
deploy-dev-hx:
  image:
    name: lachlanevenson/k8s-kubectl:latest
    entrypoint: ["/bin/sh", "-c"]
  only:
    - dev
  stage: deploy
  script:
97
    - set -x
David Mendez's avatar
David Mendez committed
98 99 100
    - echo "$KUBE_CA_PEM_HX" > "$(pwd)/kube.ca.pem"
    - kubectl config set-cluster ${KUBE_CLUS_NAME_HX} --server="${KUBE_URL_HX}" --certificate-authority="$(pwd)/kube.ca.pem"
    - kubectl config set-credentials ${KUBE_USER_HX} --token="${KUBE_TOKEN_HX}"
101 102 103 104
    - kubectl config set-context ${CHEMBL_NS_STAGING} --cluster=${KUBE_CLUS_NAME_HX} --user=${KUBE_USER_HX}
    - kubectl config use-context ${CHEMBL_NS_STAGING}
    - echo ${CHEMBL_NS_STAGING} ${KUBE_URL_HX} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
    - kubectl get pods -n ${CHEMBL_NS_STAGING}
105
    - kubectl create secret generic ${ENV_SECRET_NAME_STAGING} --from-file=.env=${ENV_STAGING_FILE_PATH} -o yaml -n ${CHEMBL_NS_STAGING} --dry-run=client | kubectl apply -f -
David Mendez's avatar
David Mendez committed
106 107 108 109 110 111 112 113 114 115
    - cat ${CONFIG_STAGING_FILE_PATH}
    - echo ${KUBE_NAMESPACE_DEV} ${KUBE_URL_HH} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
    - kubectl get pods -n ${KUBE_NAMESPACE_DEV}
    - sed -i "s~<VERSION>~${CI_COMMIT_SHORT_SHA}~" k8s-deployment.yml
    - sed -i "s~<DOCKER_IMAGE>~${DOCKER_IMAGE}~" k8s-deployment.yml
    - sed -i "s~<HTTP_PROXY>~${HTTP_PROXY_HX}~g" k8s-deployment.yaml
    - sed -i "s~<HTTPS_PROXY>~${HTTPS_PROXY_HX}~g" k8s-deployment.yaml
    - sed -i "s~<NO_PROXY>~${NO_PROXY_HX_DEFAULT}~g" k8s-deployment.yaml
    - sed -i "s~<ENV_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_STAGING}~g" k8s-deployment.yaml
    - kubectl apply -n ${KUBE_NAMESPACE_DEV} -f k8s-deployment.yml
116 117 118 119
    - cat ${INGRESS_STAGING_FILE_PATH}
    - kubectl apply -n ${CHEMBL_NS_STAGING} -f ${INGRESS_STAGING_FILE_PATH}


David Mendez's avatar
David Mendez committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
prepare_config_prod:
  stage: prepare_config
  image:
    name: alpine/git
    entrypoint: ["/bin/sh", "-c"]
  only:
    - master
  script:
    - set -x
    - rm -rf ${CONFIGS_FOLDER} || true
    - mkdir -p ${CONFIGS_FOLDER}
    - git clone https://${CONFIG_DEPLOY_GITLAB_USERNAME}:${CONFIG_DEPLOY_GITLAB_TOKEN}@${CONFIGURATIONS_REPO} ${CONFIGS_FOLDER}
  tags:
    - docker
  artifacts:
135

David Mendez's avatar
David Mendez committed
136 137 138 139 140
    paths:
      - ${ENV_PROD_HX_FILE_PATH}
      - ${INGRESS_PROD_HX_FILE_PATH}
      - ${ENV_PROD_HH_FILE_PATH}
      - ${INGRESS_PROD_HH_FILE_PATH}
141

David Mendez's avatar
David Mendez committed
142

143 144 145 146 147 148 149 150 151 152 153 154 155 156
deploy-prod-hx:
  image:
    name: lachlanevenson/k8s-kubectl:latest
    entrypoint: ["/bin/sh", "-c"]
  stage: deploy
  only:
    - master
  script:
    - echo $KUBE_URL_HX
    - echo "$KUBE_CA_PEM_HX" > "$(pwd)/kube.ca.pem"
    - kubectl config set-cluster ${KUBE_CLUS_NAME_HX} --server="${KUBE_URL_HX}" --certificate-authority="$(pwd)/kube.ca.pem"
    - kubectl config set-credentials ${KUBE_USER_HX} --token="${KUBE_TOKEN_HX}"
    - kubectl config set-context ${KUBE_NAMESPACE_PROD} --cluster=${KUBE_CLUS_NAME_HX} --user=${KUBE_USER_HX}
    - kubectl config use-context ${KUBE_NAMESPACE_PROD}
David Mendez's avatar
David Mendez committed
157

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    - kubectl create secret generic ${RUN_CONFIG_SECRET_NAME_PROD_HX} --from-file=.env=${ENV_PROD_HX_FILE_PATH} -o yaml -n ${CHEMBL_NS_} --dry-run=client | kubectl apply -f -


    - cat ${CONFIG_STAGING_FILE_PATH}
    - echo ${KUBE_NAMESPACE_DEV} ${KUBE_URL_HH} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
    - kubectl get pods -n ${KUBE_NAMESPACE_DEV}
    - sed -i "s~<VERSION>~${CI_COMMIT_SHORT_SHA}~" k8s-deployment.yml
    - sed -i "s~<DOCKER_IMAGE>~${DOCKER_IMAGE}~" k8s-deployment.yml
    - sed -i "s~<HTTP_PROXY>~${HTTP_PROXY_HX}~g" k8s-deployment.yaml
    - sed -i "s~<HTTPS_PROXY>~${HTTPS_PROXY_HX}~g" k8s-deployment.yaml
    - sed -i "s~<NO_PROXY>~${NO_PROXY_HX_DEFAULT}~g" k8s-deployment.yaml
    - sed -i "s~<ENV_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_STAGING}~g" k8s-deployment.yaml
    - kubectl apply -n ${KUBE_NAMESPACE_DEV} -f k8s-deployment.yml
    - cat ${INGRESS_STAGING_FILE_PATH}
    - kubectl apply -n ${CHEMBL_NS_STAGING} -f ${INGRESS_STAGING_FILE_PATH}

  
David Mendez's avatar
David Mendez committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198

# deploy-prod-hh:
#   image:
#     name: lachlanevenson/k8s-kubectl:latest
#     entrypoint: ["/bin/sh", "-c"]
#   stage: deploy
#   script:
#     - echo $KUBE_URL_HH
#     - echo "$KUBE_CA_PEM_HH" > "$(pwd)/kube.ca.pem"
#     - kubectl config set-cluster ${KUBE_CLUS_NAME_HH} --server="${KUBE_URL_HH}" --certificate-authority="$(pwd)/kube.ca.pem"
#     - kubectl config set-credentials ${KUBE_USER_HH} --token="${KUBE_TOKEN_HH}"
#     - kubectl config set-context ${KUBE_NAMESPACE_PROD} --cluster=${KUBE_CLUS_NAME_HH} --user=${KUBE_USER_HH}
#     - kubectl config use-context ${KUBE_NAMESPACE_PROD}
#     - echo ${KUBE_NAMESPACE_DEV} ${KUBE_URL_HH} ${KUBE_CLUS_NAME_HH} ${KUBE_USER_HH}
#     - kubectl get pods -n ${KUBE_NAMESPACE_PROD}
#     - sed -i "s~<VERSION>~${CI_COMMIT_SHORT_SHA}~" k8s-deployment.yml
#     - sed -i "s~<DOCKER_IMAGE>~${DOCKER_IMAGE}~" k8s-deployment.yml
#     - kubectl apply -n ${KUBE_NAMESPACE_PROD} -f k8s-deployment.yml
#   when: manual
#   only:
#     - master

# after_script:
#   - echo "End of script"