Skip to content

Commit b0d1f3a

Browse files
authored
Merge pull request #289 from AKSW/feature/smallerDockerBaseImage
Make the docker image smaller
2 parents ee91306 + 3eb2bf8 commit b0d1f3a

4 files changed

Lines changed: 88 additions & 38 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
uses: docker/build-push-action@v2
135135
with:
136136
push: ${{ github.event_name != 'pull_request' }}
137-
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
137+
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le
138138
cache-from: type=gha
139139
cache-to: type=gha,mode=max
140140
tags: ${{ steps.meta.outputs.tags }}

Dockerfile

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,75 @@
1-
FROM python:3
1+
FROM python:3-alpine as builder
22

3-
MAINTAINER Norman Radtke <radtke@informatik.uni-leipzig.de>
4-
MAINTAINER Natanael Arndt <arndt@informatik.uni-leipzig.de>
5-
ENV SSH_AUTH_SOCK /var/run/ssh-agent.sock
3+
LABEL org.opencontainers.image.title="Quit Store" \
4+
org.opencontainers.image.authors="Norman Radtke <radtke@informatik.uni-leipzig.de>, Natanael Arndt <arndt@informatik.uni-leipzig.de>" \
5+
org.opencontainers.image.source="https://github.com/AKSW/QuitStore/"
66

