Skip to content

Commit cb8687e

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

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
@@ -173,6 +173,60 @@ EOF
173173
RUN chmod +x /opt/csd-optimade/test-entrypoint.sh
174174
CMD ["/opt/csd-optimade/test-entrypoint.sh"]
175175

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