Newer
Older
include:
# https://docs.gitlab.com/ce/ci/yaml/README.html#workflowrules-templates
- template: 'Workflows/Branch-Pipelines.gitlab-ci.yml'
VERSION: "2022.9"
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
# MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
MAVEN_CLI_OPTS: "--batch-mode --errors --show-version --settings .ci-maven-settings.xml"
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
paths:
- .m2/repository
stages:
stage: test
image: maven:3-openjdk-11
- mvn $MAVEN_CLI_OPTS --activate-profiles quality clean verify -U
- cat coverage/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%'
coverage: '/Total.*?([0-9]{1,3})%/'
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
expire_in: 1 day
paths:
- coverage/target/site/jacoco-aggregate
junit:
- commons/target/surefire-reports/TEST-*.xml
- server/target/surefire-reports/TEST-*.xml
# - client/target/surefire-reports/TEST-*.xml
stage: package
image: maven:3-openjdk-11
dependencies:
- run tests
script:
# Then package the clean app
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
expire_in: 1 day
paths:
# - commons/target/*.jar
- server/target/*.war
# - client/target/*.jar
pages:
stage: deploy
dependencies:
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- mv coverage/target/site/jacoco-aggregate/* public
artifacts:
expire_in: 1 days
paths:
- public
image: docker:${DOCKER_VERSION}
before_script:
- if [ "${CI_COMMIT_REF_SLUG}" = "${CI_DEFAULT_BRANCH}" ] ; then
export IMAGE_TAG="${VERSION}-edge";
else
if echo "${CI_COMMIT_TAG}" | grep -Eq 'v\d+.*'; then
export IMAGE_TAG=${CI_COMMIT_TAG:1};
else
export IMAGE_TAG="${VERSION}-${CI_COMMIT_REF_SLUG}";
fi
fi
stage: dockerize
dependencies:
- package server
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: '$CI_COMMIT_TAG'
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: manual
allow_failure: true
- echo "Building docker image ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}"
- cp target/*.war docker
- cd docker
- "echo Building image: ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}"
- DOCKER_BUILDKIT=1 ${DOCKER_CMD} build --target=jetty --progress=plain -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}
- if [[ "$CI_COMMIT_TAG" =~ ^v[0-9]+.*$ ]]; then
echo "Tagging ${CI_REGISTRY_IMAGE}:${VERSION}";
${DOCKER_CMD} tag ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} ${CI_REGISTRY_IMAGE}:${VERSION};
${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${VERSION};
else
echo "Skipping :${VERSION} tag for ${CI_COMMIT_TAG}, not matching 'v0.0.0'";
fi
- ${DOCKER_CMD} logout $CI_REGISTRY
when: manual
allow_failure: true
- "echo Tagging: ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} as ${CI_REGISTRY_IMAGE}:latest"
- ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- ${DOCKER_CMD} pull ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
- echo "Tagging ${CI_REGISTRY_IMAGE}:latest"
- ${DOCKER_CMD} tag ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} ${CI_REGISTRY_IMAGE}:latest
- ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:latest
- ${DOCKER_CMD} logout $CI_REGISTRY
tag edge image:
stage: tag
image: docker:${DOCKER_VERSION}
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
allow_failure: true
<<: *docker_setup
script:
# IMAGE_TAG is VERSION-edge for main branch
- "echo Tagging: ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} as ${CI_REGISTRY_IMAGE}:edge"
- ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- ${DOCKER_CMD} pull ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
- ${DOCKER_CMD} tag ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} ${CI_REGISTRY_IMAGE}:edge
- ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:edge
- ${DOCKER_CMD} logout $CI_REGISTRY
.docker_deploy_setup: &docker_deploy_setup
image: docker:${DOCKER_VERSION}
before_script:
- if [ "${CI_COMMIT_REF_SLUG}" = "${CI_DEFAULT_BRANCH}" ] ; then
export IMAGE_TAG="${VERSION}-edge";
else
if echo "${CI_COMMIT_TAG}" | grep -Eq 'v\d+.*'; then
export IMAGE_TAG=${CI_COMMIT_TAG:1};
else
export IMAGE_TAG="${VERSION}-${CI_COMMIT_REF_SLUG}";
fi
fi
# Address the swarm
- export DOCKER_HOST=swarm.genesys-pgr.org
- 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_CERT_PATH=${TLS_PATH}
- DOCKER_CMD="docker --tlsverify=false"
deploy branch to staging.ggceapi.genesys-pgr.org:
stage: deploy
variables:
GIT_STRATEGY: none
dependencies:
- dockerize server
rules:
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: manual
allow_failure: true
script:
- echo "Deploying ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} to https://staging.ggceapi.genesys-pgr.org"
- ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} ggce-staging_api
environment:
url: https://staging.ggceapi.genesys-pgr.org

Matija Obreza
committed
deploy to staging.ggceapi.genesys-pgr.org:
variables:
GIT_STRATEGY: none
dependencies:
- tag edge image
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
allow_failure: true
script:

Matija Obreza
committed
- echo "Deploying ${CI_REGISTRY_IMAGE}:edge to https://staging.ggceapi.genesys-pgr.org"
- ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:edge ggce-staging_api

Matija Obreza
committed
url: https://staging.ggceapi.genesys-pgr.org
# deploy to demo.ggceapi.genesys-pgr.org:
# stage: deploy

Matija Obreza
committed
# variables:
# GIT_STRATEGY: none
# dependencies:
# - tag edge image
# rules:
# - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
# when: manual # Manually update Demo
# allow_failure: true
# script:
# - echo "Deploying ${CI_REGISTRY_IMAGE}:edge to https://demo.ggceapi.genesys-pgr.org"
# - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:edge ggce-demo_api
# environment:

Matija Obreza
committed
# url: https://demo.ggceapi.genesys-pgr.org