Commit 9aa02ab2 authored by David Mendez's avatar David Mendez
Browse files

Merge branch 'staging' into 'master'

Start to add CI script for deployment

See merge request !1
parents 7f18d1a1 f5a836a0
variables:
DOCKER_TLS_CERTDIR: ""
GIT_STRATEGY: clone
REGISTRY_USER: chembl/unichem
APPLICATION: malaria-frontend
REGISTRY_USER: chembl/research
APPLICATION: lina-web
SERVER_IMAGE_TAG: ${CI_REGISTRY}/${REGISTRY_USER}/${APPLICATION}:${CI_COMMIT_SHORT_SHA}
RELEASE_IMAGE: $CI_REGISTRY/$REGISTRY_USER/$APPLICATION:$CI_BUILD_REF_NAME
DOCKER_IMAGE: $CI_REGISTRY/$REGISTRY_USER/$APPLICATION
DOCKER_DRIVER: overlay
image: docker:latest
services:
- docker:dind
CONFIGS_FOLDER: run_config
# Config staging
ENV_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/staging/.env
INGRESS_STAGING_FILE_PATH: ${CONFIGS_FOLDER}/staging/ingress.yml
# 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
stages:
- build
# - test
# - deploy
- test
- prepare_config
- deploy
build-dev:
build:
image:
name: docker/compose:1.25.5
entrypoint: ["/bin/sh", "-c"]
stage: build
only:
- staging
services:
- docker:dind
tags:
- dind
variables:
DOCKER_HOST: tcp://docker:2375
script:
- echo 'hello!'
# build-dev:
# image:
# name: docker/compose:1.25.5
# entrypoint: ["/bin/sh", "-c"]
# stage: build
# only:
# - dev
# # - 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 development
# - echo Deploying ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
# - docker push ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- echo Building ${SERVER_IMAGE_TAG}
- echo building ${SERVER_IMAGE_TAG}
- docker build --tag ${SERVER_IMAGE_TAG} .
- docker push ${SERVER_IMAGE_TAG}
# build-prod:
# image:
......@@ -54,75 +61,117 @@ build-dev:
# - echo Deploying ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
# - docker push ${DOCKER_IMAGE}:${CI_COMMIT_SHORT_SHA}
# unit-tests:
# stage: test
# when: manual
# script:
# - echo "ToDo UNIT TESTS"
# only:
# - master
# - dev
unit-tests:
stage: test
script:
- echo "ToDo UNIT TESTS"
# deploy-dev-hx:
# image:
# name: lachlanevenson/k8s-kubectl:latest
# entrypoint: ["/bin/sh", "-c"]
# stage: deploy
# 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_DEV} --cluster=${KUBE_CLUS_NAME_HX} --user=${KUBE_USER_HX}
# - kubectl config use-context ${KUBE_NAMESPACE_DEV}
# - 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
# - kubectl apply -n ${KUBE_NAMESPACE_DEV} -f k8s-deployment.yml
# only:
# - dev
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:
- ${ENV_STAGING_FILE_PATH}
- ${INGRESS_STAGING_FILE_PATH}
deploy-staging:
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
only:
- staging
stage: deploy
script:
- set -x
- 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 ${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}
- kubectl create secret generic ${RUN_CONFIG_SECRET_NAME_STAGING} --from-file=.env=${ENV_STAGING_FILE_PATH} -o yaml -n ${CHEMBL_NS_STAGING} --dry-run=client | kubectl replace -f -
- cat ${ENV_STAGING_FILE_PATH}
- echo ${CHEMBL_NS_STAGING} ${KUBE_URL_HX} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
- kubectl get pods -n ${CHEMBL_NS_STAGING}
- sed -i "s~<SERVER_IMAGE_TAG>~${SERVER_IMAGE_TAG}~" k8s-deployment.yml
- sed -i "s~<HTTP_PROXY>~${HTTP_PROXY_HX}~g" k8s-deployment.yml
- sed -i "s~<HTTPS_PROXY>~${HTTPS_PROXY_HX}~g" k8s-deployment.yml
- sed -i "s~<NO_PROXY>~${NO_PROXY_HX_DEFAULT}~g" k8s-deployment.yml
- sed -i "s~<ENV_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_STAGING}~g" k8s-deployment.yml
- cat k8s-deployment.yml
- kubectl apply -n ${CHEMBL_NS_STAGING} -f k8s-deployment.yml
- cat ${INGRESS_STAGING_FILE_PATH}
- kubectl apply -n ${CHEMBL_NS_STAGING} -f ${INGRESS_STAGING_FILE_PATH}
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:
paths:
- ${ENV_PROD_HX_FILE_PATH}
- ${INGRESS_PROD_HX_FILE_PATH}
- ${ENV_PROD_HH_FILE_PATH}
- ${INGRESS_PROD_HH_FILE_PATH}
deploy-prod-hx:
image:
name: lachlanevenson/k8s-kubectl:latest
entrypoint: ["/bin/sh", "-c"]
stage: deploy
only:
- master
script:
- set -x
- 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 ${CHEMBL_NS_PROD} --cluster=${KUBE_CLUS_NAME_HX} --user=${KUBE_USER_HX}
- kubectl config use-context ${CHEMBL_NS_PROD}
- echo ${CHEMBL_NS_PROD} ${KUBE_URL_HX} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
- kubectl get pods -n ${CHEMBL_NS_PROD}
- kubectl create secret generic ${RUN_CONFIG_SECRET_NAME_PROD_HX} --from-file=.env=${ENV_PROD_HX_FILE_PATH} -o yaml -n ${CHEMBL_NS_PROD} --dry-run=client | kubectl apply -f -
- cat ${ENV_PROD_HX_FILE_PATH}
- echo ${CHEMBL_NS_PROD} ${KUBE_URL_HX} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
- kubectl get pods -n ${CHEMBL_NS_PROD}
- sed -i "s~<SERVER_IMAGE_TAG>~${SERVER_IMAGE_TAG}~" k8s-deployment.yml
- sed -i "s~<HTTP_PROXY>~${HTTP_PROXY_HX}~g" k8s-deployment.yml
- sed -i "s~<HTTPS_PROXY>~${HTTPS_PROXY_HX}~g" k8s-deployment.yml
- sed -i "s~<NO_PROXY>~${NO_PROXY_HX_DEFAULT}~g" k8s-deployment.yml
- sed -i "s~<ENV_SECRET_NAME>~${RUN_CONFIG_SECRET_NAME_PROD_HX}~g" k8s-deployment.yml
- cat k8s-deployment.yml
- kubectl apply -n ${CHEMBL_NS_PROD} -f k8s-deployment.yml
- cat ${INGRESS_PROD_HX_FILE_PATH}
- kubectl apply -n ${CHEMBL_NS_PROD} -f ${INGRESS_PROD_HX_FILE_PATH}
# deploy-dev-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_DEV} --cluster=${KUBE_CLUS_NAME_HH} --user=${KUBE_USER_HH}
# - kubectl config use-context ${KUBE_NAMESPACE_DEV}
# - echo ${KUBE_NAMESPACE_DEV} ${KUBE_URL_HH} ${KUBE_CLUS_NAME_HH} ${KUBE_USER_HH}
# - 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
# - kubectl apply -n ${KUBE_NAMESPACE_DEV} -f k8s-deployment.yml
# only:
# - dev
# deploy-prod-hx:
# image:
# name: lachlanevenson/k8s-kubectl:latest
# entrypoint: ["/bin/sh", "-c"]
# stage: deploy
# 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}
# - echo ${KUBE_NAMESPACE_DEV} ${KUBE_URL_HX} ${KUBE_CLUS_NAME_HX} ${KUBE_USER_HX}
# - 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
# deploy-prod-hh:
# image:
......
FROM node:lts
ENV ENV_FILE_PATH=${ENV_FILE_PATH:-'/etc/run_config/.env'}
LABEL maintainer="heinzke@ebi.ac.uk"
......@@ -16,10 +17,10 @@ COPY . $APP_SOURCE
ARG DELAYED_JOBS_API
ENV DELAYED_JOBS_API $DELAYED_JOBS_API
RUN npm install && npm run build
RUN npm install
ENV HOST 0.0.0.0
EXPOSE 3000
ENTRYPOINT [ "npm", "start" ]
ENTRYPOINT ENV_FILE_PATH=${ENV_FILE_PATH} npm run build && npm start
apiVersion: apps/v1
kind: Deployment
metadata:
name: malaria-front
name: lina-web
labels:
app: malaria-front
app: lina-web
spec:
selector:
matchLabels:
app: malaria-front
app: lina-web
role: master
tier: frontend
replicas: 2
template:
metadata:
labels:
app: malaria-front
app: lina-web
role: master
tier: frontend
spec:
containers:
- name: malaria-front
image: <DOCKER_IMAGE>:<VERSION>
- name: lina-web
image: <SERVER_IMAGE_TAG>
imagePullPolicy: Always
ports:
- containerPort: 3000
imagePullSecrets:
- name: malaria-frontend-registry
volumeMounts:
- name: run-config
mountPath: '/etc/run_config/'
readOnly: true
env:
- name: HTTP_PROXY
value: "<HTTP_PROXY>"
- name: http_proxy
value: "<HTTP_PROXY>"
- name: HTTPS_PROXY
value: "<HTTPS_PROXY>"
- name: https_proxy
value: "<HTTPS_PROXY>"
- name: NO_PROXY
value: "<NO_PROXY>"
- name: no_proxy
value: "<NO_PROXY>"
volumes:
- name: run-config
secret:
secretName: <ENV_SECRET_NAME>
---
apiVersion: v1
kind: Service
metadata:
name: malaria-front
name: lina-web
spec:
selector:
app: malaria-front
app: lina-web
ports:
- protocol: TCP
port: 3000
......
require('dotenv').config({ path: process.env.ENV_FILE_PATH })
export default {
mode: 'universal',
router: {
base: '/chembl/lina-web'
base: '/chembl/lina_web'
},
env: {
baseUrl: process.env.BASE_URL || 'http://localhost:3000',
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment