Rework Docker image. Closes #84

This commit is contained in:
Lucas Verney 2017-11-27 12:23:08 +01:00
parent 702f58cf9e
commit b81c11b2a8
5 changed files with 47 additions and 29 deletions

View File

@ -20,19 +20,32 @@ docker build -t phyks/flatisfy .
mkdir flatisfy
cd flatisfy
FLATISFY_VOLUME=$(pwd)
docker run -P -v $FLATISFY_VOLUME:/flatisfy -p 8080:8080 phyks/flatisfy sh -c "cd /home/user/app && python -m flatisfy init-config > /flatisfy/config.json"
docker run -it -v $FLATISFY_VOLUME:/flatisfy phyks/flatisfy sh -c "cd /home/user/app && python -m flatisfy init-config > /flatisfy/config.json"
```
3\. Then, edit the generated `config.json` file according to your needs. See
3\. Then, edit the generated `$FLATISFY_VOLUME/config.json` file according to your needs. See
[0.getting_started.md](0.getting_started.md) for more infos on the
configuration file format.
configuration file format. You will have to define your constraints (at
least postal codes, house type and type of post), set `data_directory` to
`/flatisfy` and set `host` to `0.0.0.0` to make the web UI accessible from
outside the Docker container. The rest is up to you.
4\. Finally, run the docker image to fetch flats and serve the web UI:
```
docker run -P -v $FLATISFY_VOLUME:/flatisfy -p 8080:8080 phyks/flatisfy
docker run -it -v $FLATISFY_VOLUME:/flatisfy -p 8080:8080 phyks/flatisfy
```
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
```
This can be done easily in a crontask on your host system, to run it typically
every night.

View File

@ -1,8 +1,6 @@
FROM python:2
MAINTAINER Phyks <phyks@phyks.me>
ENV LANG C.UTF-8
# Setup layout.
RUN useradd -d /home/user -m -s /bin/bash -U user
@ -39,12 +37,12 @@ RUN cd /home/user \
RUN chown user:user -R /home/user
RUN mkdir -p /home/user/.local/share/flatisfy
COPY ./docker_run.sh /home/user/run.sh
COPY ./run.sh /home/user/run.sh
RUN chmod +x /home/user/run.sh
COPY ./fetch.sh /home/user/fetch.sh
RUN chmod +x /home/user/fetch.sh
# Run server.
USER user
CMD /home/user/run.sh
EXPOSE 8080

View File

@ -1,20 +0,0 @@
#!/bin/bash
cd /home/user/app
python -m flatisfy build-data -v --config /flatisfy/config.json
# Run the server in the background.
python -m flatisfy serve --config /flatisfy/config.json &
while true;
do
cd /home/user/weboob
git pull
cd /home/user/app
python -m flatisfy import -v --config /flatisfy/config.json
echo "Done, sleeping for 30 minutes."
sleep 1800
done

11
docker/fetch.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash
set -e
echo "Updating Weboob..."
cd /home/user/weboob
git pull
pip install .
echo "Fetching housing posts..."
cd /home/user/app
python -m flatisfy import -v --config /flatisfy/config.json

16
docker/run.sh Normal file
View File

@ -0,0 +1,16 @@
#!/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 "Building data for Flatisfy..."
cd /home/user/app
python -m flatisfy build-data -v --config /flatisfy/config.json
echo "Fetching new housing posts..."
/home/user/fetch.sh
echo "Starting web UI..."
python -m flatisfy serve --config /flatisfy/config.json