From 276f60f2c4080e67e2eca4078ce98f3aefc1d148 Mon Sep 17 00:00:00 2001
From: Mikhail Piatliou <mikhail_piatliou@epam.com>
Date: Fri, 23 Oct 2020 10:45:05 +0300
Subject: [PATCH] GONRG-989: Update pipeline for legal cloudrun

---
 .gitlab-ci.yml                                | 37 ++++++++++++-------
 .../cloudbuild/Dockerfile.cloudbuild          | 12 ++++++
 provider/legal-gcp/cloudbuild/cloudbuild.yaml | 30 +++++++++++++++
 3 files changed, 65 insertions(+), 14 deletions(-)
 create mode 100644 provider/legal-gcp/cloudbuild/Dockerfile.cloudbuild
 create mode 100644 provider/legal-gcp/cloudbuild/cloudbuild.yaml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bec86ffed..7e0b68563 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,9 +11,15 @@ variables:
   GCP_PROJECT: opendes-evt
   GCP_TENANT_NAME: opendes-evt
 
-  OSDU_GCP_BUILD_SUBDIR: provider/legal-gcp
-  OSDU_GCP_INT_TEST_SUBDIR: testing/legal-test-gcp
+# appengine vars
+  # OSDU_GCP_BUILD_SUBDIR: provider/legal-gcp
+  # OSDU_GCP_INT_TEST_SUBDIR: testing/legal-test-gcp
+  # OSDU_GCP_APPLICATION_NAME: os-legal
+
+  OSDU_GCP_SERVICE: legal
+  OSDU_GCP_VENDOR: gcp
   OSDU_GCP_APPLICATION_NAME: os-legal
+  OSDU_GCP_ENV_VARS: ENABLE_FULL_BUCKET_NAME=$ENABLE_FULL_BUCKET_NAME,PROJECT_ID=$OSDU_GCP_PROJECT,AUTHORIZE_API=$OSDU_GCP_AUTHORIZE_API,AUDIENCES=$GOOGLE_AUDIENCE,REDIS_GROUP_HOST=$REDIS_GROUP_HOST,REDIS_STORAGE_HOST=$REDIS_STORAGE_HOST,LEGAL_HOSTNAME=$OSDU_GCP_LEGAL_HOSTNAME --vpc-connector=$OSDU_GCP_VPC_CONNECTOR
 
   IBM_BUILD_SUBDIR: provider/legal-ibm
   IBM_INT_TEST_SUBDIR: testing/legal-test-ibm
@@ -22,7 +28,6 @@ variables:
   AZURE_BUILD_SUBDIR: provider/legal-azure
   AZURE_TEST_SUBDIR: testing/legal-test-azure
 
-
 include:
   - project: "osdu/platform/ci-cd-pipelines"
     file: "standard-setup.yml"
@@ -36,22 +41,26 @@ include:
   - project: "osdu/platform/ci-cd-pipelines"
     file: "scanners/gitlab-ultimate.yml"
 
-  - project: "osdu/platform/ci-cd-pipelines"
-    file: "cloud-providers/aws.yml"
+  # - project: "osdu/platform/ci-cd-pipelines"
+  #   file: "cloud-providers/aws.yml"
 
-  - project: "osdu/platform/ci-cd-pipelines"
-    file: "cloud-providers/ibm.yml"
+  # - project: "osdu/platform/ci-cd-pipelines"
+  #   file: "cloud-providers/ibm.yml"
 
-  - project: "osdu/platform/ci-cd-pipelines"
-    file: "cloud-providers/azure.yml"
+  # - project: "osdu/platform/ci-cd-pipelines"
+  #   file: "cloud-providers/azure.yml"
 
-  - project: 'osdu/platform/ci-cd-pipelines'
-    ref:  "master"
-    file: 'cloud-providers/osdu-gcp.yml'
+  # - project: 'osdu/platform/ci-cd-pipelines'
+  #   ref:  "master"
+  #   file: 'cloud-providers/osdu-gcp.yml'
 
   - project: 'osdu/platform/ci-cd-pipelines'
-    ref: "master"
-    file: 'cloud-providers/gcp.yml'
+    ref:  "migrate-legal-to-cloudrun"
+    file: 'cloud-providers/osdu-gcp-cloudrun.yml'
+
+  # - project: 'osdu/platform/ci-cd-pipelines'
+  #   ref: "master"
+  #   file: 'cloud-providers/gcp.yml'
 
 compile-and-unit-test:
   variables:
diff --git a/provider/legal-gcp/cloudbuild/Dockerfile.cloudbuild b/provider/legal-gcp/cloudbuild/Dockerfile.cloudbuild
new file mode 100644
index 000000000..535934b23
--- /dev/null
+++ b/provider/legal-gcp/cloudbuild/Dockerfile.cloudbuild
@@ -0,0 +1,12 @@
+# Use the official AdoptOpenJDK for a base image.
+# https://hub.docker.com/_/openjdk
+FROM openjdk:8-slim
+WORKDIR /app
+ARG PROVIDER_NAME
+ENV PROVIDER_NAME $PROVIDER_NAME
+ARG PORT
+ENV PORT $PORT
+# Copy the jar to the production image from the builder stage.
+COPY provider/legal-${PROVIDER_NAME}/target/legal-${PROVIDER_NAME}-*-spring-boot.jar legal-${PROVIDER_NAME}.jar
+# Run the web service on container startup.
+CMD java -Djava.security.egd=file:/dev/./urandom -Dserver.port=${PORT} -jar /app/legal-${PROVIDER_NAME}.jar
diff --git a/provider/legal-gcp/cloudbuild/cloudbuild.yaml b/provider/legal-gcp/cloudbuild/cloudbuild.yaml
new file mode 100644
index 000000000..23ee7e3ab
--- /dev/null
+++ b/provider/legal-gcp/cloudbuild/cloudbuild.yaml
@@ -0,0 +1,30 @@
+# Copyright 2020 Google LLC
+# Copyright 2017-2019, Schlumberger
+# Copyright 2020 EPAM
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+steps:
+  - name: 'gcr.io/cloud-builders/docker'
+    args: [
+            'build',
+            '--build-arg', 'PROVIDER_NAME=${_PROVIDER_NAME}',
+            '--build-arg', 'PORT=${_PORT}',
+            '-t', 'gcr.io/$PROJECT_ID/os-legal/os-legal-${_PROVIDER_NAME}:${_SHORT_SHA}',
+            '-t', 'gcr.io/$PROJECT_ID/os-legal/os-legal-${_PROVIDER_NAME}:latest',
+            '-f', 'provider/legal-${_PROVIDER_NAME}/cloudbuild/Dockerfile.cloudbuild',
+            '.'
+    ]
+
+images:
+  - 'gcr.io/$PROJECT_ID/os-legal/os-legal-${_PROVIDER_NAME}'
-- 
GitLab