-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ESWE-1181] Add DB (PostgreSQL) #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,13 @@ ext["logback.version"] = "1.5.15" | |
dependencies { | ||
implementation("uk.gov.justice.service.hmpps:hmpps-kotlin-spring-boot-starter:1.1.1") | ||
implementation("uk.gov.justice.service.hmpps:hmpps-sqs-spring-boot-starter:5.2.2") | ||
implementation("org.springframework.boot:spring-boot-starter-data-jpa") | ||
implementation("org.springframework.boot:spring-boot-starter-webflux") | ||
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0") | ||
|
||
runtimeOnly("org.flywaydb:flyway-database-postgresql") | ||
runtimeOnly("org.postgresql:postgresql") | ||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using Flyway with PostgreSQL |
||
|
||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") | ||
} | ||
|
||
|
@@ -45,6 +49,7 @@ testing { | |
implementation("org.apache.commons:commons-compress:1.27.1") | ||
} | ||
implementation("org.testcontainers:localstack") | ||
implementation("org.testcontainers:postgresql") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. running PostgreSQL container for integration tests |
||
implementation("org.jetbrains.kotlin:kotlin-test-junit5") | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,11 @@ generic-service: | |
MN_JOBBOARD_API_TOKEN: "MN_JOBBOARD_API_TOKEN" | ||
application-insights: | ||
APPLICATIONINSIGHTS_CONNECTION_STRING: "APPLICATIONINSIGHTS_CONNECTION_STRING" | ||
rds-postgresql-instance-output: | ||
DATABASE_USERNAME: "database_username" | ||
DATABASE_PASSWORD: "database_password" | ||
DATABASE_NAME: "database_name" | ||
DATABASE_ENDPOINT: "rds_instance_endpoint" | ||
Comment on lines
+39
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pull in DB parameters from secrets (prepared before during DB bootstrap with TF) |
||
|
||
allowlist: | ||
groups: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import org.springframework.test.context.bean.override.mockito.MockitoSpyBean | |
import org.springframework.test.web.reactive.server.WebTestClient | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.integration.testcontainers.LocalStackContainer | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.integration.testcontainers.LocalStackContainer.setLocalStackProperties | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.integration.testcontainers.PostgresContainer | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.integration.wiremock.ExampleApiExtension | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.integration.wiremock.ExampleApiExtension.Companion.exampleApi | ||
import uk.gov.justice.digital.hmpps.jobsboardintegrationapi.integration.wiremock.HmppsAuthApiExtension | ||
|
@@ -54,10 +55,20 @@ abstract class IntegrationTestBase { | |
|
||
companion object { | ||
private val localStackContainer by lazy { LocalStackContainer.instance } | ||
private val postgresContainer = PostgresContainer.flywayContainer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. provide a postgreSQL for integration tests with Flyway enabled |
||
|
||
@JvmStatic | ||
@DynamicPropertySource | ||
fun configureTestContainers(registry: DynamicPropertyRegistry) { | ||
postgresContainer?.run { | ||
registry.add("spring.datasource.url", postgresContainer::getJdbcUrl) | ||
registry.add("spring.datasource.username", postgresContainer::getUsername) | ||
registry.add("spring.datasource.password", postgresContainer::getPassword) | ||
registry.add("spring.flyway.url", postgresContainer::getJdbcUrl) | ||
registry.add("spring.flyway.user", postgresContainer::getUsername) | ||
registry.add("spring.flyway.password", postgresContainer::getPassword) | ||
} | ||
|
||
localStackContainer?.also { setLocalStackProperties(it, registry) } | ||
} | ||
} | ||
|
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() } | ||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using two different postgreSQL containers for different integration tests (with or without Flyway) |
||
|
||
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) | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for integration tests with Flyway |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for local run with DB |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enable Flyway by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add JPA