diff --git a/Dockerfile b/Dockerfile index 21f8be2..aed3bb3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,27 @@ -FROM openjdk:17-jdk-slim +FROM eclipse-temurin:17-jdk-alpine as build -RUN apt-get -y update -RUN apt-get -y install netcat -RUN apt-get -y install curl +COPY .mvn/ .mvn +COPY mvnw pom.xml ./ +COPY src ./src +COPY bot.properties.example bot.properties ./ + +RUN ["chmod", "+x", "./mvnw"] +RUN ./mvnw install + + +FROM eclipse-temurin:17-jre-alpine + +RUN apk add netcat-openbsd +RUN apk add curl WORKDIR /app ARG API_PORT=9000 EXPOSE ${API_PORT} -COPY .mvn/ .mvn -COPY mvnw pom.xml ./ -COPY src ./src COPY bot.properties.example bot.properties ./ COPY startup.sh ./ - -RUN ["chmod", "+x", "./mvnw"] -RUN ./mvnw install +COPY --from=build /target/netneutrality-jar-with-dependencies.jar ./ RUN ["chmod", "+x", "./startup.sh"] CMD ["./startup.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9cbe57e..4a4bdd3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.3' services: db: - image: mariadb:10.7 + image: mariadb:lts container_name: db restart: unless-stopped volumes: diff --git a/startup.sh b/startup.sh index ae06536..916905d 100644 --- a/startup.sh +++ b/startup.sh @@ -1,10 +1,10 @@ -#!/bin/bash +#!/bin/sh -function prop { +prop() { grep "${1}" bot.properties | cut -d'=' -f2 } -function _term() { +_term() { echo "Caught SIGTERM/SIGINT signal, graceful shutdown of bot.." if [ -z "$pid" ]; then echo "Bot isn't running, exiting." @@ -16,10 +16,10 @@ function _term() { fi } -trap _term SIGTERM -trap _term SIGINT +trap _term TERM +trap _term INT -if [ ! -f /bin/nc ]; then +if [ ! -f /usr/bin/nc ]; then echo "nc not found. Exiting." exit 1 fi @@ -40,9 +40,9 @@ echo "Waiting 10 seconds for database to start.." sleep 10 echo "Checking if MySQL / MariaDB is started.." -if /bin/nc -z "$MYSQL_HOST" "$MYSQL_PORT"; then +if /usr/bin/nc -z "$MYSQL_HOST" "$MYSQL_PORT"; then echo "Database OK. Starting bot.."; - /usr/local/openjdk-17/bin/java -jar target/netneutrality-jar-with-dependencies.jar & + /opt/java/openjdk/bin/java -jar /app/netneutrality-jar-with-dependencies.jar & pid=$! wait "$pid"