7-
RUN apt-get update && apt-get -y install \
7+
RUN apk --no-cache add \
88
git \
9-
cmake \
9+
gcc \
10+
musl-dev \
11+
libgit2-dev \
1012
libffi-dev \
11-
libssl-dev \
12-
libssh2-1-dev \
13-
&& rm -rf /var/lib/apt/lists/*
13+
libressl-dev \
14+
libssh2-dev \
15+
python3-dev \
16+
openssl-dev \
17+
cargo \
18+
curl
1419

15-
RUN useradd -md /usr/src/app quit
20+
RUN adduser -u 1000 -h /usr/src/app -S quit
1621
USER quit
1722
WORKDIR /usr/src/app
1823

19-
COPY quit/ /usr/src/app/quit
20-
COPY scripts/install-libgit2.sh /
24+
ENV PATH="/usr/src/app/.local/bin:$PATH"
25+
ENV POETRY_VERSION=1.1.12
2126

22-
USER root
23-
# Install libgit2
24-
RUN pip install --no-deps --only-binary :all: pygit2 \
25-
|| /install-libgit2.sh
27+
# In contrast to `pip install --prefer-binary poetry` the install script installs poetry in a
28+
# venv in ~/.local/share/pypoetry/ which can be left behind when copying the files from the build stage
29+
RUN curl -sSL https://install.python-poetry.org \
30+
| python - --version "${POETRY_VERSION}"
2631

2732
COPY poetry.lock pyproject.toml /usr/src/app/
2833

29-
RUN poetry export -f requirements.txt | pip install --no-cache-dir -r /dev/stdin \
30-
&& ln -s /usr/src/app/quit/run.py /usr/local/bin/quit
34+
RUN poetry export -f requirements.txt > requirements.txt
35+
RUN rm ./.local/bin/poetry
3136

32-
COPY docker/config.ttl /etc/quit/
37+
USER root
38+
RUN pip install --prefer-binary --no-cache-dir -r requirements.txt
3339

34-
ENV QUIT_CONFIGFILE="/etc/quit/config.ttl"
40+
RUN ln -s $( python -c "import site; print(site.getsitepackages()[0])" ) /usr/local/python-site-packages
41+
42+
USER quit
43+
44+
# Set default git user
45+
RUN git config --global user.name QuitStore && git config --global user.email quitstore@example.org
46+
47+
FROM python:3-alpine
3548

49+
RUN adduser -u 1000 -h /usr/src/app -S quit
50+
WORKDIR /usr/src/app
51+
52+
RUN apk --no-cache add \
53+
libgit2 \
54+
libssh2
55+
56+
RUN ln -s $( python -c "import site; print(site.getsitepackages()[0])" ) /usr/local/python-site-packages
57+
COPY --from=builder /usr/local/python-site-packages /usr/local/python-site-packages
58+
COPY --from=builder /usr/local/bin /usr/local/bin
59+
COPY --from=builder /usr/src/app/.gitconfig .
3660
RUN mkdir /data && chown quit /data
3761

62+
COPY quit/ /usr/src/app/quit
63+
COPY docker/config.ttl /etc/quit/
64+
3865
USER quit
3966

67+
ENV PATH="/usr/src/app/.local/bin:${PATH}"
68+
ENV SSH_AUTH_SOCK="/var/run/ssh-agent.sock"
69+
ENV QUIT_CONFIGFILE="/etc/quit/config.ttl"
70+
4071
VOLUME /data
4172
VOLUME /etc/quit
4273
EXPOSE 8080
4374

44-
# Set default git user
45-
RUN git config --global user.name QuitStore && git config --global user.email quitstore@example.org
46-
4775
CMD uwsgi --http 0.0.0.0:8080 -w quit.run -b 40960 --pyargv "-vv"

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,27 @@ You can access them with your browser at the following paths.
205205

206206
## Docker
207207

208-
We also provide a [Docker image for the Quit Store](https://hub.docker.com/r/aksw/quitstore/) on the public docker hub.
209-
The Image will expose port 8080 by default.
210-
An existing repository can be linked to the volume `/data`.
211-
The default configuration is located in `/etc/quit/config.ttl`, which can also be overwritten using a respective volume or by setting the `QUIT_CONFIGFILE` environment variable.
208+
We provide a Docker image for the Quit Store on the [public docker hub](https://hub.docker.com/r/aksw/quitstore/) as well as on the [github docker registry](https://github.com/AKSW/QuitStore/pkgs/container/quitstore).
209+
The image exposes port 8080 by default.
210+
The default user within the image is the user `quit` with the user id `1000`.
211+
For this user a git configuration with `user.name QuitStore` and `user.email quitstore@example.org` is preset.
212+
Without any further configuration, a git repository is initialized within the container in the `/data` directory (owned by the default user `quit`).
212213

213-
Further options which can be set are:
214+
To store the data on the host a local directory or volume is required to store the git repository.
215+
An host directory or volume can be linked to the directory `/data`.
216+
Make sure the quit process running with the user id `1000` within the docker container has write access to this directory.
214217

215-
* `QUIT_TARGETDIR` - the target repository directory on which quit should run
216-
* `QUIT_CONFIGFILE` - the path to the config.ttl (default: `/etc/quit/config.ttl`)
217-
* `QUIT_LOGFILE` - the path where quit should create its logfile
218-
* `QUIT_BASEPATH` - the HTTP base path where quit will be served
219-
* `QUIT_OAUTH_CLIENT_ID` - the GitHub OAuth client id (for OAuth see also the [github docu](https://developer.github.com/apps/building-oauth-apps/authorization-options-for-oauth-apps/))
220-
* `QUIT_OAUTH_SECRET` - the GitHub OAuth secret
218+
Alternatively the user id within the container can be set using the [`docker run --user $UID …` option](https://docs.docker.com/engine/reference/commandline/run/).
219+
In this case you have to make sure a `user.name` a `user.email` is configure using `git config` within the repository (`.git/config`) or a git config file is mounted to `/.gitconfig` (to `/usr/src/app/.gitconfig` if you are running it with user id `1000`).
220+
221+
Example setup with the default user:
221222

222-
You need a local directory where you want to store the git repository.
223-
In the example below `mkdir /store/repo`.
224-
Make sure the quit process in the docker container has write access to this directory by executing:
225223
```
224+
mkdir /store/repo
226225
sudo chown 1000 /store/repo
227226
sudo chmod u+w /store/repo
228227
```
228+
229229
To run the image execute the following command (maybe you have to replace `docker` with `sudo docker`):
230230

231231
```
@@ -240,6 +240,17 @@ docker run -d --name containername -p 8080:8080 -v /store/repo:/data aksw/quitst
240240

241241
Now you should be able to access the quit web interface under `http://localhost:8080` and the SPARQL 1.1 interface under `http://localhost:8080/sparql`.
242242

243+
The default configuration is located in `/etc/quit/config.ttl`, which can also be overwritten using a respective volume or by setting the `QUIT_CONFIGFILE` environment variable.
244+
245+
Further options which can be set are:
246+
247+
* `QUIT_TARGETDIR` - the target repository directory on which quit should run
248+
* `QUIT_CONFIGFILE` - the path to the config.ttl (default: `/etc/quit/config.ttl`)
249+
* `QUIT_LOGFILE` - the path where quit should create its logfile
250+
* `QUIT_BASEPATH` - the HTTP base path where quit will be served
251+
* `QUIT_OAUTH_CLIENT_ID` - the GitHub OAuth client id (for OAuth see also the [github docu](https://developer.github.com/apps/building-oauth-apps/authorization-options-for-oauth-apps/))
252+
* `QUIT_OAUTH_SECRET` - the GitHub OAuth secret
253+
243254
## Run the Tests
244255

245256
You need to have the quitstore installed from source, see section [Installation from Source](#installation-from-source).

requirements.txt.windows.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/requirements.txt b/requirements.txt
2+
index fccdc79..f465b85 100644
3+
--- a/requirements.txt
4+
+++ b/requirements.txt
5+
@@ -5,6 +5,3 @@ pygit2>=1.1.0
6+
sortedcontainers
7+
uritools
8+
git+https://github.com/RDFLib/rdflib-jsonld@master
9+
-
10+
-uwsgi
11+
-pylava

0 commit comments

Comments
 (0)