From 9125a5781d3381db552a890792924ee149af89a2 Mon Sep 17 00:00:00 2001
From: bclayton-usgs <bclayton@usgs.gov>
Date: Wed, 27 May 2020 07:28:59 -0600
Subject: [PATCH] update pipeline

---
 .gitlab-ci.yml | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a75e487..d341659 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_PASSWORD: ${GITLAB_API_TOKEN}
+  GIT_NSHMP_USERNAME: ${GITLAB_USER_EMAIL}
   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
@@ -20,7 +22,6 @@ stages:
 #   - 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:
   install-aws: &install-aws |-
@@ -35,15 +36,6 @@ 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_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;
 
 ####
 # Template: Devlopment tags
@@ -62,8 +54,6 @@ stages:
   only:
     - branches
     - master@ghsc/nshmp/nshmp-netcdf
-  before_script:
-    - *ssh-key
 
 ####
 # Template: Deploy to Docker Swarm
@@ -125,7 +115,7 @@ Build Project:
   extends:
     - .gradle
   script:
-    - ./gradlew --no-daemon assemble;
+    - ./gradlew --no-daemon assemble
 
 ####
 # Run Spotless check.
@@ -134,7 +124,7 @@ Spotless Check:
   extends:
     - .gradle
   script:
-    - ./gradlew --no-daemon spotlessCheck;
+    - ./gradlew --no-daemon spotlessCheck
 
 ####
 # Run Spotbugs main.
@@ -143,7 +133,7 @@ Spotbugs Main:
   extends:
     - .gradle
   script:
-    - ./gradlew --no-daemon spotbugsMain;
+    - ./gradlew --no-daemon spotbugsMain
 
 ####
 # Run tests.
@@ -161,11 +151,9 @@ Unit Tests:
     - master@ghsc/nshmp/nshmp-netcdf
     - tags@ghsc/nshmp/nshmp-netcdf
   coverage: '/Total.*?([0-9]{1,3})%/'
-  before_script:
-    - *ssh-key
   script:
-    - ./gradlew --no-daemon check;
-    - cat ${JACOCO_HTML_DIR}/index.html;
+    - ./gradlew --no-daemon check
+    - cat ${JACOCO_HTML_DIR}/index.html
   artifacts:
     paths:
       - ${REPORTS_DIR}
@@ -187,9 +175,12 @@ Build Image:
     - tags@ghsc/nshmp/nshmp-netcdf
   before_script:
     - *install-aws
-    - *ssh-key
   script:
-    - docker build --build-arg ssh_private_key="${SSH_PRIVATE_KEY}" -t local/${IMAGE_NAME} .
+    - |
+      docker build \
+          --build-arg git_username="${GIT_NSHMP_USERNAME}" \
+          --build-arg get_password="${GIT_NSHMP_PASSWORD}" \
+          -t local/${IMAGE_NAME} .
 
 ####
 # Build and publish Docker images with data from AWS S3.
@@ -206,7 +197,6 @@ Build/Publish Data Images:
   before_script:
     - *install-aws
     - *static-data
-    - *ssh-key
     - mkdir ${DOCKER_DIR}
   script:
     - echo "${CHS_PASSWORD}" | docker login --username ${CHS_USERNAME} --password-stdin ${CODE_REGISTRY}
@@ -219,7 +209,8 @@ Build/Publish Data Images:
             DATA/${data}.nc;
         docker build \
             --build-arg netcdf_file="DATA/${data}.nc" \
-            --build-arg ssh_private_key="${SSH_PRIVATE_KEY}" \
+            --build-arg git_username="${GIT_NSHMP_USERNAME}" \
+            --build-arg get_password="${GIT_NSHMP_PASSWORD}" \
             -t ${INTERNAL_IMAGE_NAME} .;
         rm DATA/${data}.nc
         docker push ${INTERNAL_IMAGE_NAME};
-- 
GitLab