Commit 1225338d authored by LAVENIER's avatar LAVENIER
Browse files

[fix] CI: fix yaml

parent 86538557
......@@ -236,41 +236,41 @@ gitlab-release:
script:
# Create the target directory
- mkdir -p target/docker/config
#- cp -rf ${APP_WAR_MODULE}/src/main/docker/* target/docker/
- cp -rf ${APP_WAR_MODULE}/src/main/docker/* target/docker/
- cp -f ${ARTIFACT_WAR_FILE} target/docker/app.war
- cp -f ${ARTIFACT_CONFIG_FILES} target/docker/config/
- ls -l target/docker/config
- cd target/docker
# Create the starter script
- echo '#!/bin/bash' > app.sh
- echo 'BASEDIR=/app' >> app.sh
- echo 'JAVA_OPTS="-Dsumaris.basedir=${BASEDIR}"' >> app.sh
- echo 'JAVA_OPTS="$JAVA_OPTS -Dspring.config.location=${BASEDIR}/config/"' >> app.sh
- echo 'JAVA_OPTS="$JAVA_OPTS -Doracle.net.tns_admin=/home/tnsnames' >> app.sh
- echo 'JAVA_OPTS="$JAVA_OPTS -Doracle.jdbc.timezoneAsRegion=false"' >> app.sh
- echo '[[ "_${PROFILES}" != "_" ]] && JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=${PROFILES}"' >> app.sh
- echo '[[ "_${TZ}" != "_" ]] && JAVA_OPTS="$JAVA_OPTS -Duser.timezone=${TZ}"' >> app.sh
- echo '[[ "_${PORT}" != "_" ]] && JAVA_OPTS="$JAVA_OPTS -Dserver.port=${PORT}"' >> app.sh
- echo 'ARGS=${@:2}' >> app.sh
- echo 'java ${JAVA_OPTS} -server -jar ${BASEDIR}/app.war ${ARGS}' >> app.sh
# Create the Dockerfile
- echo 'FROM openjdk:11-jre' > Dockerfile
- echo "ARG WAR_FILE=app.war" >> Dockerfile
- echo "ARG CONFIG_FILES=config/*.properties" >> Dockerfile
- echo 'RUN apt-get update && apt-get -y install libsodium-dev' >> Dockerfile
- echo 'RUN addgroup -S spring && adduser -S spring -G spring' >> Dockerfile
- echo 'USER spring:spring' >> Dockerfile
- echo 'WORKDIR /app' >> Dockerfile
- echo 'COPY app.sh app.sh' >> Dockerfile
- echo 'RUN chmod +x app.sh' >> Dockerfile
- echo 'COPY ${WAR_FILE} app.war' >> Dockerfile
- echo 'RUN mkdir config' >> Dockerfile
- echo 'COPY ${CONFIG_FILES} ./config/' >> Dockerfile
- echo 'ENV PORT=8080 \' >> Dockerfile
- echo ' TZ=UTC \' >> Dockerfile
- echo ' PROFILES=default' >> Dockerfile
- echo 'EXPOSE ${PORT}' >> Dockerfile
- echo 'ENTRYPOINT ["app.sh"]' >> Dockerfile
# - echo '#!/bin/bash' > app.sh
# - echo 'BASEDIR=/app' >> app.sh
# - echo 'JAVA_OPTS="-Dsumaris.basedir=${BASEDIR}"' >> app.sh
# - echo 'JAVA_OPTS="$JAVA_OPTS -Dspring.config.location=${BASEDIR}/config/"' >> app.sh
# - echo 'JAVA_OPTS="$JAVA_OPTS -Doracle.net.tns_admin=/home/tnsnames' >> app.sh
# - echo 'JAVA_OPTS="$JAVA_OPTS -Doracle.jdbc.timezoneAsRegion=false"' >> app.sh
# - echo '[[ "_${PROFILES}" != "_" ]] && JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=${PROFILES}"' >> app.sh
# - echo '[[ "_${TZ}" != "_" ]] && JAVA_OPTS="$JAVA_OPTS -Duser.timezone=${TZ}"' >> app.sh
# - echo '[[ "_${PORT}" != "_" ]] && JAVA_OPTS="$JAVA_OPTS -Dserver.port=${PORT}"' >> app.sh
# - echo 'ARGS=${@:2}' >> app.sh
# - echo 'java ${JAVA_OPTS} -server -jar ${BASEDIR}/app.war ${ARGS}' >> app.sh
# # Create the Dockerfile
# - echo 'FROM openjdk:11-jre' > Dockerfile
# - echo "ARG WAR_FILE=app.war" >> Dockerfile
# - echo "ARG CONFIG_FILES=config/*.properties" >> Dockerfile
# - echo 'RUN apt-get update && apt-get -y install libsodium-dev' >> Dockerfile
# - echo 'RUN addgroup -S spring && adduser -S spring -G spring' >> Dockerfile
# - echo 'USER spring:spring' >> Dockerfile
# - echo 'WORKDIR /app' >> Dockerfile
# - echo 'COPY app.sh app.sh' >> Dockerfile
# - echo 'RUN chmod +x app.sh' >> Dockerfile
# - echo 'COPY ${WAR_FILE} app.war' >> Dockerfile
# - echo 'RUN mkdir config' >> Dockerfile
# - echo 'COPY ${CONFIG_FILES} ./config/' >> Dockerfile
# - echo 'ENV PORT=8080 \' >> Dockerfile
# - echo ' TZ=UTC \' >> Dockerfile
# - echo ' PROFILES=default' >> Dockerfile
# - echo 'EXPOSE ${PORT}' >> Dockerfile
# - echo 'ENTRYPOINT ["app.sh"]' >> Dockerfile
# Build docker image
#- docker pull ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} || true
#- docker build --cache-from ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} --pull -t ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} .
......
FROM openjdk:8-jdk-alpine
FROM openjdk:8-jdk
ARG WAR_FILE=app.war
ARG CONFIG_FILES=config/*.properties
RUN apt update && apt -y install libsodium-dev
......
#!/bin/bash
CI_REGISTRY=gitlab-registry.ifremer.fr
CI_PROJECT_NAME=sumaris-pod
CI_PROJECT_PATH=sih-public/sumaris/sumaris-pod
CI_REGISTRY_IMAGE_PATH=${CI_REGISTRY}/${CI_PROJECT_PATH}
CI_REGISTER_USER=
CI_REGISTER_PWD=
if [[ $# -lt 2 || (! $1 =~ ^[0-9]+.[0-9]+.[0-9]+(-(alpha|beta|rc|SNAPSHOT)[-0-9]*)?$ && ! $1 = 'develop' ) ]]; then
echo "ERROR: Invalid arguments"
echo " Usage: $0 <version> <port>"
exit 1
fi
SCRIPT_DIR=$(dirname $0)
BASEDIR=$(cd "${SCRIPT_DIR}" && pwd -P)
VERSION=$1
PORT=$2
PROFILES=$3
CONFIG=${BASEDIR}/config
CI_REGISTRY_IMAGE=${CI_REGISTRY_IMAGE_PATH}:${VERSION}
CONTAINER_PREFIX="${CI_PROJECT_NAME}-${PORT}"
CONTAINER_NAME="${CONTAINER_PREFIX}-${VERSION}"
# Starting log
echo "Starting ${CI_PROJECT_NAME} v${APP_VERSION} on port ${PORT} (profiles: '${PROFILES}', config: '${CONFIG})'}"
## Login to container registry
echo "Login to ${CI_REGISTRY}..."
docker login -u "${CI_REGISTER_USER}" -p "${CI_REGISTER_PWD}" ${CI_REGISTRY}
[[ $? -ne 0 ]] && exit 1
# Pull the expected image
echo "Pulling image ${CI_REGISTRY_IMAGE}"
docker pull --no-cache ${CI_REGISTRY_IMAGE}
[[ $? -ne 0 ]] && exit 1
# Logout from container registry
docker logout ${CI_REGISTRY}
# Stop existing container
if [[ ! -z $(docker ps -f name=${CONTAINER_PREFIX} -q) ]]; then
echo "Stopping running instance..."
docker stop $(docker ps -f name=${CONTAINER_PREFIX} -q)
fi
if [[ ! -d "${CONFIG}" ]]; then
echo "ERROR: Config (directory or file) not found: '${CONFIG}'"
exit 1
fi
docker run -it -d --rm \
--name "${CONTAINER_NAME}" \
-p ${PORT}:${PORT} \
-v ${CONFIG}:/app/config \
-v /home/tnsnames:/home/tnsnames \
-e PROFILES=${PROFILES} \
-e PORT=${PORT} \
-e TZ=UTC \
${CI_REGISTRY_IMAGE}
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