Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/Dockerfile: port 1.8 changes to 1.9 #1049

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/complementary-config-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ jobs:

- name: Config parser check
run: |
export LOCAL_UID=$(id -u $USER)
export LOCAL_GID=$(id -g $USER)
cd ./datacube-ows
export $(grep -v '^#' ./complementary_config_test/.env_complementary_config_dea_dev | xargs)
docker-compose -f docker-compose.yaml -f docker-compose.cleandb.yaml up -d
docker-compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows /bin/sh -c "cd /code; sh ./docker/ows/wait-for-db"
docker-compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows /bin/sh -c "datacube system init; datacube system check"
docker-compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows /bin/sh -c "curl https://raw.githubusercontent.com/GeoscienceAustralia/dea-config/master/dev/services/wms/inventory.json -o /tmp/inventory.json"
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml exec -T ows /bin/sh -c "cd /code; ./compare-cfg.sh"
docker-compose -f docker-compose.yaml -f docker-compose.cleandb.yaml down
docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml up -d --wait
docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows /bin/sh -c "datacube system init; datacube system check"
docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml exec -T ows /bin/sh -c "curl https://raw.githubusercontent.com/GeoscienceAustralia/dea-config/master/dev/services/wms/inventory.json -o /tmp/inventory.json"
docker compose -f docker-compose.yaml -f docker-compose.db.yaml exec -T ows /bin/sh -c "cd /code; ./compare-cfg.sh"
docker compose -f docker-compose.yaml -f docker-compose.cleandb.yaml down
14 changes: 10 additions & 4 deletions .github/workflows/pyspy-profiling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ jobs:
# Run performance profiling
- name: setup performance profiling with py-spy (stage 1 - run profiling containers)
run: |
export LOCAL_UID=$(id -u $USER)
export LOCAL_GID=$(id -g $USER)
export $(grep -v '^#' .env_simple | xargs)
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml up -d
docker compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml up -d

- name: Sleep for 10 seconds (stage 1 - wait for services to be ready)
uses: whatnick/wait-action@master
Expand All @@ -51,6 +53,8 @@ jobs:
- name: set output container pid (stage 1 - get ows container pid)
id: set-output-container-id
run: |
export LOCAL_UID=$(id -u $USER)
export LOCAL_GID=$(id -g $USER)
export $(grep -v '^#' .env_simple | xargs)
echo "::set-output name=PID::$(docker inspect --format '{{.State.Pid}}' $(docker inspect -f '{{.Name}}' \
$(docker-compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml ps -q ows) \
Expand All @@ -60,17 +64,19 @@ jobs:
timeout-minutes: 1
continue-on-error: true
run: |
export LOCAL_UID=$(id -u $USER)
export LOCAL_GID=$(id -g $USER)
export $(grep -v '^#' .env_simple | xargs)
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml \
docker compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml \
exec -T ows /bin/sh -c "cd /code;./test_urls.sh &"
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml \
docker compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml \
run pyspy record -f speedscope -o ./artifacts/profile.json --duration 30 \
--pid ${{steps.set-output-container-id.outputs.PID}} --subprocesses

- name: Stop py-spy profiling after timeout (stage 1 - stop profiling)
run: |
export $(grep -v '^#' .env_simple | xargs)
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml down
docker compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.pyspy.yaml down

- name: Upload profile to artifact (stage 1 - Upload profiling svg to artifacts)
uses: actions/upload-artifact@v4
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/test-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,10 @@ jobs:
# Build prod image and tag as latest, connect to pre-indexed database
- name: Build and run prod OWS images (stage 2)
run: |
export LOCAL_UID=$(id -u $USER)
export LOCAL_GID=$(id -g $USER)
export $(grep -v '^#' .env_simple | xargs)
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.prod.yaml up -d

- name: Sleep for 10 seconds
uses: whatnick/wait-action@master
with:
time: '10s'
docker compose -f docker-compose.yaml -f docker-compose.db.yaml -f docker-compose.prod.yaml up -d --wait

# Run some tests on the images
# These tests require a working database
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ jobs:
- name: Test and lint dev OWS image
run: |
mkdir artifacts
docker run -v ${PWD}/artifacts:/mnt/artifacts ${ORG}/${IMAGE}:_builder /bin/sh -c "cd /code;./check-code.sh"
docker run -e LOCAL_UID=$(id -u $USER) -e LOCAL_GID=$(id -g $USER) -v ${PWD}/artifacts:/mnt/artifacts ${ORG}/${IMAGE}:_builder /bin/sh -c "cd /code;./check-code.sh"
mv ./artifacts/coverage.xml ./artifacts/coverage-unit.xml

- name: Dockerized Integration Pytest
run: |
chmod a+rw artifacts
export LOCAL_UID=$(id -u $USER)
export LOCAL_GID=$(id -g $USER)
export $(grep -v '^#' .env_simple | xargs)
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml up -d
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml exec -T ows /bin/sh -c "cd /code;./check-code-all.sh"
docker-compose -f docker-compose.yaml -f docker-compose.db.yaml down
docker compose -f docker-compose.yaml -f docker-compose.db.yaml up -d --wait --build
SpacemanPaul marked this conversation as resolved.
Show resolved Hide resolved
docker compose -f docker-compose.yaml -f docker-compose.db.yaml exec -T ows /bin/sh -c "cd /code;./check-code-all.sh"
docker compose -f docker-compose.yaml -f docker-compose.db.yaml down

- name: Upload All coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ RUN pip freeze
# Should match builder base.
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.8.5

