# CI/CD Pipeline # dev branch -> staging # master branch -> internal (Custom Downloads) # 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:14.16.0 before_script: - cd src/ensembl - npm install --global npm@7.7.4 - 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/ensembl-web/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 WP k8s cluster .deploy-wp-feature: stage: deploy image: dockerhub.ebi.ac.uk/ensembl-web/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 deployfeature - sed -i "s##${CI_COMMIT_REF_SLUG}#g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml - sed -i "s##${CONTAINER_IMAGE}#g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml - sed -i "s##${CI_COMMIT_REF_SLUG}#g" ensembl-client-caas-deploy/ensembl_client_service_node.yaml - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_deployment.yaml - kubectl apply -f ensembl-client-caas-deploy/ensembl_client_service_node.yaml # Template to deploy review-app to WP k8s cluster .deploy-wp-review: stage: deploy image: dockerhub.ebi.ac.uk/ensembl-web/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 wp-review-apps - sed -i "s##${CI_COMMIT_REF_SLUG}#g" ensembl-client-caas-deploy/ensembl_client_deployment.yaml - 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 for stopping review app - Do cleanup here .stop-wp-review: stage: deploy image: dockerhub.ebi.ac.uk/ensembl-web/deploy-tools:0.1 variables: GIT_STRATEGY: none when: manual script: - kubectl delete ingress ensembl-client-${CI_COMMIT_REF_SLUG}-ingress - kubectl delete svc ensembl-client-${CI_COMMIT_REF_SLUG}-svc - kubectl delete deploy ensembl-client-${CI_COMMIT_REF_SLUG}-deployment # Template to deploy to EHK k8s cluster .deploy-ehk: stage: deploy image: dockerhub.ebi.ac.uk/ensembl-web/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:14.16.0 stage: test before_script: - cd src/ensembl - npm ci script: - npm run check-types - npm run test only: - /^nodeploy\/.*$/ except: - dev - master # 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 # master 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: - master Test_N_Build:review: extends: .build-static variables: ENVIRONMENT: development API_HOST: "" except: - dev - master - /^nodeploy\/.*$/ # 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 # master branch -> internal Nginx:Internal-EHK: extends: .build-nginx-ehk variables: DEPLOYENV: internal CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-internal only: - master needs: - Test_N_Build:internal # Job to build nginx docker image for staging and internal environment at WP # master branch -> internal Nginx:Internal-WP: extends: .build-nginx-wp variables: DEPLOYENV: internal CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-internal-ing only: - master needs: - Test_N_Build:internal Nginx:review: extends: .build-nginx-wp variables: DEPLOYENV: dev CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_REF_SLUG} except: - dev - master - /^nodeploy\/.*$/ needs: - Test_N_Build:review # 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: - Test_N_Build - Nginx:Staging-WP # Job to deploy to staging environment (WP-HH k8s cluster) Staging:WP-HH: extends: .deploy-wp variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-stage-ing environment: name : wp-hh-staging only: - dev needs: - Test_N_Build - 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 live environment (WP-HX k8s cluster) Live:WP-HX: extends: .deploy-wp variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-prod-ing environment: name : wp-hx-live only: - master needs: - Test_N_Build - Nginx:Live-WP # Job to deploy to live environment (WP-HH k8s cluster) Live:WP-HH: extends: .deploy-wp variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-prod-ing environment: name : wp-hh-live only: - master needs: - Test_N_Build - Nginx:Live-WP # 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: - master needs: - Test_N_Build:internal - Nginx:Internal-EHK # Job to deploy to internal environment (WP-HX k8s cluster) Internal:WP-HX: extends: .deploy-wp variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-internal-ing environment: name : wp-hx-internal only: - master needs: - Test_N_Build:internal - Nginx:Internal-WP # Job to deploy to internal environment (WP-HH k8s cluster) Internal:WP-HH: extends: .deploy-wp variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-internal-ing environment: name : wp-hh-internal only: - master needs: - Test_N_Build:internal - Nginx:Internal-WP Feature:EHK-HH: extends: .deploy-ehk variables: DEPLOYENV: ${CI_COMMIT_REF_SLUG} CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_REF_SLUG} KUBE_CONTEXT: ens-dev-ctx except: - dev - master - /^nodeploy\/.*$/ needs: - Test_N_Build:review - Nginx:review Review:WP-HX: extends: .deploy-wp-review variables: CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_REF_SLUG} environment: name: review/$CI_COMMIT_REF_SLUG url: http://$CI_COMMIT_REF_SLUG.review.ensembl.org on_stop: stop_review kubernetes: namespace: ensembl-dev except: - dev - master - /^nodeploy\/.*$/ needs: - Test_N_Build:review - Nginx:review stop_review: extends: .stop-wp-review environment: name: review/$CI_COMMIT_REF_SLUG action: stop kubernetes: namespace: ensembl-dev except: - dev - master - /^nodeploy\/.*$/