From e51520f68bff3ea6cef0560d18c7e7ed9cff4917 Mon Sep 17 00:00:00 2001 From: Kenneth Ezekiel <88850771+KenEzekiel@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:20:26 +0700 Subject: [PATCH] add: docker running --- Dockerfile | 26 ++++++++++++++++++++++++++ docker-compose.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..45f269e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Set base image to maven image with version 3.6.3 and JDK 8 +FROM maven:3.6.3-jdk-8 AS mvnbuild +# Set working directory to app +WORKDIR /app +# Copy current directory on the host to the current directory in the container (/app) +COPY pom.xml . +COPY src ./src + +# Use Maven to build the application +#RUN --mount=type=cache,target=/root/.m2 mvn -f pom.xml clean package +RUN mvn -f pom.xml clean package + +# Start a new stage from an OpenJDK image for running the application +FROM openjdk:8-jre + +# Set working directory to /app +WORKDIR /app +# Copy the wait-for-it script into the container and make it executable +COPY /script/wait-for-it.sh /wait-for-it.sh +RUN chmod +x /wait-for-it.sh +# Copy only the built JAR from the build stage into this new stage +COPY --from=mvnbuild /app/target/letterpaw-soap-service-jar-with-dependencies.jar letterpaw-soap-service-jar-with-dependencies.jar + +# Set the entrypoint to run the JAR +ENTRYPOINT ["/wait-for-it.sh", "db:3306", "--timeout=30", "--strict", "--"] +CMD ["java", "-jar", "letterpaw-soap-service-jar-with-dependencies.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5b17611 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +version: '3.9' + +services: + db: + image: mysql + container_name: db + restart: always + environment: + - MYSQL_ROOT_PASSWORD=rootpass + - MYSQL_DATABASE=letterpaw_soap + - MYSQL_USER=soap_user + - MYSQL_PASSWORD=p4ssw0rd + ports: + - "3306:3306" + volumes: + - ./script:/docker-entrypoint-initdb.d/:ro + - mysql_data:/var/lib/mysql + networks: + - soap-network + soap: + build: . + env_file: + - .env + environment: + - DB_HOST=db + - DB_PORT=3306 + - DB_NAME=letterpaw_soap + - DB_USER=soap_user + - DB_PASS=p4ssw0rd + - DB_URL=jdbc:mysql://db:3306/letterpaw_soap + - HOST=0.0.0.0 + - PORT=7000 + depends_on: + - db + ports: + - "7000:7000" + networks: + - soap-network +volumes: + mysql_data: +networks: + soap-network: \ No newline at end of file -- GitLab