diff --git a/.dockerignore b/.dockerignore index 165c23ab60f6e50cbdd31708aee130da1ad6f518..27fa1f58b3245719b4f64591f4ce72a30725d0f1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -14,3 +14,4 @@ Scratch*.java nshmp-haz-log* .vscode config.properties +libs diff --git a/.gitignore b/.gitignore index 995f4215ba03babdc405569847bd2a2f8b179390..f733e83b93c33d3db8fea921fca0bca7bec4cc79 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ scratch*.html Scratch*.js webapp/config.json config.properties +libs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ca43ef1170caab252bd3e74fa6e93a9069420441..5dd34217543ecbf5dbb50f4552f31d39db5cc137 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,13 +3,9 @@ variables: CI_REGISTRY_IMAGE: ${CODE_REGISTRY_IMAGE} DOCKER_DIR: docker-images DOCKER_TAR: ${DOCKER_DIR}/app.tar - FAULT_SECTIONS: nshm-fault-sections - FAULT_SECTIONS_GIT: https://gitlab-ci-token:${CI_JOB_TOKEN}@code.usgs.gov/ghsc/nshmp/${FAULT_SECTIONS}.git IMAGE_NAME: ${CI_PROJECT_NAME}:${CI_COMMIT_REF_SLUG} JACOCO_HTML_DIR: build/reports/jacoco/test/html JUNIT_FILES: build/test-results/test/TEST-*.xml - NSHMP_LIB: nshmp-lib - NSHMP_LIB_GIT: https://gitlab-ci-token:${CI_JOB_TOKEN}@code.usgs.gov/ghsc/nshmp/${NSHMP_LIB}.git stages: - test @@ -30,19 +26,16 @@ stages: # - adjust-image-names: Update container image names #### .templates: - nshmp-lib: &nshmp-lib |- - cd ..; - rm -rf ${NSHMP_LIB}; - git clone ${NSHMP_LIB_GIT}; - cd ${CI_PROJECT_NAME}; - fault-sections: &fault-sections |- - cd ..; - rm -rf ${FAULT_SECTIONS}; - git clone ${FAULT_SECTIONS_GIT}; - cd ${CI_PROJECT_NAME}; - adjust-image-names: &adjust-image-names + adjust-image-names: &adjust-image-names |- IMAGE_NAME=${IMAGE_NAME/:master/:latest}; INTERNAL_IMAGE_NAME=${CI_REGISTRY_IMAGE}/${IMAGE_NAME}; + ssh-key: &ssh-key |- + eval $(ssh-agent -s); + mkdir -p ~/.ssh; + chmod 700 ~/.ssh; + echo "${SSH_PRIVATE_KEY}" >> ~/.ssh/id_rsa; + chmod 0600 ~/.ssh/id_rsa; + echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config; #### # Template: Deploy to Docker Swarm @@ -96,11 +89,11 @@ Build Project: image: gradle:jdk11 extends: .dev-tags only: - - merge_request + - branches - master@ghsc/nshmp/nshmp-haz-v2 - tags@ghsc/nshmp/nshmp-haz-v2 before_script: - - *nshmp-lib + - *ssh-key script: - ./gradlew assemble @@ -112,10 +105,10 @@ Spotless Check: image: gradle:jdk11 extends: .dev-tags only: - - merge_request + - branches - master@ghsc/nshmp/nshmp-haz-v2 before_script: - - *nshmp-lib + - *ssh-key script: - ./gradlew spotlessCheck; @@ -127,10 +120,10 @@ Spotbugs Main: image: gradle:jdk11 extends: .dev-tags only: - - merge_request + - branches - master@ghsc/nshmp/nshmp-haz-v2 before_script: - - *nshmp-lib + - *ssh-key script: - ./gradlew spotbugsMain; @@ -142,10 +135,10 @@ Spotbugs Test: image: gradle:jdk11 extends: .dev-tags only: - - merge_request + - branches - master@ghsc/nshmp/nshmp-haz-v2 before_script: - - *nshmp-lib + - *ssh-key script: - ./gradlew spotbugsTest; @@ -160,13 +153,12 @@ Unit Tests: image: gradle:jdk11 extends: .dev-tags only: - - merge_request + - branches - master@ghsc/nshmp/nshmp-haz-v2 - tags@ghsc/nshmp/nshmp-haz-v2 coverage: '/Total.*?([0-9]{1,3})%/' before_script: - - *fault-sections - - *nshmp-lib + - *ssh-key script: - ./gradlew check - cat ${JACOCO_HTML_DIR}/index.html @@ -190,20 +182,17 @@ Build Image: image: docker:stable extends: .dev-tags only: - - merge_request + - branches - master@ghsc/nshmp/nshmp-haz-v2 - tags@ghsc/nshmp/nshmp-haz-v2 before_script: - *adjust-image-names - rm -rf ${DOCKER_DIR} - apk add git; - - *nshmp-lib - - mv ../${NSHMP_LIB} . - - *fault-sections - - mv ../${FAULT_SECTIONS} . + - *ssh-key script: - mkdir ${DOCKER_DIR} - - docker build -t local/${IMAGE_NAME} . + - docker build --build-arg ssh_private_key="${SSH_PRIVATE_KEY}" -t local/${IMAGE_NAME} . - docker save local/${IMAGE_NAME} > ${DOCKER_TAR} artifacts: paths: diff --git a/Dockerfile b/Dockerfile index 2912436f2bd8f35716d1c550a43061d7a811a829..0a4892857d420a72f716a29a189faf1c085c91d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,9 @@ # -e RUN_HAZARD=false \ # -e MODEL=<COUS-20[08|14|18] | AK-2007 | HI-2020> \ # code.chs.usgs.gov:5001/ghsc/nshmp/images/nshmp-haz-v2; +# +# Build locally: +# docker build --build-arg ssh_private_key="$(cat ~/.ssh/id_rsa)" -t nshmp-haz . #### ARG project=nshmp-haz-v2 @@ -35,15 +38,21 @@ ENV LANG="en_US.UTF-8" ARG builder_workdir ARG libs_dir ARG ws_file +ARG ssh_private_key WORKDIR ${builder_workdir} COPY . . -RUN yum install -y java-11-openjdk-devel which git +RUN yum install -y java-11-openjdk-devel which git \ + && eval $(ssh-agent -s) \ + && mkdir -p ~/.ssh \ + && chmod 700 ~/.ssh \ + && echo "${ssh_private_key}" >> ~/.ssh/id_rsa \ + && chmod 0600 ~/.ssh/id_rsa \ + && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config -RUN mv nshmp-lib ../. \ - && ./gradlew --no-daemon assemble \ +RUN ./gradlew --no-daemon assemble \ && mv ${libs_dir}/*-all.jar ${ws_file} #### diff --git a/build.gradle b/build.gradle index 4a89efb7cfc6168eb289f0580c5f2e3532e1151c..ddc3fe0368dfa32da779560a1c80bb62bf02417c 100644 --- a/build.gradle +++ b/build.gradle @@ -43,9 +43,6 @@ apply from: "${projectDir}/gradle/ext.gradle" apply from: "${projectDir}/gradle/jar.gradle" apply from: "${projectDir}/gradle/javadoc.gradle" apply from: "${projectDir}/gradle/tasks.gradle" -apply from: project(":nshmp-lib").file("gradle/git-hooks.gradle") -apply from: project(":nshmp-lib").file("gradle/spotbugs.gradle") -apply from: project(":nshmp-lib").file("gradle/spotless.gradle") sourceCompatibility = JavaVersion.VERSION_11 compileJava.options.encoding = "UTF-8" @@ -60,9 +57,18 @@ repositories { jcenter() } -dependencies { - implementation project(":nshmp-lib") +git { + implementation("git@code.usgs.gov:ghsc/nshmp/nshmp-lib.git", { + name "nshmp-haz-dep--nshmp-lib" + tag "v0.0.4" + }) +} +apply from: "${nshmpLibGradleDir}/git-hooks.gradle" +apply from: "${nshmpLibGradleDir}/spotbugs.gradle" +apply from: "${nshmpLibGradleDir}/spotless.gradle" + +dependencies { // AWS implementation "com.amazonaws:aws-lambda-java-core:${awsLambdaCoreVersion}" implementation "com.amazonaws:aws-java-sdk-lambda:${awsLambdaVersion}" diff --git a/gradle.properties b/gradle.properties index 1cb947167a901745f496957700c5543597a7ca4f..1a2f1bd03cde8020b084e9d03f09d691ecffcca0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,3 +8,4 @@ logbackVersion = 1.2.3 mnOpenAPIVersion = 1.4.0 mnVersion = 1.3.2 swaggerVersion = 2.1.1 +nshmFaultSectionsTag = v0.1 diff --git a/gradle/ext.gradle b/gradle/ext.gradle index dbc300ca859641da5f74c27b469abbe65713b9e8..d2f9df49ade0faedb7317233bbe5a5dbee0380d9 100644 --- a/gradle/ext.gradle +++ b/gradle/ext.gradle @@ -6,6 +6,11 @@ ext { propsPath = '/classes/java/main/service.properties' + nshmpLib = "libs/nshmp-haz-dep--nshmp-lib" + nshmpLibGradleDir = "${nshmpLib}/gradle" + spotbugsDir = "${nshmpLib}/gradle" + spotlessDir = "${nshmpLib}/src/main/resources" + /* Multi-model repository paths for version tracking */ repo_cous_2008 = '../nshm-cous-2008' repo_cous_2014 = '../nshm-cous-2014' diff --git a/settings.gradle b/settings.gradle index 1c75d2d58d46ae355814d24609bb6cdb310f3b01..3f7cbf821b8d12002b0ed02a11ca4c9793a7bd48 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,12 @@ -rootProject.name = 'nshmp-haz-v2' -include ':nshmp-lib' -project(':nshmp-lib').projectDir = new File(settingsDir, '../nshmp-lib') +plugins { + id "com.alexvasilkov.git-dependencies" version "2.0.1" +} + +rootProject.name = "nshmp-haz-v2" + +git { + // Required for nshmp-lib tests + fetch ("git@code.usgs.gov:ghsc/nshmp/nshm-fault-sections.git", { + tag nshmFaultSectionsTag + }) +}