Skip to content

Commit 4a9dc14

Browse files
ravi kakumanuravi kakumanu
authored andcommitted
azurite seed config with cicd variable
1 parent 4ca7855 commit 4a9dc14

File tree

8 files changed

+129
-147
lines changed

8 files changed

+129
-147
lines changed

.github/workflows/ci-draft.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
1818
AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
1919
HMCTS_ADO_PAT: ${{ secrets.HMCTS_CP_ADO_PAT }}
20+
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING}}
2021
with:
2122
is_publish: ${{ github.event_name == 'push' }}
2223
trigger_docker: ${{ github.event_name == 'push' }}

build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,33 @@ tasks.named('jacocoTestReport') {
306306
reports { xml.required.set(true); csv.required.set(false); html.required.set(true) }
307307
}
308308
tasks.named('composeBuild') { dependsOn tasks.named('bootJar') }
309+
dockerCompose {
310+
useComposeFiles = ['docker/docker-compose.integration.yml']
311+
startedServices = ['artemis', 'db', 'azurite', 'azurite-seed', 'wiremock', 'app']
312+
buildBeforeUp = true
313+
forceRecreate = true
314+
removeOrphans = true
315+
removeContainers = true
316+
removeVolumes = true
317+
waitForTcpPorts = true
318+
upAdditionalArgs = ['--wait', '--wait-timeout', '180']
319+
320+
// Explicitly use project.file to avoid the "method not found" error
321+
def envFile = project.file('docker/.env')
322+
if (envFile.exists()) {
323+
envFile.eachLine { line ->
324+
def trimmedLine = line.trim()
325+
if (trimmedLine && !trimmedLine.startsWith('#') && trimmedLine.contains('=')) {
326+
def parts = trimmedLine.split('=', 2)
327+
environment.put(parts[0].trim(), parts[1].trim())
328+
}
329+
}
330+
}
331+
captureContainersOutput = true
332+
projectName = "${rootProject.name}-it".replaceAll('[^A-Za-z0-9]', '')
333+
useDockerComposeV2 = true
334+
dockerExecutable = 'docker'
335+
}
309336

