Update Dockerfile to use an entrypoint

Mimmick what Kresus is doing so that generated file are not owned by
root. Fix for #106.
This commit is contained in:
Lucas Verney 2017-12-30 19:57:14 +01:00
parent 83ff6be409
commit f55b6a940b
5 changed files with 33 additions and 15 deletions

View File

@ -20,7 +20,7 @@ docker build -t phyks/flatisfy .
mkdir flatisfy
cd flatisfy
FLATISFY_VOLUME=$(pwd)
docker run -it -v $FLATISFY_VOLUME:/flatisfy phyks/flatisfy sh -c "cd /home/user/app && python -m flatisfy init-config > /flatisfy/config.json"
docker run -it -e LOCAL_USER_ID=`id -u` -v $FLATISFY_VOLUME:/flatisfy phyks/flatisfy sh -c "cd /home/user/app && python -m flatisfy init-config > /flatisfy/config.json"
```
@ -35,7 +35,7 @@ docker run -it -v $FLATISFY_VOLUME:/flatisfy phyks/flatisfy sh -c "cd /home/user
4\. Finally, run the docker image to fetch flats and serve the web UI:
```
docker run -it -v $FLATISFY_VOLUME:/flatisfy -p 8080:8080 phyks/flatisfy
docker run -it -e LOCAL_USER_ID=`id -u` -v $FLATISFY_VOLUME:/flatisfy -p 8080:8080 phyks/flatisfy
```
Your Flatisfy instance is now available at `localhost:8080`!
@ -44,7 +44,7 @@ Your Flatisfy instance is now available at `localhost:8080`!
To fetch new housing posts, you should manually call
```
docker run -it -v $FLATISFY_VOLUME:/flatisfy phyks/flatisfy /home/user/fetch.sh
docker run -it -e LOCAL_USER_ID=`id -u` -v $FLATISFY_VOLUME:/flatisfy phyks/flatisfy /home/user/fetch.sh
```
This can be done easily in a crontask on your host system, to run it typically

View File

@ -19,7 +19,7 @@ RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install -y nodejs
# Install weboob's code itself.
RUN git clone https://git.weboob.org/weboob/devel /home/user/weboob \
RUN git clone --depth 1 https://git.weboob.org/weboob/devel /home/user/weboob \
&& cd /home/user/weboob \
&& pip install .
@ -40,9 +40,14 @@ RUN mkdir -p /home/user/.local/share/flatisfy
COPY ./run.sh /home/user/run.sh
RUN chmod +x /home/user/run.sh
COPY ./entrypoint.sh /home/user/entrypoint.sh
RUN chmod +x /home/user/entrypoint.sh
COPY ./update_weboob.sh /home/user/update_weboob.sh
RUN chmod +x /home/user/update_weboob.sh
# Run server.
EXPOSE 8080
CMD /home/user/run.sh
ENTRYPOINT ["/home/user/entrypoint.sh"]
CMD ["/home/user/run.sh"]

20
docker/entrypoint.sh Normal file
View File

@ -0,0 +1,20 @@
#!/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 -o user
export HOME=/home/user
echo "[ENTRYPOINT] Setting fake values for git config..."
git config --global user.email flatisfy@example.com
git config --global user.name "Flatisfy Root"
echo "Update Weboob..."
/home/user/update_weboob.sh
exec su user -c "$@"

View File

@ -1,16 +1,13 @@
#!/bin/bash
set -e
echo "Update Weboob..."
/home/user/update_weboob.sh
echo "Building data for Flatisfy..."
cd /home/user/app
su user -c "python -m flatisfy build-data -v --config /flatisfy/config.json"
python -m flatisfy build-data -v --config /flatisfy/config.json
echo "Fetching new housing posts..."
cd /home/user/app
su user -c "python -m flatisfy import -v --config /flatisfy/config.json"
python -m flatisfy import -v --config /flatisfy/config.json
echo "Starting web UI..."
exec su user -c "python -m flatisfy serve -v --config /flatisfy/config.json"
python -m flatisfy serve -v --config /flatisfy/config.json

View File

@ -1,10 +1,6 @@
#!/bin/bash
set -e
echo "Setting fake values for git config..."
git config --global user.email flatisfy@example.com
git config --global user.name "Flatisfy Root"
echo "Updating Weboob..."
cd /home/user/weboob
git pull