Commit 9a76dc9c authored by Matija Obreza's avatar Matija Obreza
Browse files

Updated CI for server deployment

parent 61801497
Pipeline #1454 passed with stages
in 3 minutes and 15 seconds
variables:
IMAGE_VERSION: "1.0"
DOCKER_HOST: "genesys1.swarm.genesys-pgr.org"
ARTIFACTS: "target/www"
IMAGE_VERSION: "1.0"
DOCKER_HOST: "genesys1.swarm.genesys-pgr.org"
ARTIFACTS: "target/www"
stages:
- package
- dockerize
# - deploy
# - undeploy
- deploy
- undeploy
.package_template: &node_package
image: node:8.1-alpine
.package_template: &node_package
image: node:8.1-alpine
before_script:
- npm install
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
expire_in: 1 day
name: "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
expire_in: 1 day
paths:
- ${ARTIFACTS}
package master or tag:
<<: *node_package
stage: package
<<: *node_package
stage: package
script:
- npm run build:target
- npm run build:ssr
only:
- master
- tags
package the branch:
<<: *node_package
stage: package
when: manual
allow_failure: false
<<: *node_package
stage: package
# when: manual
allow_failure: false
script:
- npm run build:target
- npm run build:ssr
except:
- master
- tags
.docker_image_template: &docker_image
image: docker:latest
.docker_image_template: &docker_image
image: docker:latest
before_script:
- echo Building docker image ${CI_REGISTRY_IMAGE} on ${DOCKER_HOST}
- echo Registry ${CI_REGISTRY} user=${CI_REGISTRY_USER} ${CI_REGISTRY_PASSWORD}
......@@ -65,15 +65,15 @@ package the branch:
else
export IMAGE_TAG="${IMAGE_VERSION}-${CI_COMMIT_REF_SLUG}";
fi
- "echo The image tag: ${IMAGE_TAG}"
- "echo The image tag: ${IMAGE_TAG}"
- ${DOCKER_CMD} build -t ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} .
- ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
- ${DOCKER_CMD} logout $CI_REGISTRY
dockerize master or tag:
<<: *docker_image
stage: dockerize
<<: *docker_image
stage: dockerize
dependencies:
- package master or tag
only:
......@@ -81,92 +81,106 @@ dockerize master or tag:
- tags
dockerize the branch:
<<: *docker_image
stage: dockerize
<<: *docker_image
stage: dockerize
dependencies:
- package the branch
# when: manual
allow_failure: false
# when: manual
allow_failure: false
except:
- master
- tags
# deploy for review:
# stage: deploy
# image: docker:latest
# # when: manual
# allow_failure: false
# environment:
# name: review/$CI_COMMIT_REF_SLUG
# url: https://catalogui-${CI_COMMIT_REF_SLUG}.review.genesys-pgr.org
# on_stop: remove review instance
# script:
# # Address the swarm
# - export DOCKER_HOST=swarm.genesys-pgr.org
# # Configuration
# - TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
# - echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
# - echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
# - echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
# - export DOCKER_TLS_VERIFY=1
# - export DOCKER_CERT_PATH=${TLS_PATH}
# - DOCKER_CMD=docker
# # Actions
# - if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
# export IMAGE_TAG="${IMAGE_VERSION}";
# else
# export IMAGE_TAG="${IMAGE_VERSION}-${CI_COMMIT_REF_SLUG}";
# fi
# - echo Deploying ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} for review as https\://catalogui-${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
# - ${DOCKER_CMD} stack deploy -c review-composed.yml catalogui-${CI_COMMIT_REF_SLUG}-review
#
# remove review instance:
# stage: undeploy
# image: docker:latest
# when: manual
# variables:
# GIT_STRATEGY: none
# environment:
# name: review/$CI_COMMIT_REF_SLUG
# action: stop
# script:
# - echo Removing review https\://catalogui-${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
# # Address the swarm
# - export DOCKER_HOST=swarm.genesys-pgr.org
# # Configuration
# - TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
# - echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
# - echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
# - echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
# - export DOCKER_TLS_VERIFY=1
# - export DOCKER_CERT_PATH=${TLS_PATH}
# - DOCKER_CMD=docker
# # Actions
# - ${DOCKER_CMD} stack rm catalogui-${CI_COMMIT_REF_SLUG}-review
#
# deploy to production:
# stage: deploy
# image: docker:latest
# when: manual
# variables:
# GIT_STRATEGY: none
# script:
# - echo "Deploy to production server"
# # Address the swarm
# - export DOCKER_HOST=swarm.genesys-pgr.org
# # Configuration
# - TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
# - echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
# - echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
# - echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
# - export DOCKER_TLS_VERIFY=1
# - export DOCKER_CERT_PATH=${TLS_PATH}
# - DOCKER_CMD=docker
# # Actions
# - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${IMAGE_VERSION} catalog_server
# only:
# - master
# environment:
# name: production
# url: https://catalog.genesys-pgr.org
deploy for review:
stage: deploy
image: docker:latest
when: manual
allow_failure: false
environment:
name: review/$CI_COMMIT_REF_SLUG
url: https://catalogui-${CI_COMMIT_REF_SLUG}.review.genesys-pgr.org
on_stop: remove review instance
script:
# Address the swarm
- export DOCKER_HOST=swarm.genesys-pgr.org
# Configuration
- TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
- echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
- echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
- echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
- export DOCKER_TLS_VERIFY=1
- export DOCKER_CERT_PATH=${TLS_PATH}
- DOCKER_CMD=docker
# Actions
- apk add --no-cache gettext
- if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
export IMAGE_TAG="${IMAGE_VERSION}";
else
export IMAGE_TAG="${IMAGE_VERSION}-${CI_COMMIT_REF_SLUG}";
fi
- echo Deploying ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} for review as https\://catalogui-${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
- echo "Settings CLIENT_ID=${CATALOG_CLIENT_ID} CLIENT_SECRET=${CATALOG_CLIENT_SECRET} traefik.frontend.rule=Host:catalogui-${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org traefik.backend=catalogui-${CI_COMMIT_REF_SLUG}-review"
- envsubst < docker/review-compose-template.yml > review-composed.yml
- cat review-composed.yml
- ${DOCKER_CMD} stack rm catalogui-${CI_COMMIT_REF_SLUG}-review || true
- ${DOCKER_CMD} stack deploy -c review-composed.yml catalogui-${CI_COMMIT_REF_SLUG}-review
remove review instance:
stage: undeploy
image: docker:latest
when: manual
variables:
GIT_STRATEGY: none
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
script:
- echo Removing review https\://catalogui-${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
# Address the swarm
- export DOCKER_HOST=swarm.genesys-pgr.org
# Configuration
- TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
- echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
- echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
- echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
- export DOCKER_TLS_VERIFY=1
- export DOCKER_CERT_PATH=${TLS_PATH}
- DOCKER_CMD=docker
# Actions
- ${DOCKER_CMD} stack rm catalogui-${CI_COMMIT_REF_SLUG}-review || true
deploy to sandbox:
stage: deploy
image: docker:latest
only:
- master
variables:
GIT_STRATEGY: none
script:
# Address the swarm
- export DOCKER_HOST=swarm.genesys-pgr.org
# Configuration
- TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
- echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
- echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
- echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
- export DOCKER_TLS_VERIFY=1
- export DOCKER_CERT_PATH=${TLS_PATH}
- DOCKER_CMD=docker
# Actions
- apk add --no-cache gettext
- if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
export IMAGE_TAG="${IMAGE_VERSION}";
else
export IMAGE_TAG="${IMAGE_VERSION}-${CI_COMMIT_REF_SLUG}";
fi
- echo Deploying ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} for review as https\://catalogui-${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
- echo "Settings CLIENT_ID=${CATALOG_CLIENT_ID} CLIENT_SECRET=${CATALOG_CLIENT_SECRET} traefik.frontend.rule=Host:catalogui-${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org traefik.backend=catalogui-${CI_COMMIT_REF_SLUG}-review"
- envsubst < docker/review-compose-template.yml > review-composed.yml
- cat review-composed.yml
- ${DOCKER_CMD} stack rm catalogui-${CI_COMMIT_REF_SLUG}-review || true
- ${DOCKER_CMD} stack deploy -c review-composed.yml catalogui-${CI_COMMIT_REF_SLUG}-review
environment:
name: sandbox
url: https://catalogui-master.review.genesys-pgr.org
......@@ -21,4 +21,8 @@ RUN chmod +x /ssr.sh \
WORKDIR ${APP_PATH}
# Instal npm dependencies and remove package.json
RUN npm i --production \
&& rm package.json
CMD [ "/ssr.sh" ]
version: '3.1'
services:
frontend:
image: ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
environment:
- "CLIENT_ID=${CATALOG_CLIENT_ID}"
- "CLIENT_SECRET=${CATALOG_CLIENT_SECRET}"
- "CATALOG_API_URL=https://catalog-master.review.genesys-pgr.org"
networks:
- traefik-net
deploy:
replicas: 1
labels:
- traefik.port=3000
- traefik.docker.network=traefik-net
- traefik.frontend.rule=Host:catalogui-${CI_COMMIT_REF_SLUG}.review.genesys-pgr.org
resources:
limits:
memory: 50m
cpus: '2'
reservations:
memory: 50m
cpus: '0.01'
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 2
window: 120s
networks:
traefik-net:
external: true
......@@ -20,13 +20,12 @@
"scripts": {
"toolbox": "react-toolbox-themr",
"clean": "gulp clean",
"ssr": "gulp clean:all; gulp build:ssr; webpack --config config/webpack-development.config.js; node target/www/index.js",
"build": "webpack --config config/webpack-development.config.js",
"build:production": "cross-env NODE_ENV=production webpack --config config/webpack-production.config.js",
"build:ssr": "gulp clean:all; gulp build:prod; npm run build:production",
"server": "webpack-dev-server --config config/webpack-development.config.js",
"server:production": "cross-env NODE_ENV=production webpack-dev-server --config config/webpack-production.config.js",
"build:production": "cross-env NODE_ENV=production webpack --config config/webpack-production.config.js",
"build:target": "gulp clean:all; gulp build:prod; cross-env NODE_ENV=production webpack --config config/webpack-production.config.js"
"server:ssr": "gulp clean:all; gulp build:ssr; npm run build; node target/www/index.js"
},
"reactToolbox": {
"output": "src/main/react/assets"
......
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