generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added local DB (PostgreSQL) - Added Flyway - Enabled JPA
- Loading branch information
1 parent
1ab1fee
commit 89b8088
Showing
10 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
FROM --platform=$BUILDPLATFORM eclipse-temurin:21-jdk-jammy AS builder | ||
|
||
ARG BUILD_NUMBER | ||
ENV BUILD_NUMBER ${BUILD_NUMBER:-1_0_0} | ||
ENV BUILD_NUMBER=${BUILD_NUMBER:-1_0_0} | ||
|
||
WORKDIR /app | ||
ADD . . | ||
|
@@ -11,7 +11,7 @@ FROM eclipse-temurin:21-jre-jammy | |
LABEL maintainer="HMPPS Digital Studio <[email protected]>" | ||
|
||
ARG BUILD_NUMBER | ||
ENV BUILD_NUMBER ${BUILD_NUMBER:-1_0_0} | ||
ENV BUILD_NUMBER=${BUILD_NUMBER:-1_0_0} | ||
|
||
RUN apt-get update && \ | ||
apt-get -y upgrade && \ | ||
|
@@ -23,6 +23,10 @@ RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezo | |
RUN addgroup --gid 2000 --system appgroup && \ | ||
adduser --uid 2000 --system appuser --gid 2000 | ||
|
||
# Install AWS RDS Root cert into Java truststore | ||
RUN mkdir /home/appuser/.postgresql | ||
ADD --chown=appuser:appgroup https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /home/appuser/.postgresql/root.crt | ||
|
||
WORKDIR /app | ||
COPY --from=builder --chown=appuser:appgroup /app/build/libs/hmpps-jobs-board-integration-api*.jar /app/app.jar | ||
COPY --from=builder --chown=appuser:appgroup /app/build/libs/applicationinsights-agent*.jar /app/agent.jar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ice/digital/hmpps/jobsboardintegrationapi/integration/testcontainers/PostgresContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package uk.gov.justice.digital.hmpps.jobsboardintegrationapi.integration.testcontainers | ||
|
||
import org.slf4j.LoggerFactory | ||
import org.testcontainers.containers.PostgreSQLContainer | ||
import org.testcontainers.containers.wait.strategy.Wait | ||
import java.io.IOException | ||
import java.net.ServerSocket | ||
|
||
object PostgresContainer { | ||
val flywayContainer: PostgreSQLContainer<Nothing>? by lazy { startPostgresqlContainer() } | ||
val repositoryContainer: PostgreSQLContainer<Nothing>? by lazy { startPostgresqlContainer() } | ||
|
||
private fun startPostgresqlContainer(): PostgreSQLContainer<Nothing>? { | ||
if (isPostgresRunning()) { | ||
log.warn("Using existing PostgreSQL database") | ||
return null | ||
} | ||
|
||
log.info("Creating a TestContainers PostgreSQL database") | ||
|
||
return PostgreSQLContainer<Nothing>("postgres:16.3").apply { | ||
withEnv("HOSTNAME_EXTERNAL", "localhost") | ||
withDatabaseName("job-board-intg") | ||
withUsername("job-board-intg") | ||
withPassword("job-board-intg") | ||
setWaitStrategy(Wait.forListeningPort()) | ||
withReuse(true) | ||
start() | ||
} | ||
} | ||
|
||
private fun isPostgresRunning(): Boolean = | ||
try { | ||
val serverSocket = ServerSocket(5432) | ||
serverSocket.localPort == 0 | ||
} catch (error: IOException) { | ||
log.warn("A PostgreSQL database is running") | ||
true | ||
} | ||
|
||
private val log = LoggerFactory.getLogger(this::class.java) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters