Commit 6ef59493 authored by Matija Obreza's avatar Matija Obreza
Browse files

Build and deploy Genesys

parent 5807a435
image: maven:3-jdk-8
variables:
GENESYS_VERSION: "2.0"
DOCKER_HOST: "genesys1.swarm.genesys-pgr.org"
build:
script: "mvn install -B"
stages:
- package
- dockerize
- deploy
package genesys:
stage: package
image: dockerhub.genesys-pgr.org/maven-with-compass:3-jdk-8
script:
# - echo "Project name ${CI_PROJECT_NAME} commit slug=${CI_COMMIT_REF_SLUG} ref=${CI_COMMIT_REF_NAME}"
# - echo "Project namespace ${CI_PROJECT_NAMESPACE}"
- MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn package -B -DskipTests=true
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
expire_in: 1 day
paths:
- target/*.jar
- target/*.war
docker image:
stage: dockerize
image: docker:latest
dependencies:
- package genesys
before_script:
- echo Building docker image ${CI_REGISTRY_IMAGE} on ${DOCKER_HOST}
- echo Registry ${CI_REGISTRY} user=${CI_REGISTRY_USER} ${CI_REGISTRY_PASSWORD}
script:
# 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 --tlsverify=false"
# - ls -la ${DOCKER_CERT_PATH}
# - set | grep DOCKER
# Actions
- cp target/*.war docker
- cd docker
- if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
TAG=${GENESYS_VERSION};
else
TAG=${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG};
fi
- "echo The image tag: ${TAG}"
- ${DOCKER_CMD} build -t ${CI_REGISTRY_IMAGE}:${TAG} .
- ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${TAG}
- ${DOCKER_CMD} logout $CI_REGISTRY
deploy for review:
stage: deploy
image: docker:latest
when: manual
dependencies:
- docker image
environment:
name: review/$CI_COMMIT_REF_SLUG
url: https://${CI_COMMIT_REF_SLUG}.review.genesys-pgr.org
on_stop: remove review instance
script:
- echo Deploying for review as https\://${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
- apk add --no-cache gettext
- envsubst < docker/review-compose-template.yml > review-composed.yml
- cat review-composed.yml
- ${DOCKER_CMD} stack deploy -c review-composed.yml genesys-${CI_COMMIT_REF_SLUG}
remove review instance:
stage: deploy
image: docker:latest
when: manual
variables:
GIT_STRATEGY: none
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
script:
- echo Removing review 'https\://${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 genesys-${CI_COMMIT_REF_SLUG}
deploy on staging server:
stage: deploy
image: docker:latest
variables:
GIT_STRATEGY: none
script:
- echo "Deploying on staging server"
only:
- staging
environment:
name: sandbox
url: https://sandbox.genesys-pgr.org
deploy to production:
stage: deploy
image: docker:latest
when: manual
variables:
GIT_STRATEGY: none
script:
- echo "Deploy to production server"
only:
- master
environment:
name: production
url: https://www.genesys-pgr.org
......@@ -5,10 +5,10 @@ FROM jetty:9.4-alpine
LABEL maintainer "Matija Obreza <matija.obreza@croptrust.org>"
ENV USER=jetty
ENV GENESYS_DATA=/data/genesys
ENV JETTY_BASE=/var/lib/jetty/
ENV GENESYS_WAR='https://jenkins.demo.genesys-pgr.org/job/genesys-server/lastStableBuild/org.genesys-pgr$genesys2-server/artifact/org.genesys-pgr/genesys2-server/2.0/genesys2-server-2.0.war'
ENV USER=jetty \
GENESYS_DATA=/data/genesys \
JETTY_BASE=/var/lib/jetty/ \
GENESYS_WAR='genesys2-server*war'
WORKDIR ${JETTY_BASE}
......@@ -19,13 +19,13 @@ RUN mkdir -p $GENESYS_DATA \
COPY webapps ${JETTY_BASE}/webapps
# RUN echo "Downloading ${GENESYS_WAR}"
ADD ${GENESYS_WAR} ${JETTY_BASE}/webapps/genesys2-server.war
COPY ${GENESYS_WAR} ${JETTY_BASE}/webapps/genesys2-server.war
# RUN echo 'Copying genesys.properties to ' ${JETTY_BASE}
COPY genesys.properties ${JETTY_BASE}/resources/genesys.properties
# list image contents
RUN chmod go+r ${JETTY_BASE}/webapps/genesys2-server.war \
&& find ${JETTY_BASE} -exec ls -la {} \;
&& find ${JETTY_BASE} -type f -exec ls -la {} \;
VOLUME /data/genesys
version: '3.1'
services:
genesys:
image: ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}
environment:
- spring.profiles.active=dev
- JAVA_OPTIONS=-Xms1800M -Xmx2800M -server -Dnetworkaddress.cache.ttl=10
- base.host=${CI_COMMIT_REF_SLUG}.review.genesys-pgr.org
- robots.allow=false
- db.url=jdbc:hsqldb:mem:genesys;sql.syntax_mys=true
- db.driverClassName=org.hsqldb.jdbc.JDBCDriver
- db.username=sa
- db.password=
- db.showSql=false
- db.hbm2ddl=true
- auto.createContent=true
- hibernate.dialect=org.hibernate.dialect.HSQLDialect
- base.cookie-secure=true
networks:
- traefik-net
deploy:
replicas: 1
labels:
- app=genesys-review
- traefik.port=8080
- traefik.docker.network=traefik-net
- traefik.frontend.rule=Host:${CI_COMMIT_REF_SLUG}.review.genesys-pgr.org
resources:
limits:
memory: 3g
cpus: '2'
reservations:
memory: 2g
cpus: '0.01'
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 2
window: 120s
networks:
traefik-net:
external: true
......@@ -50,10 +50,6 @@
<url>https://bitbucket.org/genesys2/genesys2-server/issues</url>
</issueManagement>
<prerequisites>
<maven>3.1.0</maven>
</prerequisites>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.target>1.8</jdk.target>
......
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