fix: use PostgreSQL service container in CI instead of Testcontainers
CI — Build, Lint & Security Scan / backend (push) Failing after 48s
CI — Build, Lint & Security Scan / frontend (push) Failing after 1m7s
CI — Build, Lint & Security Scan / image-scan (push) Has been skipped
CI — Build, Lint & Security Scan / secrets-scan (push) Failing after 42s
Deploy to TrueNAS / deploy (push) Successful in 2m52s
CI — Build, Lint & Security Scan / backend (push) Failing after 48s
CI — Build, Lint & Security Scan / frontend (push) Failing after 1m7s
CI — Build, Lint & Security Scan / image-scan (push) Has been skipped
CI — Build, Lint & Security Scan / secrets-scan (push) Failing after 42s
Deploy to TrueNAS / deploy (push) Successful in 2m52s
Testcontainers can't network properly on TrueNAS act-runner (host network vs bridge). Added postgres:16-alpine service container to CI workflow and made AbstractIntegrationTest conditionally skip Testcontainers when CI_POSTGRES_URL env var is present.
This commit is contained in:
@@ -19,6 +19,20 @@ jobs:
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
backend:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
env:
|
||||
POSTGRES_DB: cannamanage_test
|
||||
POSTGRES_USER: test
|
||||
POSTGRES_PASSWORD: test
|
||||
ports:
|
||||
- 5432:5432
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -34,6 +48,10 @@ jobs:
|
||||
|
||||
- name: Maven test
|
||||
run: ./mvnw test -B -T 1C
|
||||
env:
|
||||
CI_POSTGRES_URL: jdbc:postgresql://localhost:5432/cannamanage_test
|
||||
CI_POSTGRES_USER: test
|
||||
CI_POSTGRES_PASSWORD: test
|
||||
|
||||
- name: OWASP Dependency-Check (SCA)
|
||||
run: |
|
||||
|
||||
+22
-7
@@ -42,16 +42,31 @@ import java.util.UUID;
|
||||
public abstract class AbstractIntegrationTest {
|
||||
|
||||
@Container
|
||||
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16-alpine")
|
||||
.withDatabaseName("cannamanage_test")
|
||||
.withUsername("test")
|
||||
.withPassword("test");
|
||||
static PostgreSQLContainer<?> postgres = shouldUseTestcontainers()
|
||||
? new PostgreSQLContainer<>("postgres:16-alpine")
|
||||
.withDatabaseName("cannamanage_test")
|
||||
.withUsername("test")
|
||||
.withPassword("test")
|
||||
: null;
|
||||
|
||||
@DynamicPropertySource
|
||||
static void configureProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.datasource.url", postgres::getJdbcUrl);
|
||||
registry.add("spring.datasource.username", postgres::getUsername);
|
||||
registry.add("spring.datasource.password", postgres::getPassword);
|
||||
if (postgres != null) {
|
||||
registry.add("spring.datasource.url", postgres::getJdbcUrl);
|
||||
registry.add("spring.datasource.username", postgres::getUsername);
|
||||
registry.add("spring.datasource.password", postgres::getPassword);
|
||||
} else {
|
||||
registry.add("spring.datasource.url", () -> System.getenv("CI_POSTGRES_URL"));
|
||||
registry.add("spring.datasource.username", () -> System.getenv("CI_POSTGRES_USER"));
|
||||
registry.add("spring.datasource.password", () -> System.getenv("CI_POSTGRES_PASSWORD"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use Testcontainers locally; skip when CI provides PostgreSQL via service container.
|
||||
*/
|
||||
private static boolean shouldUseTestcontainers() {
|
||||
return System.getenv("CI_POSTGRES_URL") == null;
|
||||
}
|
||||
|
||||
@LocalServerPort
|
||||
|
||||
Reference in New Issue
Block a user