From 464e6d537a3a472b153ce2b06b4b1eeb0749a61c Mon Sep 17 00:00:00 2001 From: "Siarhei Symanovich (EPAM)" <siarhei_symanovich@epam.com> Date: Wed, 21 Feb 2024 09:21:22 +0000 Subject: [PATCH] #43 build docker image (osdu/platform/system/project-and-workflow!11) --- .gitlab-ci.yml | 47 +++++++++++++++++------- .mvn/community-maven.settings.xml | 8 ++-- provider/pws-aws/build-aws/Dockerfile | 23 ++++++++++++ provider/pws-aws/build-aws/entrypoint.sh | 14 +++++++ 4 files changed, 74 insertions(+), 18 deletions(-) create mode 100644 provider/pws-aws/build-aws/Dockerfile create mode 100755 provider/pws-aws/build-aws/entrypoint.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 576658e2..ce9f74d4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,19 @@ -image: maven:3.8.3-openjdk-17-slim +stages: + - review + - build + - coverage + - containerize + - scan + +include: + # - project: "osdu/platform/ci-cd-pipelines" ##TODO Uncomment after migration into common protected branch rule + # file: "standard-setup.yml" + + - project: "osdu/platform/ci-cd-pipelines" + file: "build/maven.yml" + + # - project: "osdu/platform/ci-cd-pipelines" ##TODO Uncomment after creating NOTICE file + # file: "scanners/fossa-maven.yml" .maven: image: maven:3.8.3-openjdk-17-slim @@ -6,11 +21,9 @@ image: maven:3.8.3-openjdk-17-slim variables: MAVEN_REPO_PATH: "$CI_PROJECT_DIR/.m2/repository" MAVEN_CLI_OPTS: "--batch-mode --settings=$CI_PROJECT_DIR/.mvn/community-maven.settings.xml" - cache: paths: - $MAVEN_REPO_PATH - artifacts: paths: - ./**/target/*.jar @@ -18,16 +31,22 @@ image: maven:3.8.3-openjdk-17-slim when: always expire_in: 2 days -stages: - - build - -cache: - paths: - - .m2/repository - - target +.skipForTriggeringMergeRequests: + script: + - echo "stub skipForTriggeringMergeRequests" -build: - stage: build +containerize: + stage: containerize + needs: ['compile-and-unit-test'] + tags: ["osdu-medium"] + image: docker:19.03 script: - - echo "Maven compile started" - - "mvn install" \ No newline at end of file + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - > + if [[ "$CI_COMMIT_REF_NAME" == "$CI_DEFAULT_BRANCH" ]]; + then docker build -f provider/pws-aws/build-aws/Dockerfile -t $CI_REGISTRY_IMAGE:latest . && + docker push $CI_REGISTRY_IMAGE:latest; + else + docker build -f provider/pws-aws/build-aws/Dockerfile -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA . && + docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA; + fi diff --git a/.mvn/community-maven.settings.xml b/.mvn/community-maven.settings.xml index 4eb9f389..c57b19cf 100644 --- a/.mvn/community-maven.settings.xml +++ b/.mvn/community-maven.settings.xml @@ -16,10 +16,10 @@ https://community.opengroup.org/api/v4/groups/17/-/packages/maven </repo.releases.url> <publish.snapshots.url> - https://community.opengroup.org/api/v4/projects/44/packages/maven + https://community.opengroup.org/api/v4/projects/1468/packages/maven </publish.snapshots.url> <publish.releases.url> - https://community.opengroup.org/api/v4/projects/44/packages/maven + https://community.opengroup.org/api/v4/projects/1468/packages/maven </publish.releases.url> </properties> </profile> @@ -44,10 +44,10 @@ https://community.opengroup.org/api/v4/groups/17/-/packages/maven </repo.releases.url> <publish.snapshots.url> - https://community.opengroup.org/api/v4/projects/44/packages/maven + https://community.opengroup.org/api/v4/projects/1468/packages/maven </publish.snapshots.url> <publish.releases.url> - https://community.opengroup.org/api/v4/projects/44/packages/maven + https://community.opengroup.org/api/v4/projects/1468/packages/maven </publish.releases.url> </properties> </profile> diff --git a/provider/pws-aws/build-aws/Dockerfile b/provider/pws-aws/build-aws/Dockerfile new file mode 100644 index 00000000..b6ca93c1 --- /dev/null +++ b/provider/pws-aws/build-aws/Dockerfile @@ -0,0 +1,23 @@ +# 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. + +# https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html +FROM amazoncorretto:17 + +ARG JAR_FILE=provider/pws-aws/target/*spring-boot.jar + +WORKDIR / +COPY ${JAR_FILE} app.jar +COPY /provider/pws-aws/build-aws/entrypoint.sh /entrypoint.sh +EXPOSE 8080 + +ENTRYPOINT ["/bin/sh", "-c", ". /entrypoint.sh"] diff --git a/provider/pws-aws/build-aws/entrypoint.sh b/provider/pws-aws/build-aws/entrypoint.sh new file mode 100755 index 00000000..507a0483 --- /dev/null +++ b/provider/pws-aws/build-aws/entrypoint.sh @@ -0,0 +1,14 @@ +# 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. + +# --add-opens args used to open modules and allow illegal(reflection\private classes and fields) access from the code. +java $JAVA_OPTS --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED -jar /app.jar -- GitLab