From 94751cf1f70afbba8846d341d68c18aa9e9e75a5 Mon Sep 17 00:00:00 2001 From: neo <7526431+Raghav2211@users.noreply.github.com> Date: Sat, 19 Dec 2020 18:10:02 +0000 Subject: [PATCH] FEATURE-58 // Use one Dockerfile instead of two for maven & gradle (#59) * FEATURE-58 1. Add one Dockerfile for both maven & gradle 2. Remove specific files * Update README * Remove version from psi-todo for ci build * Update CI build 1. Remove Dockerfile.mvn & Dockerfile.gradle from ci build 2. Use one Dockerfile * Update build.yml use ci environment Co-authored-by: Raghav2211 --- .github/workflows/build.yml | 6 +++--- todo-app/Dockerfile | 11 +++++++++++ todo-app/Dockerfile.gradle | 4 ---- todo-app/Dockerfile.mvn | 4 ---- todo-app/README.md | 7 ++++--- todo-app/env/ci/Docker.env | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 todo-app/Dockerfile delete mode 100644 todo-app/Dockerfile.gradle delete mode 100644 todo-app/Dockerfile.mvn diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4b3b2ae1..dbe3d935 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,10 +35,10 @@ jobs: run: mvn -B package - name: Build local image run: | - docker build -f Dockerfile.mvn --tag psi-todo:1.0.0 . - docker build -f Dockerfile.gradle --tag psi-todo:1.0.0 . + docker build --tag psi-todo . + docker build --build-arg JAR_FILE=build/libs/\*.jar --tag psi-todo . - name: Build local stack - run: docker-compose --env-file=env/local/Docker.env up -d + run: docker-compose --env-file=env/ci/Docker.env up -d - name: Test local stack run: | sleep 120 diff --git a/todo-app/Dockerfile b/todo-app/Dockerfile new file mode 100644 index 00000000..301f3fd9 --- /dev/null +++ b/todo-app/Dockerfile @@ -0,0 +1,11 @@ +FROM openjdk:11-jre-slim +ARG USER=psi +ARG GROUP=psi +ARG UID=1000 +ARG GID=1000 +ARG JAR_FILE=target/*.jar +RUN echo $JAR_FILE +RUN groupadd -g ${GID} ${GROUP} && useradd -u ${UID} -g ${GROUP} ${USER} +USER ${USER}:${GROUP} +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["java","-server", "-Dfile.encoding=utf-8", "-XX:+ExitOnOutOfMemoryError", "-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=UTC","-jar","/app.jar"] \ No newline at end of file diff --git a/todo-app/Dockerfile.gradle b/todo-app/Dockerfile.gradle deleted file mode 100644 index a9692bc0..00000000 --- a/todo-app/Dockerfile.gradle +++ /dev/null @@ -1,4 +0,0 @@ -FROM openjdk:11-jre-slim -VOLUME /tmp -ADD build/libs/psi-todo-*.jar app.jar -ENTRYPOINT ["java","-server", "-Dfile.encoding=utf-8", "-XX:+ExitOnOutOfMemoryError", "-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=UTC","-jar","/app.jar"] \ No newline at end of file diff --git a/todo-app/Dockerfile.mvn b/todo-app/Dockerfile.mvn deleted file mode 100644 index 81fbc75b..00000000 --- a/todo-app/Dockerfile.mvn +++ /dev/null @@ -1,4 +0,0 @@ -FROM openjdk:11-jre-slim -VOLUME /tmp -ADD target/psi-todo-*.jar app.jar -ENTRYPOINT ["java","-server", "-Dfile.encoding=utf-8", "-XX:+ExitOnOutOfMemoryError", "-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=UTC","-jar","/app.jar"] \ No newline at end of file diff --git a/todo-app/README.md b/todo-app/README.md index a28d8a7a..0f0c528c 100644 --- a/todo-app/README.md +++ b/todo-app/README.md @@ -47,12 +47,13 @@ or ##### Docker image ##### ```bash -docker build -f Dockerfile.mvn --tag psi-todo:1.0.0 . + +docker build --tag psi-todo:1.0.0 . ``` -or +If you use Gradle, you can run it with the following command ```bash -docker build -f Dockerfile.gradle --tag psi-todo:1.0.0 . +docker build --build-arg JAR_FILE=build/libs/\*.jar --tag psi-todo:1.0.0 . ``` ## Run ## diff --git a/todo-app/env/ci/Docker.env b/todo-app/env/ci/Docker.env index cc73a672..f529bdee 100644 --- a/todo-app/env/ci/Docker.env +++ b/todo-app/env/ci/Docker.env @@ -1,7 +1,7 @@ # Set these env variables #App variables -PSI_TODO_IMAGE=psi-todo:1.0.0 +PSI_TODO_IMAGE=psi-todo #Database variables MYSQL_IMAGE=mysql:8.0.22