Skip to content

Commit 8dbdfa9

Browse files
committed
feat: run global test in CI
1 parent 2fb27c7 commit 8dbdfa9

File tree

5 files changed

+60
-14
lines changed

5 files changed

+60
-14
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,13 @@ jobs:
8181
if: ${{ hashFiles('Data/*') == '' }}
8282
run: make download-soil-data
8383

84+
- name: Start soil id DB
85+
run: docker compose up -d
86+
8487
- name: Run tests
88+
env:
89+
DB_NAME: soil_id
90+
DB_HOST: localhost
91+
DB_USERNAME: postgres
92+
DB_PASSWORD: postgres
8593
run: make test

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Stage 1: Build database with preloaded data
2+
FROM postgis/postgis:16-3.5 as builder
3+
4+
ENV POSTGRES_DB=soil_id
5+
ENV POSTGRES_USER=postgres
6+
ENV POSTGRES_PASSWORD=postgres
7+
8+
# Copy dump into builder stage
9+
COPY Data/soil_id_db.dump /tmp/soil_id_db.dump
10+
11+
# Initialize database and preload it
12+
RUN mkdir -p /var/lib/postgresql/data \
13+
&& chown -R postgres:postgres /var/lib/postgresql
14+
15+
USER postgres
16+
17+
# Initialize database system
18+
RUN /usr/lib/postgresql/16/bin/initdb -D /var/lib/postgresql/data
19+
20+
# Start database in background, preload dump, shut it down
21+
RUN pg_ctl -D /var/lib/postgresql/data -o "-c listen_addresses=''" -w start \
22+
&& createdb -U postgres soil_id \
23+
&& psql -U postgres -d $POSTGRES_DB -c "CREATE EXTENSION postgis;" \
24+
&& pg_restore -U postgres -d soil_id /tmp/soil_id_db.dump \
25+
&& pg_ctl -D /var/lib/postgresql/data -m fast -w stop
26+
27+
# Stage 2: Final image with loaded data
28+
FROM postgis/postgis:16-3.5
29+
30+
COPY --from=builder /var/lib/postgresql/data /var/lib/postgresql/data
31+
32+
# Create a Docker-friendly pg_hba.conf
33+
USER root
34+
RUN echo "local all all trust" > /var/lib/postgresql/data/pg_hba.conf \
35+
&& echo "host all all 127.0.0.1/32 trust" >> /var/lib/postgresql/data/pg_hba.conf \
36+
&& echo "host all all ::1/128 trust" >> /var/lib/postgresql/data/pg_hba.conf \
37+
&& echo "host all all 0.0.0.0/0 trust" >> /var/lib/postgresql/data/pg_hba.conf \
38+
&& chown postgres:postgres /var/lib/postgresql/data/pg_hba.conf
39+
40+
ENV POSTGRES_DB=soil_id
41+
ENV POSTGRES_USER=postgres
42+
ENV POSTGRES_PASSWORD=postgres
43+
44+
USER postgres

docker-compose.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
name: soil_data
1+
name: soil_id
22

33
services:
44
db:
5-
image: postgis/postgis:16-3.5
5+
image: ghcr.io/techmatters/soil-id-db:0.2
66
ports:
77
- "5432:5432"
88
environment:
99
POSTGRES_USER: postgres
1010
POSTGRES_PASSWORD: postgres
11-
POSTGRES_DB: soil_data # default database
12-
volumes:
13-
- pg_data:/var/lib/postgresql/data
14-
15-
volumes:
16-
pg_data:
11+
POSTGRES_DB: soil_id # default database

soil_id/global_soil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ def normalize(arr):
12601260
##################################################################################################
12611261

12621262

1263-
def sg_list(lon, lat):
1263+
def sg_list(connection, lon, lat):
12641264
"""
12651265
Query the SoilGrids API (via get_soilgrids_property_data) and post-process
12661266
the returned JSON into a structured dictionary that includes:
@@ -1395,7 +1395,7 @@ def sg_list(lon, lat):
13951395
sg_tax_prob.sort_values("Prob", ascending=False, inplace=True)
13961396

13971397
# Merge with descriptive info
1398-
WRB_Comp_Desc = getSG_descriptions(sg_tax_prob["WRB_tax"].tolist())
1398+
WRB_Comp_Desc = getSG_descriptions(connection, sg_tax_prob["WRB_tax"].tolist())
13991399
TAXNWRB_pd = pd.merge(sg_tax_prob, WRB_Comp_Desc, on="WRB_tax", how="left")
14001400

14011401
# Only handle top 3 entries (or fewer if less are returned)

soil_id/tests/global/test_global.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919

2020
from soil_id.db import get_datastore_connection
21-
from soil_id.global_soil import list_soils_global, rank_soils_global, sg_list
21+
from soil_id.global_soil import list_soils_global, rank_soils_global
2222

2323
test_locations = [
2424
{"lon": -1.4631, "lat": 7.3318},
@@ -27,7 +27,6 @@
2727
{"lat": -10.07856, "lon": 15.107436},
2828
]
2929

30-
@pytest.mark.skip
3130
@pytest.mark.parametrize("location", test_locations)
3231
def test_soil_location(location):
3332
with get_datastore_connection() as connection:
@@ -41,10 +40,10 @@ def test_soil_location(location):
4140
location["lat"],
4241
list_output_data=list_soils_result,
4342
soilHorizon=["Loam"],
44-
horizonDepth=[15],
43+
topDepth=[0],
44+
bottomDepth=[15],
4545
rfvDepth=[20],
4646
lab_Color=[[41.23035939, 3.623018224, 13.27654356]],
4747
bedrock=None,
4848
cracks=None,
4949
)
50-
sg_list(location["lon"], location["lat"])

0 commit comments

Comments
 (0)