Skip to content

Commit 04402b0

Browse files
authored
Merge pull request #8 from microsoft/add-pypiserver
Added Pypiserver to coresvc-registry to support airgapped python wheel installations
2 parents f286bfb + 5636fac commit 04402b0

File tree

4 files changed

+135
-8
lines changed

4 files changed

+135
-8
lines changed

Dockerfiles/Dockerfile

+68-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ARG INSTALL_OCI_REGISTRY_VER="2.8.2"
22
ARG DOTNET_CONTAINER_VARIANT="6.0-jammy"
3-
3+
ARG PYPISERVER_PORT=8080
4+
ARG PYPI_SERVER_VERSION="2.1.1"
5+
ARG OCI_REGISTRY_PORT=5000
46
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${DOTNET_CONTAINER_VARIANT} AS downloader
57
ARG INSTALL_OCI_REGISTRY_VER="2.8.2"
68
ENV INSTALL_OCI_REGISTRY_VER=${INSTALL_OCI_REGISTRY_VER}
@@ -20,19 +22,78 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
2022
RUN mkdir -p /htpasswd/libs
2123
RUN ldd /usr/bin/htpasswd | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' /htpasswd/libs
2224

23-
# FROM mcr.microsoft.com/cbl-mariner/distroless/minimal:2.0
24-
FROM mcr.microsoft.com/cbl-mariner/distroless/base:2.0
25+
# Setup PypiServer
26+
FROM mcr.microsoft.com/devcontainers/python:1-3.9 as pypi_builder
27+
ARG PYPI_SERVER_VERSION="2.1.1"
28+
ENV PYPI_SERVER_VERSION=${PYPI_SERVER_VERSION}
29+
30+
RUN apt-get update && apt-get install -y --no-install-recommends \
31+
ca-certificates \
32+
gnupg \
33+
wget \
34+
git \
35+
curl \
36+
tar \
37+
libffi-dev \
38+
tree
39+
40+
RUN curl --silent --fail --create-dirs --output /code/pypiserver.tar.gz -L https://github.com/pypiserver/pypiserver/archive/refs/tags/v${PYPI_SERVER_VERSION}.tar.gz \
41+
&& tar -xvzf /code/pypiserver.tar.gz -C /code/
42+
43+
WORKDIR /code/pypiserver-${PYPI_SERVER_VERSION}
44+
45+
RUN python -m pip install \
46+
--no-warn-script-location \
47+
--prefix=/pypi-server \
48+
--requirement docker/docker-requirements.txt
2549

50+
RUN python -m pip install \
51+
--no-warn-script-location \
52+
--prefix=/pypi-server \
53+
.
54+
55+
RUN mkdir -p /code/pypiserver-${PYPI_SERVER_VERSION}/docker/data/packages
56+
57+
COPY src/gunicorn.conf.py /code/pypiserver-${PYPI_SERVER_VERSION}/docker/data/gunicorn.conf.py
58+
59+
FROM mcr.microsoft.com/cbl-mariner/base/python:3.9 as final
60+
ARG OCI_REGISTRY_PORT=5000
2661
ARG INSTALL_OCI_REGISTRY_VER="2.8.2"
62+
ARG PYPI_SERVER_VERSION="2.1.1"
63+
ARG PYPISERVER_PORT=8080
64+
65+
ENV OCI_REGISTRY_PORT=${OCI_REGISTRY_PORT}
66+
ENV PYPI_SERVER_VERSION=${PYPI_SERVER_VERSION}
67+
ENV PYPISERVER_PORT=${PYPISERVER_PORT}
68+
69+
# Flush logs immediately to stdout
70+
ENV PYTHONUNBUFFERED=t
71+
72+
ENV PYTHONPATH=/pypi-server/lib/python3.9/site-packages/
73+
74+
RUN ln -s /usr/bin/python3 /usr/bin/python \
75+
&& ln -s /usr/bin/python3 /usr/local/bin/python
76+
77+
# Copy the registry binaries and the configuration file
2778
COPY src/registry-config.yml /etc/docker/registry/config.yml
2879
COPY --from=downloader /registry /bin/registry
2980

