Skip to content

Commit e462253

Browse files
committed
fix ci
1 parent 0b726a8 commit e462253

File tree

8 files changed

+177
-137
lines changed

8 files changed

+177
-137
lines changed

.github/workflows/civ2.yml

Lines changed: 111 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,118 @@ jobs:
8282
cache-from: type=gha
8383
cache-to: type=gha, mode=max
8484

85-
# test:
86-
# runs-on: ubuntu-latest
87-
# steps:
88-
# - uses: actions/checkout@v4
89-
# - uses: docker/setup-buildx-action@v3
90-
# - name: Build and Cache Docker layers
91-
# uses: docker/bake-action@master
92-
# with:
93-
# push: false
94-
# load: true
95-
# allow:
96-
# network.host
97-
# files: |-
98-
# docker-compose.yml
99-
# docker-compose-cache.json
100-
# - name: Run docker compose
101-
# run: |
102-
# docker compose up -d pgstac
85+
check-pypgstac-base:
86+
runs-on: ubuntu-latest
87+
permissions:
88+
pull-requests: read
89+
outputs:
90+
pypgstac-image-exists: ${{ steps.pypgstac_image_check.outputs.pypgstac-image-exists }}
91+
pypgstac-image-hash: ${{ steps.pypgstac_image_check.outputs.pypgstac-image-hash }}
92+
93+
steps:
94+
- uses: actions/checkout@v4
95+
- name: Check if pypgstac-base docker image needs to be updated
96+
id: pypgstac_image_check
97+
run: |
98+
set -e
99+
IMAGE=stac-utils/pypgstac-base
100+
HASH=$(git log -1 --pretty="format:%h" -- docker/pypgstac)
101+
TAG="\"$HASH\""
102+
TOKEN=$(curl -s https://ghcr.io/token\?scope\="repository:$IMAGE:pull" | jq -r .token)
103+
EXISTS=$(curl -s -H "Authorization: Bearer $TOKEN" https://ghcr.io/v2/$IMAGE/tags/list | jq "try(any(.tags[]; . == $TAG))")
104+
echo "pypgstac-image-exists=$EXISTS" >>$GITHUB_OUTPUT
105+
echo "pypgstac-image-hash=$HASH" >>$GITHUB_OUTPUT
106+
echo "pypgstac-image-exists: $EXISTS"
107+
echo "pypgstac-image-hash: $HASH"
103108
104-
# - name: Execute tests in the running services
105-
# run: |
106-
# scripts/test --nobuild
109+
buildpypgstacbase:
110+
name: Build and push base postgres image
111+
needs: [check-pypgstac-base]
112+
if: ${{ needs.check-pypgstac-base.outputs.pypgstac-image-exists != 'true' }}
113+
runs-on: ubuntu-latest
114+
steps:
115+
- name: Display inputs
116+
run: |
117+
echo "Inputs:"
118+
echo ${{ needs.check-pypgstac-base.outputs.pypgstac-image-exists }}
119+
echo ${{ needs.check-pypgstac-base.outputs.pypgstac-image-hash }}
120+
- uses: actions/checkout@v4
121+
- uses: docker/setup-buildx-action@v3
122+
- name: Log in to the Container registry
123+
uses: docker/login-action@v3
124+
with:
125+
registry: ${{ env.REGISTRY }}
126+
username: ${{ github.actor }}
127+
password: ${{ secrets.GITHUB_TOKEN }}
128+
- name: Build and Push Base Postgres
129+
uses: docker/build-push-action@v6
130+
with:
131+
platforms: linux/amd64
132+
context: .
133+
target: pypgstac-base
134+
file: docker/pgstac/Dockerfile
135+
tags: ghcr.io/stac-utils/pypgstac-base:${{ needs.check-pypgstac-base.outputs.pypgstac-image-hash }}
136+
push: true
137+
cache-from: type=gha
138+
cache-to: type=gha, mode=max
139+
wheels:
140+
runs-on: ubuntu-latest
141+
steps:
142+
- uses: actions/checkout@v4
143+
- name: Build wheels
144+
uses: PyO3/maturin-action@v1
145+
with:
146+
working-directory: src/pypgstac
147+
target: x86_64
148+
args: --release --out /home/runner/work/pgstac/pgstac/dist
149+
sccache: 'true'
150+
manylinux: auto
151+
- name: Upload wheels
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: wheels
155+
path: /home/runner/work/pgstac/pgstac/dist/*
156+
if-no-files-found: error
157+
test:
158+
needs: [buildpg, buildpypgstacbase, wheels]
159+
if: ${{ always() && !failure() && !cancelled() }}
160+
runs-on: ubuntu-latest
161+
container: ghcr.io/stac-utils/pypgstac-base:${{ needs.check-pypgstac-base.outputs.pypgstac-image-hash }}
162+
env:
163+
PGHOST: localhost
164+
PGUSER: postgres
165+
PGPASSWORD: postgres
166+
PGDATABASE: postgres
167+
services:
168+
pg:
169+
image: ghcr.io/stac-utils/pgstac-base:${{ needs.check-pgstac-base.outputs.pgstac-image-hash }}
170+
env:
171+
POSTGRES_PASSWORD: postgres
172+
POSTGRES_USER: postgres
173+
POSTGRES_DATABASE: postgres
174+
options: >-
175+
--health-cmd pg_isready
176+
--health-interval 10s
177+
--health-timeout 5s
178+
--health-retries 5
107179
108-
# - name: Stop Docker
109-
# run: |
110-
# scripts/nuke
180+
steps:
181+
- uses: actions/checkout@v4
182+
- name: Get Wheel
183+
uses: actions/download-artifact@v4
184+
with:
185+
name: wheels
186+
path: /tmp/wheels
187+
- name: Install pypgstac
188+
run: |
189+
cd /home/runner/work/pgstac/pgstac/src/pypgstac
190+
source $UV_PROJECT_ENVIRONMENT/bin/activate
191+
uv pip install --offline --find-links /tmp/wheels pypgstac
192+
- name: Run tests
193+
run: |
194+
cd /home/runner/work/pgstac/pgstac/src/pypgstac
195+
source $UV_PROJECT_ENVIRONMENT/bin/activate
196+
$SCRIPTS/test
111197
112198
# linux_x86_64:
113199
# runs-on: ubuntu-latest
@@ -218,54 +304,4 @@ jobs:
218304
# path: /home/runner/work/pgstac/pgstac/dist/*
219305
# if-no-files-found: error
220306

221-
# test:
222-
# name: test
223-
# needs: [buildpg, linux_x86_64]
224-
# runs-on: ubuntu-latest
225-
# container:
226-
# env:
227-
# PGHOST: localhost
228-
# UV_FROZEN: true
229-
# UV_FIND_LINKS: /tmp/wheels
230-
# UV_PROJECT_ENVIRONMENT: /home/runner/work/pgstac/pgstac/src/pypgstac/.venv
231-
# VIRTUAL_ENVIRONMENT: /home/runner/work/pgstac/pgstac/src/pypgstac/.venv
232-
233-
# services:
234-
# postgres:
235-
# image: ghcr.io/stac-utils/pgstac-postgres:latest
236-
# env:
237-
# POSTGRES_PASSWORD: postgres
238-
# POSTGRES_USER: postgres
239-
# POSTGRES_DATABASE: postgres
240-
# options: >-
241-
# --health-cmd pg_isready
242-
# --health-interval 10s
243-
# --health-timeout 5s
244-
# --health-retries 5
245-
246-
# steps:
247-
# - uses: actions/checkout@v4
248-
# - name: Setup UV
249-
# uses: astral-sh/setup-uv@v3
250-
# with:
251-
# enable-cache: true
252-
# - name: Get Wheel
253-
# uses: actions/download-artifact@v4
254-
# with:
255-
# name: wheels-x86_64
256-
# path: /tmp/wheels
257-
# - name: Install pypgstac
258-
# run: |
259-
# cd /home/runner/work/pgstac/pgstac/src/pypgstac
260-
# uv venv
261-
# source $UV_PROJECT_ENVIRONMENT/bin/activate
262-
# uv pip install psycopg[binary] psycopg-pool
263-
# uv sync --frozen --no-install-project --extra test --extra dev
264-
# uv pip install --offline --find-links /tmp/wheels pypgstac
265-
266-
267-
# - name: Run tests
268-
# run: |
269-
# cd /home/runner/work/pgstac/pgstac/src/pypgstac
270-
# source $UV_PROJECT_ENVIRONMENT/bin/activate
271-
# $SCRIPTS/test
307+
#

docker/pgstac/Dockerfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
ARG PG_MAJOR=15
1+
ARG PG_MAJOR=16
22
ARG POSTGIS_MAJOR=3
33

44
# Base postgres image that pgstac can be installed onto
5-
FROM postgres:${PG_MAJOR}-bullseye AS pgstacbase
5+
FROM postgres:${PG_MAJOR}-bookworm AS pgstacbase
66
ARG POSTGIS_MAJOR
77
RUN \
88
apt-get update \
@@ -20,11 +20,12 @@ COPY docker/pgstac/dbinit/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.
2020

2121
# Base postgres image with plrust installed that can be used for future development using plrust
2222
FROM pgstacbase AS pgstacbase-plrust
23-
ENV PLRUSTVERSION=1.2.7
24-
ENV RUSTVERSION=1.72.0
25-
ENV PLRUSTDOWNLOADURL=https://github.com/tcdi/plrust/releases/download/
26-
ENV PLRUSTFILE=plrust-trusted-${PLRUSTVERSION}_${RUSTVERSION}-debian-pg${PG_MAJOR}-amd64.deb
27-
ENV PLRUSTURL=${PLRUSTDOWNLOADURL}v${PLRUSTVERSION}/${PLRUSTFILE}
23+
ENV \
24+
PLRUSTVERSION=1.2.7 \
25+
RUSTVERSION=1.72.0 \
26+
PLRUSTDOWNLOADURL=https://github.com/tcdi/plrust/releases/download/ \
27+
PLRUSTFILE=plrust-trusted-${PLRUSTVERSION}_${RUSTVERSION}-debian-pg${PG_MAJOR}-amd64.deb \
28+
PLRUSTURL=${PLRUSTDOWNLOADURL}v${PLRUSTVERSION}/${PLRUSTFILE}
2829
ADD $PLRUSTURL .
2930
ENV PATH=/home/postgres/.cargo/bin:$PATH
3031
RUN \

docker/pypgstac/Dockerfile

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
ARG UV_VERSION=latest
2-
ARG PY_VERSION=3.12
3-
1+
# Image used to build wheels for pypgstac
42
FROM ghcr.io/pyo3/maturin AS pypgstacbuilder
53
WORKDIR /io
64
RUN --mount=type=bind,source=./src/pypgstac,target=/io \
@@ -10,7 +8,8 @@ RUN --mount=type=bind,source=./src/pypgstac,target=/io \
108
ENTRYPOINT []
119
CMD []
1210

13-
FROM ghcr.io/astral-sh/uv:python3.9-bookworm-slim AS pypgstac-slim
11+
# Image that contains pypgstac but not psql, dev, or test
12+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS pypgstac-slim-base
1413
ENV \
1514
UV_LINK_MODE=copy \
1615
UV_COMPILE_BYTECODE=1 \
@@ -24,22 +23,14 @@ RUN \
2423
--mount=type=bind,source=./src/pypgstac/uv.lock,target=/opt/src/pypgstac/uv.lock \
2524
--mount=type=bind,source=./src/pypgstac/pyproject.toml,target=/opt/src/pypgstac/pyproject.toml \
2625
uv venv --allow-existing --relocatable /venv \
27-
&& uv sync --frozen --no-install-project \
28-
&& uv pip install psycopg[binary] psycopg-pool
29-
30-
RUN --mount=type=bind,from=pypgstacbuilder,source=/wheels,target=/wheels \
31-
for i in /wheels/pypgstac*x86_64.whl; do uv pip install pypgstac@$i; done
26+
&& uv sync --frozen --no-install-project --extra psycopg
3227

3328
ENTRYPOINT []
3429
CMD ["/bin/true"]
3530

36-
FROM ghcr.io/astral-sh/uv:python3.9-bookworm-slim AS pypgstac
31+
# Base image with psql and all dependencies
32+
FROM pypgstac-slim-base AS pypgstac-base
3733
ENV \
38-
UV_LINK_MODE=copy \
39-
UV_COMPILE_BYTECODE=1 \
40-
UV_PROJECT_ENVIRONMENT=/venv \
41-
UV_PYTHON_INSTALL_DIR=/venv/bin \
42-
VIRTUAL_ENVIRONMENT=/venv \
4334
PATH=/scripts:/venv/bin:$PATH \
4435
SCRIPTS=/scripts \
4536
PGSTACDIR=/src/pgstac \
@@ -48,27 +39,34 @@ ENV \
4839
TESTS=/src/pypgstac/tests
4940
WORKDIR /opt/src/pypgstac
5041
RUN \
42+
--mount=type=cache,target=/var/cache/apt,sharing=locked \
43+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
5144
--mount=type=cache,target=/root/.cache/uv \
5245
--mount=type=bind,source=./src/pypgstac/uv.lock,target=/opt/src/pypgstac/uv.lock \
5346
--mount=type=bind,source=./src/pypgstac/pyproject.toml,target=/opt/src/pypgstac/pyproject.toml \
5447
apt-get update \
55-
&& apt-get upgrade -y \
5648
&& apt-get install -y --no-install-recommends \
5749
postgresql-client libpq-dev python3-dev \
5850
&& apt-get remove -y apt-transport-https \
5951
&& apt-get clean && apt-get -y autoremove \
60-
&& uv venv --allow-existing --relocatable /venv \
61-
&& uv sync --frozen --no-install-project --extra test --extra dev --extra migrations \
62-
&& uv pip install psycopg[binary] psycopg-pool setuptools
52+
&& uv sync --frozen --no-install-project --extra test --extra dev --extra migrations --extra psycopg \
53+
&& uv pip install setuptools
54+
6355

56+
# slim image for running pypgstac
57+
FROM pypgstac-slim-base AS pypgstac-slim
6458
COPY ./docker/pypgstac/bin/ /scripts/
6559
COPY ./src /src
60+
RUN --mount=type=bind,from=pypgstacbuilder,source=/wheels,target=/tmp/wheels \
61+
uv pip install --offline --find-links /tmp/wheels pypgstac
6662

67-
RUN --mount=type=bind,from=pypgstacbuilder,source=/wheels,target=/wheels \
68-
for i in /wheels/pypgstac*x86_64.whl; do echo $i; uv pip install pypgstac@$i; done
63+
# Loaded image for running pypgstac and test suite
64+
FROM pypgstac-base AS pypgstac
65+
COPY ./docker/pypgstac/bin/ /scripts/
66+
COPY ./src /src
67+
RUN --mount=type=bind,from=pypgstacbuilder,source=/wheels,target=/tmp/wheels \
68+
uv pip install --offline --find-links /tmp/wheels pypgstac
6969

70-
ENTRYPOINT []
71-
CMD ["/bin/true"]
7270

7371

7472

src/pgstac/tests/pgtap.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SELECT plan(229);
3434
\i tests/pgtap/004a_collectionsearch.sql
3535
\i tests/pgtap/005_tileutils.sql
3636
\i tests/pgtap/006_tilesearch.sql
37-
\i tests/pgtap/999_version.sql
37+
\i tests/pgtap/999_testreadonly.sql
3838

3939
-- Finish the tests and clean up.
4040
SELECT * FROM finish();

src/pgstac/tests/pgtap/001_core.sql

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,6 @@ SELECT lives_ok(
2727
'Search works with readonly mode set to off in readwrite mode.'
2828
);
2929

30-
SET transaction_read_only TO 'on';
31-
32-
SELECT results_eq(
33-
$$ SHOW transaction_read_only; $$,
34-
$$ SELECT 'on'; $$,
35-
'Transaction set to read only'
36-
);
37-
38-
SELECT throws_ok(
39-
$$ SELECT search('{}'); $$,
40-
'25006'
41-
);
42-
43-
SET pgstac.readonly to 'true';
44-
SELECT results_eq(
45-
$$ SELECT pgstac.readonly(); $$,
46-
$$ SELECT TRUE; $$,
47-
'Readonly is set to true'
48-
);
49-
50-
SELECT lives_ok(
51-
$$ SELECT search('{}'); $$,
52-
'Search works with readonly mode set to on in readonly mode.'
53-
);
54-
55-
SET pgstac.context TO 'on';
56-
SELECT lives_ok(
57-
$$ SELECT search('{}'); $$,
58-
'Search works with readonly mode set to on in readonly mode and the context extension enabled.'
59-
);
60-
RESET transaction_read_only;
6130
RESET pgstac.readonly;
6231
RESET pgstac.context;
6332
SELECT is_definer('update_partition_stats');

src/pgstac/tests/pgtap/004_search.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,12 @@ SELECT * FROM pg_temp.testpaging('desc','asc');
705705

706706
\copy items_staging (content) FROM 'tests/testdata/items_duplicate_ids.ndjson'
707707

708+
SELECT is(
709+
(SELECT count(*) FROM items WHERE id='pgstac-test-item-duplicated'),
710+
'2',
711+
'Check count of items with dupe id'
712+
);
713+
708714
SELECT is(
709715
(SELECT jsonb_array_length(search('{"ids": ["pgstac-test-item-duplicated"]}')->'features')),
710716
'2',

0 commit comments

Comments
 (0)