Skip to content

Commit f97519d

Browse files
committed
Build fat image that includes full CSD inside web server
1 parent deaf365 commit f97519d

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,60 @@ EOF
155155
RUN chmod +x /opt/csd-optimade/test-entrypoint.sh
156156
CMD ["/opt/csd-optimade/test-entrypoint.sh"]
157157

158+
FROM python-setup AS csd-optimade-server-with-csd-sidecar
159+
160+
LABEL org.opencontainers.image.source="https://github.com/datalab-industries/csd-optimade"
161+
LABEL org.opencontainers.image.description="Server environment for the csd-optimade project"
162+
163+
# Copy the CSD data into the serve image
164+
WORKDIR /opt/ccdc/ccdc-data
165+
COPY --from=compress-csd-data /opt/csd.tar.gz.gpg /opt/csd.tar.gz.gpg
166+
167+
WORKDIR /opt/csd-optimade
168+
ENV CSD_DATA_DIRECTORY=/opt/ccdc/ccdc-data/csd
169+
170+
# Copy the ingested CSD into the final image
171+
COPY --from=csd-ingester /opt/csd-optimade/csd-optimade.jsonl.gz.gpg /opt/csd-optimade/csd-optimade.jsonl.gz.gpg
172+
173+
# Copy relevant csd-optimade build files only
174+
COPY LICENSE pyproject.toml uv.lock /opt/csd-optimade/
175+
COPY src /opt/csd-optimade/src
176+
177+
RUN --mount=type=cache,target=/root/.cache/uv \
178+
uv sync --locked --extra-index-url https://pip.ccdc.cam.ac.uk && \
179+
# Remove unecessary mandatory deps from csd-python-api
180+
uv pip uninstall tensorflow tensorflow-estimator xgboost keras jax google-pasta opt-einsum nvidia-nccl-cu12 && \
181+
# Remove duplicated csd-python-api install
182+
rm -rf /opt/csd-optimade/.venv/lib/python3.11/site-packages/lib/ccdc
183+
184+
COPY <<-"EOF" /opt/csd-optimade/serve-entrypoint.sh
185+
#!/bin/bash
186+
set -e
187+
188+
if [ -z "$CSD_ACTIVATION_KEY" ]; then
189+
echo "CSD_ACTIVATION_KEY not set" >&2
190+
exit 1
191+
fi
192+
193+
mkdir -p /root/.config/CCDC
194+
echo -e "[licensing_v1]\nlicence_key=${CSD_ACTIVATION_KEY}" > /root/.config/CCDC/ApplicationServices.ini
195+
# For some reason, this folder must be present when reading sqlite, otherwise it assumes it cannot
196+
mkdir -p /opt/ccdc/ccdc-software
197+
198+
echo "Decrypting CSD data..."
199+
time gpg --batch --passphrase ${CSD_ACTIVATION_KEY} --decrypt /opt/csd.tar.gz.gpg > /opt/csd.tar.gz
200+
time tar -xzf /opt/csd.tar.gz -C /opt/ccdc/ccdc-data
201+
echo "Decompressing CSD data..."
202+
203+
echo "Decrypting and decompressing CSD OPTIMADE format..."
204+
gpg --batch --passphrase ${CSD_ACTIVATION_KEY} --decrypt /opt/csd-optimade/csd-optimade.jsonl.gz.gpg | gunzip > /opt/csd-optimade/csd-optimade.jsonl
205+
206+
exec uv run --no-sync csd-serve --drop-first /opt/csd-optimade/csd-optimade.jsonl
207+
EOF
208+
209+
RUN chmod +x /opt/csd-optimade/serve-entrypoint.sh
210+
CMD ["/opt/csd-optimade/serve-entrypoint.sh"]
211+
158212
FROM python-setup AS csd-optimade-server
159213
LABEL org.opencontainers.image.source="https://github.com/datalab-industries/csd-optimade"
160214
LABEL org.opencontainers.image.description="Production environment for the csd-optimade project"

docker-bake.hcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,18 @@ target "csd-optimade-server" {
6565
cache-to = CI ? [] : ["type=registry,ref=${IMAGE_BASE}:cache,mode=max"]
6666
secret = ["type=env,id=csd-activation-key,env=CSD_ACTIVATION_KEY", "id=csd-installer-url,env=CSD_INSTALLER_URL"]
6767
}
68+
69+
target "csd-optimade-server-with-csd-sidecar" {
70+
inherits = ["docker-metadata-action"]
71+
context = "."
72+
dockerfile = "Dockerfile"
73+
args = {CSD_NUM_STRUCTURES = CSD_NUM_STRUCTURES}
74+
target = "csd-optimade-server-with-csd-sidecar"
75+
tags = ["${IMAGE_BASE}:${VERSION}"]
76+
cache-from = [
77+
"type=registry,ref=${IMAGE_BASE}:${VERSION}",
78+
"type=registry,ref=${IMAGE_BASE}:cache",
79+
]
80+
cache-to = CI ? [] : ["type=registry,ref=${IMAGE_BASE}:cache,mode=max"]
81+
secret = ["type=env,id=csd-activation-key,env=CSD_ACTIVATION_KEY", "id=csd-installer-url,env=CSD_INSTALLER_URL"]
82+
}

0 commit comments

Comments
 (0)