forked from github.com/pypiserver
Merge pull request #239 from ronneke1996/revamp-docker-file
Made the image smaller
This commit is contained in:
commit
b21cdb1e90
@ -11,7 +11,7 @@ python:
|
||||
- pypy3
|
||||
|
||||
install:
|
||||
- pip install -U setuptools pip sphinx tox tox-travis
|
||||
- pip install -U setuptools twine pip sphinx tox tox-travis
|
||||
|
||||
script:
|
||||
- ./bin/test-docker.sh
|
||||
|
51
Dockerfile
51
Dockerfile
@ -1,21 +1,42 @@
|
||||
FROM python:3.6-alpine
|
||||
FROM alpine:3.8 AS base
|
||||
|
||||
# Build
|
||||
COPY . /code
|
||||
WORKDIR /code
|
||||
|
||||
RUN addgroup -S -g 9898 pypiserver && \
|
||||
adduser -S -u 9898 -G pypiserver pypiserver && \
|
||||
apk add py-bcrypt && \
|
||||
python setup.py install && \
|
||||
pip install passlib && \
|
||||
cd / && \
|
||||
rm -rf /code && \
|
||||
mkdir -p /data/packages && \
|
||||
chown -R pypiserver:pypiserver /data/packages && \
|
||||
# Install python and modules that can't be installed via pip
|
||||
# Delete the uncompiled variants to shave off ~10MB of the docker file
|
||||
RUN addgroup -S -g 9898 pypiserver \
|
||||
&& adduser -S -u 9898 -G pypiserver pypiserver \
|
||||
&& mkdir -p /data/packages \
|
||||
&& chown -R pypiserver:pypiserver /data/packages \
|
||||
# Set the setgid bit so anything added here gets associated with the
|
||||
# pypiserver group
|
||||
chmod g+s /data/packages
|
||||
&& chmod g+s /data/packages \
|
||||
&& apk --no-cache add python py2-bcrypt py2-cffi py2-six \
|
||||
&& find /usr -name "*.py" ! -name "__*" -exec rm {} \;
|
||||
|
||||
FROM base as builder
|
||||
|
||||
# Copy the requirements and install them
|
||||
# Do this in a separate image in a separate directory
|
||||
# to not have all the pip stuff in the final image
|
||||
COPY docker-requirements.txt /requirements.txt
|
||||
|
||||
# Install python packages
|
||||
RUN apk add --no-cache py2-pip \
|
||||
&& mkdir /install \
|
||||
&& pip install --prefix=/install --requirement /requirements.txt \
|
||||
&& find /install -name "*.py" ! -name "__*" -exec rm {} \;
|
||||
|
||||
FROM base
|
||||
|
||||
# Copy the libraries installed via pip
|
||||
COPY --from=builder /install /usr
|
||||
|
||||
COPY . /code
|
||||
|
||||
RUN apk add py2-setuptools \
|
||||
&& cd code \
|
||||
&& python setup.py install \
|
||||
&& cd / \
|
||||
&& rm -rf code
|
||||
|
||||
VOLUME /data/packages
|
||||
USER pypiserver
|
||||
|
BIN
bin/pypiserver-1.2.6-py2.py3-none-any.whl
Normal file
BIN
bin/pypiserver-1.2.6-py2.py3-none-any.whl
Normal file
Binary file not shown.
@ -5,15 +5,44 @@
|
||||
|
||||
set -xe # exit on any error, show debug output
|
||||
|
||||
DIR="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
docker build . -t pypiserver:test
|
||||
|
||||
docker run pypiserver:test --help
|
||||
docker run pypiserver:test --help > /dev/null
|
||||
|
||||
CONTAINER_ID=$(docker run -d -p 8080:8080 pypiserver:test)
|
||||
# Mount our htpasswd file, which contains a test user with a bcrypt-encrypted
|
||||
# "test" password
|
||||
CONTAINER_ID=$(docker run \
|
||||
-d \
|
||||
-v "${DIR}/test.htpasswd:/data/.htpasswd" \
|
||||
-p 8080:8080 \
|
||||
pypiserver:test -a "list,update,download" -P /data/.htpasswd packages)
|
||||
|
||||
sleep 5 # give the contaienr some time to get going
|
||||
trap "docker container stop $CONTAINER_ID" EXIT
|
||||
|
||||
# Ensure our home page is returning something
|
||||
curl localhost:8080 | grep -q "pypiserver"
|
||||
sleep 5 # give the container some time to get going
|
||||
|
||||
docker container stop "$CONTAINER_ID"
|
||||
# Ensure we can authenticate locally
|
||||
RET=$(curl localhost:8080)
|
||||
echo $RET
|
||||
echo $RET | grep -q "pypiserver"
|
||||
|
||||
RET=$(curl localhost:8080/packages/)
|
||||
echo $RET
|
||||
echo $RET | grep -q "401"
|
||||
|
||||
|
||||
RET=$(curl test:test@localhost:8080/packages/)
|
||||
echo $RET
|
||||
echo $RET | grep -q "Index of packages"
|
||||
|
||||
twine upload \
|
||||
-u test \
|
||||
-p test \
|
||||
--repository-url http://localhost:8080 \
|
||||
"${DIR}/pypiserver-1.2.6-py2.py3-none-any.whl"
|
||||
|
||||
RET=$(curl test:test@localhost:8080/packages/)
|
||||
echo $RET
|
||||
echo $RET | grep -q "pypiserver-1.2.6"
|
||||
|
2
bin/test.htpasswd
Normal file
2
bin/test.htpasswd
Normal file
@ -0,0 +1,2 @@
|
||||
test:$2y$05$0wU8vmgucWeyLyqxB.mm1OOPf660/exARXPN5uC.gHaWziv7C4t/m
|
||||
|
1
docker-requirements.txt
Normal file
1
docker-requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
passlib==1.7.1
|
Loading…
Reference in New Issue
Block a user