diff --git a/.dockerignore b/.dockerignore index a2a2390190f528899755d9d49f3c1b327476a07a..4f50c3403653d9a260bfb4549d0476bd32530eac 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,3 +11,4 @@ tmp .apt_generated* .factorypath swagger-files +libs diff --git a/.gitignore b/.gitignore index 85d22515a6ab6e8a16d045162173a67e799f7cc5..9cbbe5b5883e1856a942be118a737a9b86874e58 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ Scratch*.js webapp/config.json config.properties swagger-files +libs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 21c49ad8d77054d0449326345c4643974e2cf0d4..33671dd3f90286726900d07ed5b8fcdcba3830d4 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: ${REPORTS_DIR}/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 REPORTS_DIR: build/reports # Static data in AWS S3 DATA_CONUS_2018A: conus-2018a @@ -21,17 +17,12 @@ stages: #### # Templates: -# - fault-sections: Download nshm-fault-sections repo. Required for nshmp-lib tests. # - install-aws: Install aws in a Alpine environment # - nshmp-lib: Download nshmp-lib repo # - static-data: Array of all static data in AWS s3 +# - ssh-key: Add ssh key #### .templates: - fault-sections: &fault-sections |- - cd ..; - rm -rf ${FAULT_SECTIONS}; - git clone ${FAULT_SECTIONS_GIT}; - cd ${CI_PROJECT_NAME} install-aws: &install-aws |- apk -v --update add --no-cache python py-pip groff; pip install awscli; @@ -44,6 +35,13 @@ stages: STATIC_DATA=" ${DATA_CONUS_2018A} "; + 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: Devlopment tags @@ -60,10 +58,10 @@ stages: stage: test image: gradle:jdk11 only: - - merge_request + - branches - master@ghsc/nshmp/nshmp-netcdf before_script: - - *nshmp-lib + - *ssh-key #### # Template: Deploy to Docker Swarm @@ -157,13 +155,12 @@ Unit Tests: image: gradle:jdk11 extends: .dev-tags only: - - merge_request + - branch - master@ghsc/nshmp/nshmp-netcdf - tags@ghsc/nshmp/nshmp-netcdf coverage: '/Total.*?([0-9]{1,3})%/' before_script: - - *fault-sections - - *nshmp-lib + - *ssh-key script: - ./gradlew --no-daemon check; - cat ${JACOCO_HTML_DIR}/index.html; @@ -183,15 +180,14 @@ Build Image: image: docker:stable-git extends: .dev-tags only: - - merge_request + - branches - master@ghsc/nshmp/nshmp-netcdf - tags@ghsc/nshmp/nshmp-netcdf before_script: - *install-aws - - *nshmp-lib - - mv ../${NSHMP_LIB} . + - *ssh-key script: - - docker build -t local/${IMAGE_NAME} . + - docker build --build-arg ssh_private_key="${SSH_PRIVATE_KEY}" -t local/${IMAGE_NAME} . #### # Build and publish Docker images with data from AWS S3. @@ -207,9 +203,8 @@ Build/Publish Data Images: - tags@ghsc/nshmp/nshmp-netcdf before_script: - *install-aws - - *nshmp-lib - *static-data - - mv ../${NSHMP_LIB} . + - *ssh-key - mkdir ${DOCKER_DIR} script: - echo "${CHS_PASSWORD}" | docker login --username ${CHS_USERNAME} --password-stdin ${CODE_REGISTRY} diff --git a/Dockerfile b/Dockerfile index bbdca32411825b8a009b6f10732527916e80d254..3552205282e5ebca687be111716e9bac71ae8402 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,8 @@ +#### +# Build locally: +# docker build --build-arg ssh_private_key="$(cat ~/.ssh/id_rsa)" -t nshmp-ws . +#### + # Current project ARG project=nshmp-netcdf @@ -20,17 +25,23 @@ ENV LANG="en_US.UTF-8" ARG workdir ARG libs_dir ARG jar_file +ARG ssh_private_key WORKDIR ${workdir} -RUN yum install -y java-11-openjdk which git +RUN yum install -y java-11-openjdk 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 COPY build.gradle . COPY .git .git COPY gradle gradle COPY gradle.properties . COPY gradlew . -COPY nshmp-lib ../nshmp-lib COPY settings.gradle . COPY src src COPY openapi.properties . diff --git a/build.gradle b/build.gradle index f57cf204c1fdcfb6cf0314dfc6c900d7ca875499..77fa9d7f27239b21aa87254f982574b1f93b266f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,15 @@ plugins { id "application" + id "com.diffplug.gradle.spotless" version "3.27.1" + id "com.github.johnrengelman.shadow" version "5.2.0" + id "com.github.spotbugs" version "3.0.0" + id "com.star-zero.gradle.githook" version "1.2.0" id "eclipse-wtp" - id "java" id "jacoco" - id "com.github.johnrengelman.shadow" version "5.2.0" + id "java" id "net.ltgt.apt-eclipse" version "0.21" - id "com.star-zero.gradle.githook" version "1.2.0" - id "com.github.spotbugs" version "3.0.0" - id "com.diffplug.gradle.spotless" version "3.27.1" } -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" @@ -27,9 +23,26 @@ repositories { } } -dependencies { - implementation project(":nshmp-lib") +git { + implementation("git@code.usgs.gov:ghsc/nshmp/nshmp-lib.git", { + name "nshmp-netcdf-dep--nshmp-lib" + tag "v0.0.4" + }) +} + +ext { + nshmpLib = "libs/nshmp-netcdf-dep--nshmp-lib" + nshmpLibGradleDir = "${nshmpLib}/gradle" + spotbugsDir = "${nshmpLib}/gradle" + spotlessDir = "${nshmpLib}/src/main/resources" + swaggerDir = "swagger-files" +} + +apply from: "${nshmpLibGradleDir}/git-hooks.gradle" +apply from: "${nshmpLibGradleDir}/spotbugs.gradle" +apply from: "${nshmpLibGradleDir}/spotless.gradle" +dependencies { // NetCDF implementation "edu.ucar:cdm:${cdmVersion}" implementation "edu.ucar:netcdf4:${netcdfVersion}" @@ -63,10 +76,6 @@ dependencies { testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" } -ext { - swaggerDir = "swagger-files" -} - test { useJUnitPlatform() } diff --git a/gradle.properties b/gradle.properties index 17f0e3514c60deaffdf5c3d95699838c9d2e5c59..a1fc4b1af53b93eb9668d35ac7a11c33e0533c16 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,3 +7,4 @@ netcdfVersion = 5.1.0 slfVersion = 1.7.30 swaggerVersion = 2.1.1 mnOpenAPIVersion = 1.4.0 +nshmFaultSectionsTag = v0.1 diff --git a/settings.gradle b/settings.gradle index 14fd4cc781a9a83b250fd674122c9781b92a8843..6bce7383a26ae6896ef8527c0f2c6f9ffa3e069c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,12 @@ -rootProject.name = 'nshmp-netcdf' -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-netcdf" + +git { + // Required for nshmp-lib tests + fetch ("git@code.usgs.gov:ghsc/nshmp/nshm-fault-sections.git", { + tag nshmFaultSectionsTag + }) +}