Commit 02a2d678 authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

Make Dockerfiles great again (fixes #575);

- use a different UID user within the Kresus image
- use an entrypoint to update kresus and weboob at restart
- expose the weboob directory so we can update it from the outside
- have two images, one for nightly and one for the stable version.
- document new stuff
parent 846b50e5
......@@ -40,3 +40,9 @@ check: ## Runs all tests and style checks.
release: ## Prepares for a release. To be done only on the `builds` branch.
./scripts/release.sh
docker-release: ## Prepares for a Docker release. Must be done after make release.
docker build -t bnjbvr/kresus -f docker/Dockerfile-stable .
docker-nightly: ## Prepares for a Docker nightly (no need for make release).
docker build -t bnjbvr/kresus-nightly -f docker/Dockerfile-nightly .
......@@ -57,11 +57,34 @@ And then you can simply start Kresus from any terminal in any directory with:
### Run a pre-built image
It is recommended to bind the data volume containing your personal data, so as
not to lose any data when you re-instanciate the image.
The environment line `LOCAL_USER_ID` can be used to set the UID of the internal
user running kresus within the docker instance. This allows avoiding as root
in the container.
To run the image as your user, binding the data volume, you can do:
```
docker run -p 9876:9876 -v /opt/kresus/data:/home/user/data -ti -d bnjbvr/kresus
docker run -p 9876:9876 \
-e LOCAL_USER_ID=`id -u` \
-v /opt/kresus/data:/home/user/data \
-ti -d bnjbvr/kresus
```
### Build the image
Weboob is pre-installed within the image. You can expose its source directory
with a data volume so as to manually update it (with `git pull`) or through a
daily cron job (for instance):
```
docker run -p 9876:9876 \
-v /opt/kresus/data:/home/user/data \
-v /opt/kresus/weboob:/weboob \
-ti -d bnjbvr/kresus
```
### Build the stable Kresus image
There is a Dockerfile from which you can build and run Kresus, using the
following commands (don't forget to change the port mapping and the volume
......@@ -69,10 +92,19 @@ mapping, if necessary!). You'll need `nodejs` > 0.10 as well as `npm` to build
it from the ground up.
- `git clone https://framagit.org/bnjbvr/kresus && cd kresus`
- `make release` (you can answer `y` to the first question)
- `docker build -t myself/kresus .`
- `docker build -t myself/kresus -f docker/Dockerfile-stable .`
And then you can use it:
- `docker run -p 9876:9876 -v /opt/kresus/data:/home/user/data -ti -d myself/kresus`
If you feel lucky, you can use the Nightly image, with the latest changes. Be
aware it can result in loss of data or bugs, since the master branch can be a
bit unstable sometimes.
- `make release` (answer `y` to the first question)
- `docker build -t myself/kresus -f docker/Dockerfile-nightly .`
## Install on CozyCloud
If you already have a Cozy instance set up, then your best (and
......
FROM node:6
MAINTAINER Benjamin Bouvier <public@benj.me>
# Globally install Weboob and its dependencies.
# Install Weboob OS-level dependencies.
RUN apt-get update && \
apt-get install -y git python python-dev libffi-dev \
libxml2-dev libxslt-dev libyaml-dev libtiff-dev libjpeg-dev zlib1g-dev \
libfreetype6-dev libwebp-dev build-essential gcc g++ wget;
RUN cd /tmp && \
# Install Weboob python dependencies
RUN mkdir /tmp/install && cd /tmp/install && \
wget https://bootstrap.pypa.io/get-pip.py && \
python ./get-pip.py && \
pip install -U setuptools && \
pip install html2text simplejson BeautifulSoup PyExecJS
RUN git clone https://git.weboob.org/weboob/devel /tmp/weboob \
&& cd /tmp/weboob \
&& python ./setup.py install \
&& rm -rf /tmp/weboob
pip install html2text simplejson BeautifulSoup PyExecJS && \
rm -rf /tmp/install
# Setup kresus layout.
RUN useradd -d /home/user -m -s /bin/bash -U user
RUN useradd -d /home/user -m -s /bin/bash -U user && \
mkdir -p /home/user/data && \
mkdir -p /home/user/app && \
chown -R user:user /home/user/app && \
mkdir -p /weboob;
# -> Install app dependencies.
USER user
RUN mkdir -p /home/user/data
VOLUME /home/user/data
RUN mkdir -p /home/user/app
WORKDIR /home/user/app
# Install app dependencies.
COPY package.json package.json
RUN npm install --production
# Copy source.
# -> Copy source.
COPY build /home/user/app/build
COPY bin /home/user/app/bin
# Run server.
USER root
RUN chown user:user -R /home/user
USER user
# Run server.
ENV HOST 0.0.0.0
ENV KRESUS_DIR /home/user/data
CMD bin/kresus.js
ENV KRESUS_WEBOOB_DIR /weboob
# Expose the port on which Kresus is running.
VOLUME /home/user/data
VOLUME /weboob
EXPOSE 9876
COPY ./docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/home/user/app/bin/kresus.js"]
FROM node:6
MAINTAINER Benjamin Bouvier <public@benj.me>
# Install Weboob OS-level dependencies.
RUN apt-get update && \
apt-get install -y git python python-dev libffi-dev \
libxml2-dev libxslt-dev libyaml-dev libtiff-dev libjpeg-dev zlib1g-dev \
libfreetype6-dev libwebp-dev build-essential gcc g++ wget;
# Install Weboob python dependencies
RUN mkdir /tmp/install && cd /tmp/install && \
wget https://bootstrap.pypa.io/get-pip.py && \
python ./get-pip.py && \
pip install -U setuptools && \
pip install html2text simplejson BeautifulSoup PyExecJS && \
rm -rf /tmp/install
# Setup kresus layout.
RUN useradd -d /home/user -m -s /bin/bash -U user && \
mkdir -p /home/user/data && \
mkdir -p /weboob && \
npm install -g --production kresus
# Run server.
ENV HOST 0.0.0.0
ENV KRESUS_DIR /home/user/data
ENV KRESUS_WEBOOB_DIR /weboob
VOLUME /home/user/data
VOLUME /weboob
EXPOSE 9876
COPY ./docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["kresus"]
#!/bin/bash
set -e
# Add local user
# Either use the LOCAL_USER_ID if passed in at runtime or
# fallback
USER_ID=${LOCAL_USER_ID:-9001}
echo "[ENTRYPOINT] Starting with UID : $USER_ID"
usermod -u $USER_ID user
export HOME=/home/user
cd /weboob
if [ ! -d /weboob/.git ]; then
echo "[ENTRYPOINT] Installing weboob..."
git clone --depth 1 https://git.weboob.org/weboob/devel .
echo "[ENTRYPOINT] Done installing."
else
echo "[ENTRYPOINT] Updating weboob..."
git pull --depth 1
echo "[ENTRYPOINT] Done installing."
fi
echo "[ENTRYPOINT] Updating Weboob dependencies..."
cd /weboob
python ./setup.py requirements > /tmp/requirements.txt
pip install -r /tmp/requirements.txt
rm /tmp/requirements.txt
echo "[ENTRYPOINT] Done updating weboob dependencies."
echo "[ENTRYPOINT] Trying to update kresus..."
npm update -g kresus
echo "[ENTRYPOINT] Done."
echo "[ENTRYPOINT] Changing rights..."
chown -R user:user /home/user
chown -R user:user /weboob
# TODO temporary fix until we get a proper location for the weboob data dir
chown -R user:user /usr/local/lib/node_modules/kresus || echo "(no kresus found in /usr/local/lib)"
echo "[ENTRYPOINT] Running kresus as user."
exec su user -c "$@"
#!/bin/bash
docker build -t bnjbvr/kresus-janitor .
docker run \
-p 9876 -p 22 \
-d \
bnjbvr/kresus-janitor
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment