diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4e0afc293ea3b33b3bdbf9c544f571dba8290437..249a8f7421be9d42b52bbc5642a86f0b9bb28d64 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,18 +10,16 @@ variables: # Static data in AWS S3 DATA_CONUS_2018A: conus-2018a +include: + - project: "ghsc/hazdev/pipeline-build-template" + ref: "1.1.3" + file: "templates/library.yml" + stages: - - assemble - - test + - build - publish - deploy -cache: - key: one-key-to-rule-them-all - paths: - - build - - .gradle - #### # Templates: # - install-aws: Install aws in a Alpine environment @@ -37,20 +35,14 @@ cache: ${DATA_CONUS_2018A} "; -#### -# Template: Devlopment tags -#### -.dev-tags: - tags: - - development - #### # Template: Common Gradle test #### .gradle: - extends: .dev-tags - stage: test - image: gradle:jdk11 + extends: + - .tags::development + stage: build + image: usgs/java:11 only: - branches - master@ghsc/nshmp/nshmp-netcdf @@ -91,11 +83,8 @@ cache: variables: APP_NAME: nshmp-netcdf STACK_NAME: nshmp-netcdf - retry: - max: 2 - when: 'always' -.staging: +.onprem-staging: only: - master@ghsc/nshmp/nshmp-netcdf - tags@ghsc/nshmp/nshmp-netcdf @@ -109,32 +98,28 @@ cache: - staging02 #### -# Stage: assemble +# Stage: build #### Build Project: extends: - .gradle - stage: assemble + stage: build script: - - ./gradlew --build-cache --no-daemon assemble - retry: - max: 2 - when: 'always' + - ./gradlew assemble -#### -# Stage: test -#### +Build Image: + extends: + - .build + variables: + DOCKER_BUILD_ARGS: | + ci_job_token="${CI_JOB_TOKEN}" Unit Tests: - stage: test - image: gradle:jdk11 - extends: .dev-tags - only: - - branches - - master@ghsc/nshmp/nshmp-netcdf - - tags@ghsc/nshmp/nshmp-netcdf + extends: + - .gradle coverage: '/Total.*?([0-9]{1,3})%/' + stage: build script: - ./gradlew --no-daemon check - cat ${JACOCO_HTML_DIR}/index.html @@ -143,68 +128,43 @@ Unit Tests: - ${REPORTS_DIR} reports: junit: ${JUNIT_FILES} - retry: - max: 2 - when: 'always' -Build Image: - stage: test - image: docker:stable-git - extends: .dev-tags - only: - - branches - - master@ghsc/nshmp/nshmp-netcdf - - tags@ghsc/nshmp/nshmp-netcdf - before_script: - - *install-aws - script: - - | - docker build \ - --build-arg ci_job_token="${CI_JOB_TOKEN}" \ - -t local/${IMAGE_NAME} . - retry: - max: 2 - when: 'always' - -#### -# Stage: publish -#### - -Build/Publish Data Images: - stage: publish - image: docker:stable-git - extends: .dev-tags - only: - - master@ghsc/nshmp/nshmp-netcdf - - tags@ghsc/nshmp/nshmp-netcdf - before_script: - - *install-aws - - *static-data - - mkdir ${DOCKER_DIR} - script: - - echo "${CHS_PASSWORD}" | docker login --username ${CHS_USERNAME} --password-stdin ${CODE_REGISTRY} - - | - for data in ${STATIC_DATA}; do - IMAGE_NAME=${IMAGE_NAME/:*/:${data}}; - INTERNAL_IMAGE_NAME=${CI_REGISTRY_IMAGE}/${IMAGE_NAME}; - aws s3 cp --only-show-errors \ - s3://nshmp-hazard-curves/${data}.nc \ - DATA/${data}.nc; - docker build \ - --build-arg ci_job_token="${CI_JOB_TOKEN}" \ - --build-arg netcdf_file="DATA/${data}.nc" \ - -t ${INTERNAL_IMAGE_NAME} .; - rm DATA/${data}.nc - docker push ${INTERNAL_IMAGE_NAME}; - docker image rm ${INTERNAL_IMAGE_NAME}; - done - - rm -rf /root/.docker/config.json - retry: - max: 2 - when: 'always' +# #### +# # Stage: publish +# #### + +# Build/Publish Data Images: +# stage: publish +# image: docker:stable-git +# extends: .dev-tags +# only: +# - master@ghsc/nshmp/nshmp-netcdf +# - tags@ghsc/nshmp/nshmp-netcdf +# before_script: +# - *install-aws +# - *static-data +# - mkdir ${DOCKER_DIR} +# script: +# - echo "${CHS_PASSWORD}" | docker login --username ${CHS_USERNAME} --password-stdin ${CODE_REGISTRY} +# - | +# for data in ${STATIC_DATA}; do +# IMAGE_NAME=${IMAGE_NAME/:*/:${data}}; +# INTERNAL_IMAGE_NAME=${CI_REGISTRY_IMAGE}/${IMAGE_NAME}; +# aws s3 cp --only-show-errors \ +# s3://nshmp-hazard-curves/${data}.nc \ +# DATA/${data}.nc; +# docker build \ +# --build-arg ci_job_token="${CI_JOB_TOKEN}" \ +# --build-arg netcdf_file="DATA/${data}.nc" \ +# -t ${INTERNAL_IMAGE_NAME} .; +# rm DATA/${data}.nc +# docker push ${INTERNAL_IMAGE_NAME}; +# docker image rm ${INTERNAL_IMAGE_NAME}; +# done +# - rm -rf /root/.docker/config.json Maven: - image: gradle:jdk11 + image: usgs/java:11 stage: publish extends: .dev-tags only: @@ -219,11 +179,11 @@ Maven: Staging 01: extends: - .deploy - - .staging + - .onprem-staging - .staging01 Staging 02: extends: - .deploy - - .staging + - .onprem-staging - .staging02 diff --git a/Dockerfile b/Dockerfile index 1cd6cc9b19f1907bbe431fc6285a90a524418b82..3ac48a8f88035483b9e7c2fa5c580c1a5e0bfe56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ #### # Build locally: # docker build -# --build-arg git_username=<user@name.com> -# --build-arg git_password=<git-api-token> +# --build-arg gitlab_token=<token> # -t nshmp-netcdf . #### +ARG BUILD_IMAGE=usgs/java:11 +ARG FROM_IMAGE=usgs/java:11 + ARG project=nshmp-netcdf ARG workdir=/app/${project} ARG libs_dir=${workdir}/build/libs @@ -14,9 +16,7 @@ ARG jar_file=${libs_dir}/${project}.jar #### # Build war file #### -FROM usgs/centos:8 as builder - -ENV LANG="en_US.UTF-8" +FROM ${BUILD_IMAGE} as builder ARG gitlab_token=null ARG ci_job_token=null @@ -24,13 +24,12 @@ ARG libs_dir ARG jar_file ARG workdir +# TODO: Token needed until nshmp-lib is public ENV GITLAB_TOKEN ${gitlab_token} ENV CI_JOB_TOKEN ${ci_job_token} WORKDIR ${workdir} -RUN yum install -y glibc-langpack-en java-11-openjdk which git - COPY build.gradle . COPY .git .git COPY gradle gradle @@ -46,9 +45,7 @@ RUN ./gradlew --no-daemon assemble \ #### # Run service #### -FROM usgs/centos:8 - -ENV LANG "en_US.UTF-8" +FROM ${FROM_IMAGE} # The NetCDF file to read in ARG netcdf_file="src/main/resources/default.nc" @@ -68,10 +65,9 @@ WORKDIR ${workdir} COPY --from=builder ${jar_file} ${project}.jar COPY ${NETCDF_FILE} ${NETCDF_FILE} -RUN yum install -y java-11-openjdk-headless - -EXPOSE 8080 ENTRYPOINT /usr/bin/java -jar ${PROJECT}.jar \ "-Dmicronaut.server.context-path=${CONTEXT_PATH}" \ -nshm=${NSHM} \ -netcdf=${NETCDF_FILE} + +EXPOSE 8080