STAC Catalog
Goal
Create a container and run the stac step in the container image tagged localhost/stac:latest.
Lab
This step has a dedicated lab available at /workspace/mastering-app-package/practice-labs/Containers/stac.ipynb
Container
Each step has its own recipe to build the container image.
The stac step container image recipe is:
| stac/Dockerfile | 
|---|
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13 | FROM docker.io/library/python:3.11-slim@sha256:91e9d01cf4bd56be7128c603506b6fe367ef7506f9f2ad8f3a908aeec8941bb9
# System deps needed by rasterio wheels
RUN apt-get update && \
    apt-get install -y --no-install-recommends libexpat1 && \
    rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir "pystac==1.13.0" "rio-stac==0.11.2" "loguru==0.7.3" "click==8.2.1" && \
    python -c "import rio_stac"
ADD app.py /app/app.py
ENTRYPOINT []
 | 
Build the container image with:
| terminal | 
|---|
|  | export WORKSPACE=/workspace/mastering-app-package
podman build --format docker -t localhost/crop:latest ${WORKSPACE}/water-bodies/command-line-tools/crop
podman build --format docker -t localhost/norm-diff:latest ${WORKSPACE}/water-bodies/command-line-tools/norm_diff
podman build --format docker -t localhost/otsu:latest ${WORKSPACE}/water-bodies/command-line-tools/otsu
 | 
Run the container
The command to run the stac step in the container is:
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20 | podman \
    run \
    -i \
    --userns=keep-id \
    --mount=type=bind,source=/workspace/mastering-app-package/runs,target=/runs \
    --mount=type=bind,source=/workspace/mastering-app-package/runs/otsu.tif,target=/inputs/otsu.tif,readonly \
    --workdir=/runs \
    --read-only=true \
    --user=1001:100 \
    --rm \
    --env=HOME=/runs \
    --env=PYTHONPATH=/app \
    localhost/stac:latest \
    python \
    -m \
    app \
    --input-item \
    https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2B_10TFK_20210713_0_L2A \
    --water-body \
    /inputs/otsu.tif
 | 
Step
Run the command to run the stac step with:
sh -x ${WORKSPACE}/scripts/podman-stac.sh
Expected outcome
The folder /workspace/mastering-app-package/runs contains: 
(base) jovyan@coder-mrossi:~/runs$ tree .
.
├── S2B_10TFK_20210713_0_L2A
│   ├── S2B_10TFK_20210713_0_L2A.json
│   └── otsu.tif
├── catalog.json
├── crop_green.tif
├── crop_nir.tif
├── norm_diff.tif
└── otsu.tif
1 directory, 7 files