310337
tasks.register('integration', Test) {
311338
description = "Runs integration tests against docker-compose stack"

docker/docker-compose.integration.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ services:
77
- "10000:10000"
88
restart: unless-stopped
99

10+
azurite-seed:
11+
container_name: cdks_azurite_seed
12+
image: mcr.microsoft.com/azure-cli:2.63.0
13+
depends_on:
14+
azurite:
15+
condition: service_started
16+
environment:
17+
AZURE_STORAGE_CONNECTION_STRING: "${AZURE_STORAGE_CONNECTION_STRING}"
18+
volumes:
19+
- ../src/integrationTest/resources/wiremock-seed:/seed:ro
20+
- ../src/integrationTest/resources/wiremock-seed/azurite-seed.sh:/azurite-seed.sh:ro
21+
entrypoint: ["/bin/sh", "/azurite-seed.sh"]
22+
restart: "no"
23+
1024
artemis:
1125
container_name: cdks_artemis
1226
build:
@@ -69,8 +83,8 @@ services:
6983
condition: service_started
7084
wiremock:
7185
condition: service_started
72-
azurite:
73-
condition: service_started
86+
azurite-seed:
87+
condition: service_completed_successfully
7488
ports:
7589
- "8082:8082"
7690
- "5005:5005"
@@ -143,11 +157,12 @@ services:
143157
OTEL_TRACES_URL: http://localhost:4318/traces
144158
OTEL_METRICS_URL: http://localhost:4318/metrics
145159

146-
CP_CDK_AZURE_STORAGE_CONNECTION_STRING: >
147-
DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
148-
AccountKey=Eby8vdM02xNOcqFeqCnf2w==;
149-
BlobEndpoint=http://azurite:10000/devstoreaccount1;
160+
CP_CDK_STORAGE_MODE: connection-string
161+
CP_CDK_AZURE_STORAGE_CONNECTION_STRING: "${AZURE_STORAGE_CONNECTION_STRING}"
150162
CP_CDK_AZURE_STORAGE_CONTAINER: documents
163+
CDK_STORAGE_AZURE_MODE: connection-string
164+
CDK_STORAGE_AZURE_CONNECTION_STRING: "${AZURE_STORAGE_CONNECTION_STRING}"
165+
CDK_STORAGE_AZURE_CONTAINER: documents
151166

152167
CP_CDK_RAG_URL: http://wiremock:8080
153168
CP_CDK_RAG_SUBSCRIPTION_KEY: dummy-key

src/integrationTest/java/uk/gov/hmcts/cp/cdk/http/IngestionProcessHttpLiveTest.java

Lines changed: 29 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

7-
7+
import uk.gov.hmcts.cp.cdk.domain.Answer;
88
import uk.gov.hmcts.cp.cdk.domain.AnswerId;
99
import uk.gov.hmcts.cp.cdk.domain.CaseDocument;
10-
import uk.gov.hmcts.cp.cdk.domain.Answer;
11-
12-
import uk.gov.hmcts.cp.cdk.jobmanager.IngestionProperties;
1310
import uk.gov.hmcts.cp.cdk.testsupport.AbstractHttpLiveTest;
1411
import uk.gov.hmcts.cp.cdk.util.BrokerUtil;
1512

@@ -19,23 +16,21 @@
1916
import java.sql.PreparedStatement;
2017
import java.sql.ResultSet;
2118
import java.sql.SQLException;
19+
import java.time.Duration;
2220
import java.time.OffsetDateTime;
2321
import java.util.List;
24-
2522
import java.util.UUID;
2623

24+
import org.awaitility.Awaitility;
2725
import org.junit.jupiter.api.BeforeAll;
2826
import org.junit.jupiter.api.Test;
2927
import org.junit.jupiter.api.TestInstance;
30-
import org.springframework.beans.factory.annotation.Autowired;
31-
import org.springframework.boot.test.context.SpringBootTest;
3228
import org.springframework.http.HttpEntity;
3329
import org.springframework.http.HttpHeaders;
3430
import org.springframework.http.HttpMethod;
3531
import org.springframework.http.HttpStatus;
3632
import org.springframework.http.MediaType;
3733
import org.springframework.http.ResponseEntity;
38-
import org.springframework.test.context.TestPropertySource;
3934

4035

4136
/**
@@ -282,75 +277,35 @@ void start_ingestion_process_executes_all_tasks_successfully() throws Exception
282277
}
283278

284279
assertNotNull(auditResponse, "Expected audit event after full ingestion task chain");
285-
boolean jmenable = isJobManagerEnabled();
280+
286281
Thread.sleep(60000);
287-
if (jmenable) {
288-
289-
// ---- CaseDocument table validation using JDBC
290-
UUID caseId = UUID.fromString("2204cd6b-5759-473c-b0f7-178b3aa0c9b3");
291-
CaseDocument doc;
292-
try (Connection c = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass);
293-
PreparedStatement ps = c.prepareStatement(
294-
"SELECT doc_id, case_id, material_id, doc_name, blob_uri, uploaded_at " +
295-
"FROM case_documents " +
296-
"WHERE case_id = ? " +
297-
"ORDER BY uploaded_at DESC " +
298-
"LIMIT 1"
299-
)) {
300-
ps.setObject(1, caseId);
301-
try (ResultSet rs = ps.executeQuery()) {
302-
assertTrue(rs.next(), "Expected at least one CaseDocument for the case");
303-
304-
doc = new CaseDocument();
305-
doc.setDocId((UUID) rs.getObject("doc_id"));
306-
doc.setCaseId((UUID) rs.getObject("case_id"));
307-
doc.setMaterialId((UUID) rs.getObject("material_id"));
308-
doc.setDocName(rs.getString("doc_name"));
309-
doc.setBlobUri(rs.getString("blob_uri"));
310-
doc.setUploadedAt(rs.getObject("uploaded_at", OffsetDateTime.class));
311-
}
312-
}
282+
UUID caseId = UUID.fromString("2204cd6b-5759-473c-b0f7-178b3aa0c9b3");
283+
UUID queryId = UUID.fromString("2a9ae797-7f70-4be5-927f-2dae65489e69");
284+
285+
286+
final HttpHeaders answerHeaders = new HttpHeaders();
287+
answerHeaders.setAccept(List.of(
288+
MediaType.valueOf("application/vnd.casedocumentknowledge-service.answers+json")
289+
));
290+
291+
Awaitility.await()
292+
.atMost(Duration.ofSeconds(120))
293+
.untilAsserted(() -> {
294+
295+
ResponseEntity<String> answerResponse = http.exchange(
296+
baseUrl + "/answers/" + caseId + "/" + queryId,
297+
HttpMethod.GET,
298+
new HttpEntity<>(answerHeaders),
299+
String.class
300+
);
301+
302+
assertThat(answerResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
303+
assertThat(answerResponse.getBody()).isNotNull();
304+
assertThat(answerResponse.getBody()).contains("\"answer\"");
305+
assertThat(answerResponse.getBody()).contains("\"version\"");
306+
});
313307

314-
assertThat(doc.getBlobUri()).isNotBlank();
315-
assertThat(doc.getDocName()).isNotBlank();
316-
assertThat(doc.getMaterialId()).isNotNull();
317-
assertThat(doc.getUploadedAt()).isNotNull();
318-
319-
// ---- Answer table validation using JDBC
320-
UUID queryId = UUID.fromString("2a9ae797-7f70-4be5-927f-2dae65489e69");
321-
Answer answer;
322-
323-
try (Connection c = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPass);
324-
PreparedStatement ps = c.prepareStatement(
325-
"SELECT case_id, query_id, version, created_at, answer, doc_id " +
326-
"FROM answers " +
327-
"WHERE case_id = ? AND query_id = ? " +
328-
"ORDER BY created_at DESC, version DESC " +
329-
"LIMIT 1"
330-
)) {
331-
ps.setObject(1, caseId);
332-
ps.setObject(2, queryId);
333-
334-
try (ResultSet rs = ps.executeQuery()) {
335-
assertTrue(rs.next(), "Expected at least one Answer for the case and query");
336-
337-
answer = new Answer();
338-
AnswerId answerId = new AnswerId();
339-
answerId.setCaseId((UUID) rs.getObject("case_id"));
340-
answerId.setQueryId((UUID) rs.getObject("query_id"));
341-
answerId.setVersion(rs.getInt("version"));
342-
answer.setAnswerId(answerId);
343-
344-
answer.setCreatedAt(rs.getObject("created_at", OffsetDateTime.class));
345-
answer.setAnswerText(rs.getString("answer"));
346-
answer.setDocId((UUID) rs.getObject("doc_id"));
347-
}
348-
}
349308

350-
assertThat(answer.getAnswerText()).isNotBlank();
351-
assertThat(answer.getCreatedAt()).isNotNull();
352-
assertThat(answer.getDocId()).isNotNull();
353-
}
354309
}
355310

356311

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
CS="${AZURE_STORAGE_CONNECTION_STRING}"
5+
6+
echo "Waiting for Azurite..."
7+
i=0
8+
until az storage container list --connection-string "$CS" >/dev/null 2>&1; do
9+
i=$((i+1))
10+
[ "$i" -lt 60 ] || { echo "Azurite not ready"; exit 1; }
11+
sleep 1
12+
done
13+
14+
echo "Creating documents container..."
15+
az storage container create \
16+
--name documents \
17+
--public-access blob \
18+
--connection-string "$CS" >/dev/null
19+
20+
echo "Enforcing public access..."
21+
az storage container set-permission \
22+
--name documents \
23+
--public-access blob \
24+
--connection-string "$CS" >/dev/null
25+
26+
echo "Uploading source.pdf..."
27+
[ -f /seed/source.pdf ] || { echo "Missing /seed/source.pdf"; ls -la /seed; exit 1; }
28+
29+
az storage blob upload \
30+
--overwrite true \
31+
--container-name documents \
32+
--name source.pdf \
33+
--file /seed/source.pdf \
34+
--content-type application/pdf \
35+
--connection-string "$CS" >/dev/null
36+
37+
echo "Verifying source blob exists..."
38+
az storage blob show \
39+
--container-name documents \
40+
--name source.pdf \
41+
--connection-string "$CS" >/dev/null
42+
43+
ACL="$(az storage container show --name documents --connection-string "$CS" --query properties.publicAccess -o tsv || true)"
44+
echo "documents publicAccess=$ACL"
45+
46+
echo "Seeded URL: http://azurite:10000/devstoreaccount1/documents/source.pdf"
252 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)