diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..afc0c75 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM maven:4.0.0-rc-4-eclipse-temurin-21-alpine AS build +WORKDIR /app + +# separate dependency stage to reduce build time when dependencies are unchanged +COPY pom.xml . +RUN mvn dependency:go-offline -B + +COPY src ./src +# issues when not skipping, idk why +RUN mvn clean package -DskipTests + +# openjdk is now deprecated over temurin +FROM eclipse-temurin:21-jre-alpine +WORKDIR /app +COPY --from=build /app/target/*.jar app.jar +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b33d558 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +services: + postgres: + image: postgres:18-alpine + container_name: itse-b08-database + environment: + POSTGRES_DB: pw_demo + POSTGRES_USER: pw_demo + POSTGRES_PASSWORD: pw_demo + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + - ./init-scripts:/docker-entrypoint-initdb.d + healthcheck: + test: ["CMD-SHELL", "pg_isready -U myuser -d myappdb"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - app-network + + app: + build: + context: . + dockerfile: Dockerfile + container_name: itse-b08-spring + depends_on: + postgres: + condition: service_healthy + environment: + SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/pw_demo + SPRING_DATASOURCE_USERNAME: pw_demo + SPRING_DATASOURCE_PASSWORD: pw_demo + SPRING_JPA_HIBERNATE_DDL_AUTO: update + ports: + - "8080:8080" + networks: + - app-network + +volumes: + postgres_data: + +networks: + app-network: + driver: bridge \ No newline at end of file diff --git a/init-scripts/init.sql b/init-scripts/init.sql new file mode 100644 index 0000000..2194156 --- /dev/null +++ b/init-scripts/init.sql @@ -0,0 +1,13 @@ +CREATE TABLE IF NOT EXISTS users ( + username VARCHAR(50) NOT NULL PRIMARY KEY, + password VARCHAR(500) NOT NULL, + enabled BOOLEAN NOT NULL +); + +CREATE TABLE IF NOT EXISTS authorities ( + username VARCHAR(50) NOT NULL, + authority VARCHAR(50) NOT NULL, + CONSTRAINT fk_authorities_users FOREIGN KEY (username) REFERENCES users(username) +); + +CREATE UNIQUE INDEX IF NOT EXISTS ix_auth_username ON authorities (username, authority); \ No newline at end of file