Docker compose for scala and postgres

This commit is contained in:
Guntis Smaukstelis
2023-12-19 14:47:45 +02:00
parent 69458131bd
commit d08422f929
4 changed files with 53 additions and 2 deletions
-1
View File
@@ -1,5 +1,4 @@
# flyctl launch added from .gitignore # flyctl launch added from .gitignore
**/src/main/resources/application.conf
**/project/target **/project/target
**/project/project/target **/project/project/target
+29
View File
@@ -0,0 +1,29 @@
# Use a base image with Java and Scala, including SBT
FROM hseeberger/scala-sbt:17.0.2_1.6.2_2.13.8 as build
# Set the working directory
WORKDIR /app
# Copy project files to the Docker image
COPY . /app
# Compile the application
RUN sbt clean assembly
# Use a smaller base image for the final image
FROM amazoncorretto:17-alpine
# Copy the compiled JAR from the build stage
COPY --from=build /app/target/scala-2.13/WeatherTool-assembly-0.1.1-SNAPSHOT.jar /app.jar
# Define the volume to persist data
VOLUME /data
# Command to run the application
CMD ["java", "-jar", "/app.jar"]
# docker build -t scala-app .
# docker run -v /local/data/path:/data scala-app
+23
View File
@@ -0,0 +1,23 @@
version: '3'
services:
postgres:
image: postgres:latest
ports:
- "5432:5432"
environment:
POSTGRES_DB: weather-tool
POSTGRES_USER: postgres
POSTGRES_PASSWORD: mysecretpassword
volumes:
- /var/lib/postgresql/data:/var/lib/postgresql/data
scala-app:
build:
context: .
dockerfile: Dockerfile.local
volumes:
- $PWD:/app
ports:
- "8080:8080"
depends_on:
- postgres
+1 -1
View File
@@ -13,7 +13,7 @@ case class PostgresConfig(url: String, username: String, password: String)
object DBConnection { object DBConnection {
private def getDatabaseUrl: String = private def getDatabaseUrl: String =
sys.env.getOrElse("DATABASE_URL", "postgres://postgres:mysecretpassword@localhost:5432/weather-tool") sys.env.getOrElse("DATABASE_URL", "postgres://postgres:mysecretpassword@postgres:5432/weather-tool")
private def parseUrl(url: String): Either[String, PostgresConfig] = { private def parseUrl(url: String): Either[String, PostgresConfig] = {
Try { Try {