# CI/CD Pipeline # dev branch -> staging # dev branch -> internal (Custom Downloads + Entity Viewer) # master branch -> live # Define stages for the CI/CD pipeline stages: - test - test_build_static - build_docker_images - deploy variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} KUBE_CONTEXT: ens-dev-ctx DEPLOYENV: dev ENVIRONMENT: production DOCKER_TLS_CERTDIR: "" # Template to build static assets .build-static: stage: test_build_static image: node:12.13.0 before_script: - cd src/ensembl - npm ci script: - npm run test - npm run build artifacts: name: static_assets paths: - src/ensembl/dist/ # Template to build nginx docker image for WP k8s cluster # WP k8s cluster uses ingress .build-nginx-wp: image: docker services: - docker:dind stage: build_docker_images before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - apk update && apk add git - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git - git -C ensembl-client-nginx checkout migration/wp-hx/ingress - docker build -t ${CONTAINER_IMAGE} -f ensembl-client-nginx/Dockerfile --no-cache . - docker push ${CONTAINER_IMAGE} - docker rmi ${CONTAINER_IMAGE} - docker logout $CI_REGISTRY # Template to build nginx docker image for EHK k8s cluster .build-nginx-ehk: image: docker services: - docker:dind stage: build_docker_images before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - apk update && apk add git - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git - sed -i "s//${DEPLOYENV}/g" ensembl-client-nginx/config/conf.d/local.conf - docker build -t ${CONTAINER_IMAGE} -f ensembl-client-nginx/Dockerfile --no-cache . - docker push ${CONTAINER_IMAGE} - docker rmi ${CONTAINER_IMAGE} - docker logout "$CI_REGISTRY" needs: ["Test_N_Build"] # Template to deploy to WP k8s cluster .deploy-wp: stage: deploy image: dockerhub.ebi.ac.uk/kamal/deploy-tools:0.1 script: - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git - git -C ensembl-client-caas-deploy/ checkout migration/wp-hx - sed -i "s##${CONTAINER_IMAGE}#g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml # Template to deploy to EHK k8s cluster .deploy-ehk: stage: deploy image: dockerhub.ebi.ac.uk/kamal/deploy-tools:0.1 before_script: - export KUBECONFIG=/etc/deploy/config - mkdir -p /etc/deploy - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG} script: - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git - git -C ensembl-client-caas-deploy checkout refactor-manifest - sed -i "s//${CI_COMMIT_SHORT_SHA}-${DEPLOYENV}/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml - sed -i "s//${DEPLOYENV}/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml - kubectl config use-context ${KUBE_CONTEXT} - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml Test: image: node:12.13.0 stage: test before_script: - cd src/ensembl - npm ci script: - npm run check-types - npm run test except: - dev - master - /^feature\/.*$/ - /^migration\/.*$/ # Job to build static asset for staging and live environment # dev branch -> Staging # master branch -> Live Test_N_Build: extends: .build-static variables: GOOGLE_ANALYTICS_KEY: ${GA_KEY} ENVIRONMENT: production API_HOST: "" script: - npm run test - npm run build only: - dev - master # Job to build static asset for internal environment # dev branch -> Internal Test_N_Build:internal: extends: .build-static variables: GOOGLE_ANALYTICS_KEY: ${GA_KEY} ENVIRONMENT: internal API_HOST: "" artifacts: name: static_assets paths: - src/ensembl/dist/ only: - dev Test_N_Build:feature: image: node:12.13.0 stage: test_build_static before_script: - cd src/ensembl - npm ci script: - npm run test - export NODE_ENV=development - export GOOGLE_ANALYTICS_KEY=${GA_KEY} - export ENVIRONMENT=development - export API_HOST="" - npm run build artifacts: name: static_assets_feature paths: - src/ensembl/dist/ only: - /^feature\/.*$/ # Job to build nginx docker image for staging environment (EHK k8s cluster) Nginx:Staging-EHK: extends: .build-nginx-ehk variables: DEPLOYENV: staging CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-staging only: - dev # Job to build nginx docker image for live environment (EHK k8s cluster) Nginx:Live-EHK: extends: .build-nginx-ehk variables: DEPLOYENV: prod CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-prod only: - master # Job to build nginx docker image for staging environment # dev branch -> Staging Nginx:Staging-WP: extends: .build-nginx-wp variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-stage-ing only: - dev needs: ["Test_N_Build"] # Job to build nginx docker image for live environment # master branch -> Live Nginx:Live-WP: extends: .build-nginx-wp variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-prod-ing only: - master needs: ["Test_N_Build"] # Job to build nginx docker image for staging and internal environment # dev branch -> internal Nginx:Internal-EHK: extends: .build-nginx-ehk variables: DEPLOYENV: internal CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-internal only: - dev needs: ["Test_N_Build:internal"] Nginx:feature: image: docker services: - docker:dind stage: build_docker_images before_script: - case "${CI_COMMIT_REF_NAME}" in dev) DEPLOYENV="staging" ;; master) DEPLOYENV="prod" ;; cicd-test) DEPLOYENV="staging" ;; *) DEPLOYENV="dev" ;; esac script: - feature_branch=${CI_COMMIT_REF_NAME} - feature_tag=${feature_branch#"feature/"} - feature_tag=`echo "${feature_tag}" | tr '[A-Z]' '[a-z]'` - apk update && apk add git - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git - sed -i "s//internal/g" ensembl-client-nginx/config/conf.d/local.conf - cat ensembl-client-nginx/config/conf.d/local.conf - docker build -t ${CONTAINER_IMAGE}-$feature_tag -f ensembl-client-nginx/Dockerfile --no-cache . - echo "$GITLAB_REGISTRY_TOKEN" | docker login -u "$GITLAB_REGISTRY_USER" --password-stdin https://"$GITLAB_REGISTRY_URL" - docker push ${CONTAINER_IMAGE}-$feature_tag - docker rmi ${CONTAINER_IMAGE}-$feature_tag - docker logout "$GITLAB_REGISTRY_URL" only: - /^feature\/.*$/ dependencies: - Test_N_Build:feature # Job to deploy to staging environment (EHK k8s cluster) Staging:EHK-HH: extends: .deploy-ehk variables: DEPLOYENV: staging CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-staging KUBE_CONTEXT: ens-stage-ctx only: - dev needs: ["Nginx:Staging-EHK"] # Job to deploy to staging environment (WP-HX k8s cluster) Staging:WP-HX: extends: .deploy-wp variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-stage-ing environment: name : wp-hx-staging only: - dev needs: ["Nginx:Staging-WP"] # Job to deploy to live environment (EHK k8s cluster) Live:EHK-HH: extends: .deploy-ehk variables: DEPLOYENV: prod CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-prod KUBE_CONTEXT: ens-prod-ctx only: - master needs: ["Nginx:Live-EHK"] # Job to deploy to internal environment (EHK k8s cluster) Internal:EHK-HH: extends: .deploy-ehk variables: DEPLOYENV: internal CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-internal KUBE_CONTEXT: ens-dev-ctx only: - dev needs: ["Nginx:Internal-EHK"] Feature:EHK-HH: stage: deploy image: alpine before_script: - export KUBECONFIG=/etc/deploy/config - mkdir -p /etc/deploy - echo ${EMBASSY_KUBECONFIG} | base64 -d > ${KUBECONFIG} script: - feature_branch=${CI_COMMIT_REF_NAME} - feature_tag=${feature_branch#"feature/"} - apk update && apk add --no-cache curl git - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl - chmod +x ./kubectl - mv ./kubectl /usr/local/bin/kubectl - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-caas-deploy.git - cd ensembl-client-caas-deploy - git checkout refactor-manifest - cd .. - sed -i "s//${CI_COMMIT_SHORT_SHA}-$feature_tag/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml - sed -i "s//$feature_tag/g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml - cat ensembl-client-caas-deploy/ensembl_client_deployment.yaml - kubectl config view - kubectl config use-context ens-dev-ctx - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml only: - /^feature\/.*$/ dependencies: - Nginx:feature