RUN apt-get update -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
gosu \
tini \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /var/dpkg/* /var/tmp/* /var/log/dpkg.log

# Add login-script for UID/GID-remapping.
COPY --chown=root:root --link docker/files/remap-user.sh /usr/local/bin/remap-user.sh

# all the python pip installed libraries
COPY --from=builder /usr/local/lib/python3.10/dist-packages /usr/local/lib/python3.10/dist-packages
COPY --from=builder /usr/lib/python3/dist-packages /usr/lib/python3/dist-packages
Expand Down Expand Up @@ -68,7 +78,7 @@ WORKDIR /code
COPY . /code

# Configure user
RUN useradd -m -s /bin/bash -N -g 100 -u 1001 ows
RUN useradd -m -s /bin/bash ows
WORKDIR "/home/ows"

ENV GDAL_DISABLE_READDIR_ON_OPEN="EMPTY_DIR" \
Expand All @@ -78,5 +88,5 @@ ENV GDAL_DISABLE_READDIR_ON_OPEN="EMPTY_DIR" \

RUN chown 1000:100 /dev/shm

USER ows
ENTRYPOINT ["/usr/local/bin/remap-user.sh"]
CMD ["gunicorn", "-b", "0.0.0.0:8000", "--workers=3", "--threads=2", "-k", "gevent", "--timeout", "121", "--pid", "/home/ows/gunicorn.pid", "--log-level", "info", "--worker-tmp-dir", "/dev/shm", "--config", "python:datacube_ows.gunicorn_config", "datacube_ows.wsgi"]
3 changes: 0 additions & 3 deletions check-code-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# Convenience script for running Travis-like checks.
set -ex

# ensure db is ready
sh ./docker/ows/wait-for-db

# Initialise ODC schemas

datacube system init
Expand Down
11 changes: 9 additions & 2 deletions docker-compose.cleandb.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
version: '3.4'

services:
postgres:
# clean postgis db
image: kartoza/postgis:16
hostname: postgres
environment:
- POSTGRES_DB=${DB_DATABASE}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_USER=${DB_USERNAME}
ports:
- "${DB_PORT}:5432"
restart: always
healthcheck:
test: ["CMD", "pg_isready", "-h", "postgres", "-q", "-d", "$POSTGRES_DB", "-U", "$POSTGRES_USER"]
timeout: 45s
interval: 10s
retries: 10
# Overwrite ows so it can talk to docker db
ows:
ports:
- 8000:8000
environment:
DB_PORT: 5432
depends_on:
postgres:
condition: service_healthy
11 changes: 9 additions & 2 deletions docker-compose.db.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
version: '3.4'

services:
postgres:
# db
build: docker/database/
hostname: postgres
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_USER=${POSTGRES_USER}
ports:
- "${POSTGRES_PORT}:${POSTGRES_PORT}"
restart: always
healthcheck:
test: ["CMD", "pg_isready", "-h", "postgres", "-q", "-d", "$POSTGRES_DB", "-U", "$POSTGRES_USER"]
timeout: 45s
interval: 10s
retries: 10
# Overwrite ows so it can talk to docker db
ows:
ports:
- 8000:8000
depends_on:
postgres:
condition: service_healthy
5 changes: 2 additions & 3 deletions docker-compose.index.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.4'

services:
index:
image: opendatacube/datacube-index:latest
Expand All @@ -11,5 +9,6 @@ services:
DB_DATABASE: ${DB_DATABASE}
restart: always
depends_on:
- postgres
postgres:
condition: service_healthy
command: tail -f /dev/null
2 changes: 0 additions & 2 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.4'

# override default compose to change the launch command

services:
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.pyspy.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: '3.4'

services:
ows:
cap_add:
- SYS_PTRACE
depends_on:
postgres:
condition: service_healthy

pyspy:
build: docker/pyspy/
Expand Down
7 changes: 3 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.4'

# Default compose will create an ows image, with dev settings and connect to a local db
services:
ows:
Expand All @@ -13,6 +11,8 @@ services:
# Uncomment for use with non-dockerised postgres (for docker-compose 1.x)
# network_mode: host
environment:
LOCAL_UID: ${LOCAL_UID:-1000}
LOCAL_GID: ${LOCAL_GID:-1000}
# Defaults are defined in .env file
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
Expand Down Expand Up @@ -45,8 +45,7 @@ services:
SENTRY_DSN: "${SENTRY_DSN}"
volumes:
- ${OWS_CFG_DIR}:${OWS_CFG_MOUNT_DIR}
- ./docker/ows/wait-for-db:/usr/local/bin/wait-for-db
- ./:/code/
- ./artifacts:/mnt/artifacts
restart: always
command: ["wait-for-db", "flask", "run", "--host=0.0.0.0", "--port=8000"]
command: ["flask", "run", "--host=0.0.0.0", "--port=8000"]
13 changes: 13 additions & 0 deletions docker/files/remap-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -e

# Script that gives the container user uid $LOCAL_UID and gid $LOCAL_GID.
# If $LOCAL_UID or $LOCAL_GID are not set, they default to 1000 (default
# for the first user created in Ubuntu).

USER_ID=${LOCAL_UID:-1000}
GROUP_ID=${LOCAL_GID:-1000}

[[ "$USER_ID" == "1000" ]] || usermod -u $USER_ID -o -m -d /home/ows ows
[[ "$GROUP_ID" == "1000" ]] || groupmod -g $GROUP_ID ows
[[ $(id -u) != "0" ]] || GOSU="/usr/sbin/gosu ows"
exec /usr/bin/tini -- $GOSU "$@"
11 changes: 0 additions & 11 deletions docker/ows/wait-for-db

This file was deleted.

Loading