3081
# Pull in the shared libraries from the downloader so we can run htpasswd
3182
COPY --from=downloader /usr/bin/htpasswd /usr/bin/htpasswd
3283
COPY --from=downloader /htpasswd/libs/* /usr/lib/
3384

85+
# Copy the built pypi-server files
86+
COPY --from=pypi_builder /pypi-server /pypi-server
87+
COPY --from=pypi_builder /code/pypiserver-${PYPI_SERVER_VERSION}/docker/data /data
88+
COPY --chmod=0755 src/entrypoint.sh /entrypoint.sh
89+
90+
91+
VOLUME "/var/lib/registry"
92+
VOLUME "/data/packages"
93+
EXPOSE ${OCI_REGISTRY_PORT} ${PYPISERVER_PORT}
94+
95+
USER root
96+
97+
ENTRYPOINT ["/entrypoint.sh"]
98+
3499

35-
VOLUME ["/var/lib/registry"]
36-
EXPOSE 5000
37-
ENTRYPOINT ["registry"]
38-
CMD ["serve", "/etc/docker/registry/config.yml"]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![coresvc-registry-build](https://github.com/microsoft/azure-orbital-space-sdk-coresvc-registry/actions/workflows/coresvc-registry-build.yml/badge.svg)](https://github.com/microsoft/azure-orbital-space-sdk-coresvc-registry/actions/workflows/coresvc-registry-build.yml)
44

5-
Provides an on-vehicle container image repository to use for the Space SDK. This is a fork from https://github.com/distribution/distribution with updates to source images to pullfrom the Microsoft Container Registry.
5+
Provides an on-vehicle container image repository to use for the Space SDK. This is a fork from https://github.com/distribution/distribution with updates to source images to pullfrom the Microsoft Container Registry. It has combined with https://github.com/pypiserver/pypiserver.
66

77
## Build
88

src/entrypoint.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
# This will start the OCI Registry and the PyPI server in the background and listen for the
4+
# SIGTERM and SIGINT signals to stop the processes gracefully.
5+
6+
REGISTRY_ENABLED="${REGISTRY_ENABLED:-"true"}"
7+
PYPISERVER_ENABLED="${PYPISERVER_ENABLED:-"true"}"
8+
9+
# Function to handle termination signal
10+
terminate_processes() {
11+
echo "Termination signal received. Stopping processes..."
12+
if [[ "${REGISTRY_ENABLED}" == "true" ]] && [[ "${PYPISERVER_ENABLED}" == "true" ]]; then
13+
kill $REGISTRY_PID $PYPI_PID
14+
wait $REGISTRY_PID $PYPI_PID
15+
elif [[ "${REGISTRY_ENABLED}" == "true" ]]; then
16+
kill $REGISTRY_PID
17+
wait $REGISTRY_PID
18+
elif [[ "${PYPISERVER_ENABLED}" == "true" ]]; then
19+
kill $PYPI_PID
20+
wait $PYPI_PID
21+
fi
22+
23+
echo "Processes stopped."
24+
exit 0
25+
}
26+
27+
# Trap SIGTERM and SIGINT signals and call the termination function
28+
trap terminate_processes SIGTERM SIGINT
29+
30+
if [[ "${REGISTRY_ENABLED}" == "true" ]]; then
31+
echo "REGISTRY_ENABLED='true'. Starting the OCI Registry..."
32+
# Run the OCI_Registry in the background
33+
registry serve /etc/docker/registry/config.yml &
34+
REGISTRY_PID=$!
35+
echo "...OCI Registry successfully started."
36+
fi
37+
38+
if [[ "${PYPISERVER_ENABLED}" == "true" ]]; then
39+
echo "PYPISERVER_ENABLED='true'. Starting the PyPiServer..."
40+
# Run the pypi server in the background
41+
mkdir -p /data/packages
42+
/pypi-server/bin/pypi-server run -p ${PYPISERVER_PORT:-$PORT} --server gunicorn --backend cached-dir /data/packages --verbose --log-file /var/log/pypiserver.log &
43+
PYPI_PID=$!
44+
echo "...PyPiServer started."
45+
fi
46+
47+
48+
if [[ "${REGISTRY_ENABLED}" == "true" ]] && [[ "${PYPISERVER_ENABLED}" == "true" ]]; then
49+
# Wait for the background processes to complete
50+
wait $REGISTRY_PID $PYPI_PID
51+
elif [[ "${REGISTRY_ENABLED}" == "true" ]]; then
52+
wait $REGISTRY_PID
53+
elif [[ "${PYPISERVER_ENABLED}" == "true" ]]; then
54+
wait $PYPI_PID
55+
fi
56+

src/gunicorn.conf.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Enable to log every request
2+
accesslog = "-"
3+
errorlog = "-"
4+
preload_app = True
5+
workers = 1
6+
worker_class = "gevent"
7+
8+
# SSL Certs
9+
keyfile = "/certs/registry.spacefx.local.key" # Path to your private key file
10+
certfile = "/certs/registry.spacefx.local.crt" # Path to your certificate file

0 commit comments

Comments
 (0)