From e2907e83ba3f83425f2a0f94a784f05643ac5c32 Mon Sep 17 00:00:00 2001 From: "Sanders (aider)" Date: Fri, 14 Feb 2025 10:38:38 +0300 Subject: [PATCH] feat: Add Docker setup with environment variable configuration --- .dockerignore | 6 ++++++ .gitignore | 2 ++ Dockerfile | 21 +++++++++++++++++++ .../resources/application-secrets.properties | 10 ++++----- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..42796a2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.gitignore +target +*.iml +.idea +*.md diff --git a/.gitignore b/.gitignore index cb07dea..db7f6dc 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,5 @@ out/ ### Secret configurations ### ###src/main/resources/application-secrets.properties *.secrets.* +# Docker +*.jar diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..096d7fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# Сборка приложения +FROM maven:3.8.6-openjdk-11 AS build +WORKDIR /app +COPY pom.xml . +COPY src ./src +RUN mvn clean package -DskipTests + +# Запуск приложения +FROM openjdk:11-jre-slim +WORKDIR /app +COPY --from=build /app/target/*.jar app.jar + +# Переменные окружения для конфигурации +ENV SPRING_DATASOURCE_URL=${DB_URL} +ENV SPRING_DATASOURCE_USERNAME=${DB_USER} +ENV SPRING_DATASOURCE_PASSWORD=${DB_PASSWORD} +ENV BOT_TOKEN=${BOT_TOKEN} +ENV BOT_NAME=${BOT_NAME} + +EXPOSE 8080 +ENTRYPOINT ["java","-jar","app.jar"] diff --git a/src/main/resources/application-secrets.properties b/src/main/resources/application-secrets.properties index 34a91e7..1bea10d 100644 --- a/src/main/resources/application-secrets.properties +++ b/src/main/resources/application-secrets.properties @@ -1,8 +1,8 @@ # Telegram configuration -bot.token=5908676914:AAGU9LVyXYZYafpRgwOf1tolk0HGYvcHszY -bot.name=TelegaBot +bot.token=${BOT_TOKEN:5908676914:AAGU9LVyXYZYafpRgwOf1tolk0HGYvcHszY} +bot.name=${BOT_NAME:TelegaBot} # Database configuration -spring.datasource.url=jdbc:postgresql://192.168.0.10:5432/telegabot -spring.datasource.username=postgres -spring.datasource.password=Vftrixpo05 \ No newline at end of file +spring.datasource.url=${DB_URL:jdbc:postgresql://192.168.0.10:5432/telegabot} +spring.datasource.username=${DB_USER:postgres} +spring.datasource.password=${DB_PASSWORD:Vftrixpo05}