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

Dockerfile: remove test deps from prod image #1059

Merged
merged 2 commits into from
Aug 12, 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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
# the production image
- name: Build dev OWS image
run: |
docker build \
docker build --build-arg ENVIRONMENT=test \
--tag ${ORG}/${IMAGE}:_builder \
.

Expand All @@ -62,7 +62,7 @@ jobs:
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 --wait
docker compose -f docker-compose.yaml -f docker-compose.db.yaml up -d --wait --build
docker compose -f docker-compose.yaml -f docker-compose.db.yaml exec -T ows_18 /bin/sh -c "cd /code && ./check-code-all.sh"
docker compose -f docker-compose.yaml -f docker-compose.db.yaml down

Expand Down
75 changes: 36 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Note that this is now pinned to a fixed version. Remember to check for new versions periodically.
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.9.1 AS builder

# Environment is test or deployment.
ARG ENVIRONMENT=deployment

# Setup build env for postgresql-client-16
USER root
RUN apt-get update -y \
Expand All @@ -12,65 +15,59 @@ RUN apt-get update -y \
python3-pip \
postgresql-client-16 \
# For Pyproj build \
proj-bin proj-data libproj-dev \
proj-bin libproj-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /var/dpkg/* /var/tmp/* /var/log/dpkg.log

ENV GDAL_DISABLE_READDIR_ON_OPEN="EMPTY_DIR"

# Copy source code and install it
WORKDIR /code
COPY . /code

RUN echo "version=\"$(python3 setup.py --version)\"" > datacube_ows/_version.py \
&& pip --disable-pip-version-check install --no-cache-dir .[ops,test] --break-system-packages

## Only install pydev requirements if arg PYDEV_DEBUG is set to 'yes'
ARG PYDEV_DEBUG="no"
RUN if [ "$PYDEV_DEBUG" = "yes" ]; then \
pip --disable-pip-version-check install --no-cache-dir .[dev] --break-system-packages \
;fi
WORKDIR /build

RUN pip freeze
RUN python3 -m pip --disable-pip-version-check -q wheel --no-binary psycopg2 psycopg2 \
&& ([ "$ENVIRONMENT" = "deployment" ] || \
python3 -m pip --disable-pip-version-check -q wheel --no-binary pyproj pyproj)

# Should match builder base.
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.9.1

RUN apt-get update -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# Environment is test or deployment.
ARG ENVIRONMENT=deployment
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends \
git \
gosu \
python3-pip \
tini \
&& ([ "$ENVIRONMENT" = "deployment" ] || \
apt-get install -y --no-install-recommends \
proj-bin) \
&& 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.12/dist-packages /usr/local/lib/python3.12/dist-packages
COPY --from=builder /usr/lib/python3/dist-packages /usr/lib/python3/dist-packages
# postgres client
COPY --from=builder /usr/lib/postgresql /usr/lib/postgresql
COPY --from=builder /usr/share/postgresql /usr/share/postgresql
# datacube cli
COPY --from=builder /usr/local/bin/datacube /usr/local/bin/datacube
# datacube-ows cli
COPY --from=builder /usr/local/bin/datacube-ows /usr/local/bin/datacube-ows
# datacube-ows-update cli
COPY --from=builder /usr/local/bin/datacube-ows-update /usr/local/bin/datacube-ows-update
# datacube-ows-cfg check
COPY --from=builder /usr/local/bin/datacube-ows-cfg /usr/local/bin/datacube-ows-cfg
# flask cli
COPY --from=builder /usr/local/bin/flask /usr/local/bin/flask
# gunicorn cli
COPY --from=builder /usr/local/bin/gunicorn /usr/local/bin/gunicorn
# pybabel cli
COPY --from=builder /usr/local/bin/pybabel /usr/local/bin/pybabel

# Copy source code and install it
WORKDIR /code
COPY . /code

## Only install pydev requirements if arg PYDEV_DEBUG is set to 'yes'
ARG PYDEV_DEBUG="no"
COPY --from=builder --link /build/*.whl ./
RUN EXTRAS=$([ "$ENVIRONMENT" = "deployment" ] || echo ",test") && \
python3 -m pip --disable-pip-version-check install ./*.whl --break-system-packages && \
rm ./*.whl && \
echo "version=\"$(python3 setup.py --version)\"" > datacube_ows/_version.py && \
python3 -m pip --disable-pip-version-check install --no-cache-dir ".[ops$EXTRAS]" --break-system-packages && \
([ "$PYDEV_DEBUG" != "yes" ] || \
python3 -m pip --disable-pip-version-check install --no-cache-dir .[dev] --break-system-packages) && \
python3 -m pip freeze && \
([ "$ENVIRONMENT" != "deployment" ] || \
(rm -rf /code/* /code/.git* && \
apt-get purge -y \
git \
git-man \
python3-pip))

# Configure user
WORKDIR "/home/ubuntu"

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
context: .
args:
PYDEV_DEBUG: "${PYDEV_DEBUG}"
ENVIRONMENT: test
cache_from:
- opendatacube/ows_18:_builder
image: opendatacube/ows_18:latest
Expand Down
Loading