From 9d0762f653c5aab627cc137adf20da4fe8b7f0c4 Mon Sep 17 00:00:00 2001 From: bclayton-usgs <bclayton@usgs.gov> Date: Tue, 26 May 2020 11:06:58 -0600 Subject: [PATCH 1/4] switch to https for nshmp-lib --- .gitlab-ci.yml | 22 ++-------------------- Dockerfile | 23 +++++++++++------------ build.gradle | 2 +- settings.gradle | 4 ++++ ws.Dockerfile | 16 ++++++---------- 5 files changed, 24 insertions(+), 43 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da74d6a82..98d1f6f18 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,8 @@ variables: CI_REGISTRY_IMAGE: ${CODE_REGISTRY_IMAGE} DOCKER_DIR: docker-images DOCKER_TAR: ${DOCKER_DIR}/app.tar + GIT_NSHMP_USERNAME: ${GITLAB_USER_EMAIL} + GIT_NSHMP_PASSWORD: ${CI_JOB_TOKEN} IMAGE_NAME_HAZ: nshmp-haz:${CI_COMMIT_REF_SLUG} IMAGE_NAME_WS: nshmp-haz-ws:${CI_COMMIT_REF_SLUG} JACOCO_HTML_DIR: build/reports/jacoco/test/html @@ -30,15 +32,6 @@ stages: DOCKERFILE="ws.Dockerfile"; IMAGE_NAME=${IMAGE_NAME_WS/:master/:latest}; INTERNAL_IMAGE_NAME=${CI_REGISTRY_IMAGE}/${IMAGE_NAME_WS}; - ssh-key: &ssh-key |- - eval $(ssh-agent -s); - mkdir -p ~/.ssh; - chmod 700 ~/.ssh; - echo "${SSH_PRIVATE_KEY}" >> ~/.ssh/id_ed25519; - chmod 0600 ~/.ssh/id_ed25519; - echo "${SSH_PRIVATE_KEY}" >> ~/.ssh/id_rsa; - chmod 0600 ~/.ssh/id_rsa; - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config; .docker-build: stage: test @@ -50,7 +43,6 @@ stages: - tags@ghsc/nshmp/nshmp-haz-v2 script: - apk add git; - - *ssh-key - mkdir ${DOCKER_DIR} - | docker build \ @@ -129,8 +121,6 @@ Build Project: - branches - master@ghsc/nshmp/nshmp-haz-v2 - tags@ghsc/nshmp/nshmp-haz-v2 - before_script: - - *ssh-key script: - ./gradlew assemble @@ -141,8 +131,6 @@ Spotless Check: only: - branches - master@ghsc/nshmp/nshmp-haz-v2 - before_script: - - *ssh-key script: - ./gradlew spotlessCheck; @@ -153,8 +141,6 @@ Spotbugs Main: only: - branches - master@ghsc/nshmp/nshmp-haz-v2 - before_script: - - *ssh-key script: - ./gradlew spotbugsMain; @@ -165,8 +151,6 @@ Spotbugs Test: only: - branches - master@ghsc/nshmp/nshmp-haz-v2 - before_script: - - *ssh-key script: - ./gradlew spotbugsTest; @@ -179,8 +163,6 @@ Unit Tests: - master@ghsc/nshmp/nshmp-haz-v2 - tags@ghsc/nshmp/nshmp-haz-v2 coverage: '/Total.*?([0-9]{1,3})%/' - before_script: - - *ssh-key script: - ./gradlew check - cat ${JACOCO_HTML_DIR}/index.html diff --git a/Dockerfile b/Dockerfile index 391db9442..4e67103d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,10 @@ # 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 . +# docker build +# --build-arg git_username=<user@name.com> +# --build-arg git_password=<git-api-token> +# -t nshmp-haz . #### ARG project=nshmp-haz-v2 @@ -26,23 +29,19 @@ FROM usgs/centos:8 as builder ARG builder_workdir ARG libs_dir -ARG ssh_private_key +ARG git_username +ARG git_password -ENV LANG="en_US.UTF-8" +ENV LANG "en_US.UTF-8" +ENV GIT_NSHMP_USERNAME ${git_username} +ENV GIT_NSHMP_PASSWORD ${git_password} WORKDIR ${builder_workdir} COPY . . 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 ./gradlew --no-daemon assemble + && ./gradlew --no-daemon assemble #### # Application image: Run jar or war file. @@ -60,7 +59,7 @@ ENV CONFIG_FILE "" ENV DEBUG false ENV IML "" ENV JAVA_XMX "8g" -ENV LANG="en_US.UTF-8" +ENV LANG "en_US.UTF-8" ENV MODEL "" ENV MOUNT_MODEL false ENV NSHM_VERSION master diff --git a/build.gradle b/build.gradle index ec436c10a..7fe810d40 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,7 @@ repositories { } git { - implementation("git@code.usgs.gov:ghsc/nshmp/nshmp-lib.git", { + implementation("https://code.usgs.gov/ghsc/nshmp/nshmp-lib.git", { name "nshmp-haz-dep--nshmp-lib" tag "v0.0.5" }) diff --git a/settings.gradle b/settings.gradle index 8c6e33c8e..2fa9c2eeb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,3 +3,7 @@ plugins { } rootProject.name = "nshmp-haz-v2" + +git { + defaultAuthGroup "nshmp" +} diff --git a/ws.Dockerfile b/ws.Dockerfile index d3089971c..1cdc994c3 100644 --- a/ws.Dockerfile +++ b/ws.Dockerfile @@ -16,25 +16,21 @@ ARG ws_file=${libs_dir}/${project}-ws.jar FROM usgs/centos:8 as builder ARG builder_workdir +ARG git_username +ARG git_password ARG libs_dir -ARG ssh_private_key ARG ws_file ENV LANG="en_US.UTF-8" WORKDIR ${builder_workdir} +ENV GIT_NSHMP_USERNAME ${git_username} +ENV GIT_NSHMP_PASSWORD ${git_password} COPY . . - +RUN env 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 ./gradlew --no-daemon assemble \ + && ./gradlew --no-daemon assemble \ && mv ${libs_dir}/*-all.jar ${ws_file} #### -- GitLab From a59a81bb2d3b0ac8a578e8bdf9ba74f00ddf6f38 Mon Sep 17 00:00:00 2001 From: bclayton-usgs <bclayton@usgs.gov> Date: Tue, 26 May 2020 11:21:38 -0600 Subject: [PATCH 2/4] add comments --- ws.Dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ws.Dockerfile b/ws.Dockerfile index 1cdc994c3..e886ffafd 100644 --- a/ws.Dockerfile +++ b/ws.Dockerfile @@ -2,7 +2,12 @@ # Run hazard web services. # # Build locally: -# docker build --build-arg ssh_private_key="$(cat ~/.ssh/id_rsa)" -t nshmp-haz-ws . +# docker build +# -f ws.Dockerfile +# --build-arg git_username=<user@name.com> +# --build-arg git_password=<git-api-token> +# -t nshmp-haz-ws . + #### ARG project=nshmp-haz-v2 -- GitLab From eacf2ee09d8761b2a3ab9f684d1fa6469675adb7 Mon Sep 17 00:00:00 2001 From: bclayton-usgs <bclayton@usgs.gov> Date: Tue, 26 May 2020 11:23:03 -0600 Subject: [PATCH 3/4] add token variable --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 98d1f6f18..3605ef77a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ variables: DOCKER_DIR: docker-images DOCKER_TAR: ${DOCKER_DIR}/app.tar GIT_NSHMP_USERNAME: ${GITLAB_USER_EMAIL} - GIT_NSHMP_PASSWORD: ${CI_JOB_TOKEN} + GIT_NSHMP_PASSWORD: ${GITLAB_API_TOKEN} IMAGE_NAME_HAZ: nshmp-haz:${CI_COMMIT_REF_SLUG} IMAGE_NAME_WS: nshmp-haz-ws:${CI_COMMIT_REF_SLUG} JACOCO_HTML_DIR: build/reports/jacoco/test/html -- GitLab From ccb6eb7b143ea56a5a417daeb6d008f783b8997f Mon Sep 17 00:00:00 2001 From: bclayton-usgs <bclayton@usgs.gov> Date: Tue, 26 May 2020 11:38:05 -0600 Subject: [PATCH 4/4] add build arguments --- .gitlab-ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3605ef77a..8cbae4ba3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,8 +3,8 @@ variables: CI_REGISTRY_IMAGE: ${CODE_REGISTRY_IMAGE} DOCKER_DIR: docker-images DOCKER_TAR: ${DOCKER_DIR}/app.tar - GIT_NSHMP_USERNAME: ${GITLAB_USER_EMAIL} GIT_NSHMP_PASSWORD: ${GITLAB_API_TOKEN} + GIT_NSHMP_USERNAME: ${GITLAB_USER_EMAIL} IMAGE_NAME_HAZ: nshmp-haz:${CI_COMMIT_REF_SLUG} IMAGE_NAME_WS: nshmp-haz-ws:${CI_COMMIT_REF_SLUG} JACOCO_HTML_DIR: build/reports/jacoco/test/html @@ -46,7 +46,8 @@ stages: - mkdir ${DOCKER_DIR} - | docker build \ - --build-arg ssh_private_key="${SSH_PRIVATE_KEY}" \ + --build-arg git_username="${GIT_NSHMP_USERNAME}" \ + --build-arg git_password="${GIT_NSHMP_PASSWORD}" \ -f ${DOCKERFILE} \ -t local/${IMAGE_NAME} . - docker save local/${IMAGE_NAME} > ${DOCKER_TAR} -- GitLab