From b4872f6bf8ae0bd59b9030ecd57b929ccb510448 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Thu, 15 Aug 2019 01:12:24 +1000 Subject: [PATCH] Docker setup --- Dockerfile | 20 +++++++++++-------- Makefile | 12 +++++++++++ docker-compose.yml | 50 ++++++++++++++++++++++++++-------------------- start.sh | 39 +++++++++++++++++++++--------------- 4 files changed, 75 insertions(+), 46 deletions(-) mode change 100644 => 100755 start.sh diff --git a/Dockerfile b/Dockerfile index f30c15c..0f37abd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,24 @@ -FROM python:2.7 - +FROM python:3.6 +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive TERM=linux EXPOSE 8801 -VOLUME ["/config", "/var/airnotifier", "/var/log/airnotifier"] RUN apt-get update && \ - apt-get install -y --no-install-recommends git ca-certificates && \ - mkdir -p /var/airnotifier/pemdir + apt-get install -y --no-install-recommends git ca-certificates + +RUN pip3 install pipenv -RUN git clone https://github.com/airnotifier/airnotifier.git /airnotifier +RUN git clone -b 2.x https://github.com/airnotifier/airnotifier.git /airnotifier +RUN mkdir -p /var/airnotifier/pemdir && \ + mkdir -p /var/log/airnotifier +VOLUME ["/airnotifier", "/var/log/airnotifier", "/var/airnotifier/pemdir"] WORKDIR /airnotifier -RUN pip install -r requirements.txt -RUN sed -i 's/https = True/https = False/g' airnotifier.conf-sample +RUN pipenv install --deploy ADD start.sh /airnotifier +RUN chmod a+x /airnotifier/start.sh ENTRYPOINT /airnotifier/start.sh diff --git a/Makefile b/Makefile index 2a3a013..813154d 100644 --- a/Makefile +++ b/Makefile @@ -15,3 +15,15 @@ test: format: black --exclude "ENV\/|venv\/|venv3.6\/|build/|buck-out/|dist/|_build/|\.eggs/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/" . + +docker-build: + docker build --tag=airnotifier . + +docker-run: + docker run -p 8088:8088 airnotifier + +docker-shell: + docker run -it --entrypoint /bin/bash airnotifier + +docker-start: + docker-compose up diff --git a/docker-compose.yml b/docker-compose.yml index 70e4a7b..3f02163 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,25 +1,31 @@ # After staring container, don't forget to install db : # docker exec -it airnotifier python /airnotifier/install.py -airnotifier: - image: anthodingo/airnotifier:latest - container_name: airnotifier - volumes: - - ./config:/config - - ./certs:/var/airnotifier/pemdir - - ./logs:/var/log/airnotifier - ports: - - 8801:8801 - - 27017:27017 - links: - - mongodb - # optionnal - environment: - - MONGO_SERVER=mongodb - - MONGO_PORT=27017 - -mongodb: - image: mongo:2.6 - container_name: mongodb - volumes: - - ./db:/data/db +version: "3" +services: + mongodb: + image: mongo:latest + container_name: mongodb + ports: + - 27017:27017 + environment: + - MONGO_DATA_DIR=/data/db + - MONGO_LOG_DIR=/dev/null + volumes: + - ./db:/data/db + command: mongod --logpath=/dev/null # --quiet + airnotifier: + links: + - mongodb + depends_on: + - mongodb + build: . + container_name: airnotifier + volumes: + - ./certs:/var/airnotifier/pemdir + - ./logs:/var/log/airnotifier + ports: + - 8801:8801 + environment: + - MONGO_SERVER=mongodb + - MONGO_PORT=27017 diff --git a/start.sh b/start.sh old mode 100644 new mode 100755 index 3581f53..d9c527b --- a/start.sh +++ b/start.sh @@ -1,29 +1,36 @@ #!/bin/bash set -e -if [ ! -f "/config/airnotifier.conf" ]; then - cp /airnotifier/airnotifier.conf-sample /config/airnotifier.conf -fi -if [ ! -f "/config/logging.ini" ]; then - cp /airnotifier/logging.ini-sample /config/logging.ini -fi +export LOGDIR=/var/log/airnotifier +export LOGFILE=$LOGDIR/airnotifier.log +export LOGFILE_ERR=$LOGDIR/airnotifier.err -if [ -f "airnotifier.conf" ]; then - rm airnotifier.conf +if [ ! -f "/config/config.py" ]; then + cp config.py-sample config.py fi -ln -s /config/airnotifier.conf -if [ -f "logging.ini" ]; then - rm logging.ini +sed -i 's/https = True/https = False/g' ./config.py + +if [ ! -f "/config/logging.ini" ]; then + cp logging.ini-sample logging.ini fi -ln -s /config/logging.ini if [ -n "$MONGO_SERVER" ]; then - sed -i "s/mongohost = \"localhost\"/mongohost = \"$MONGO_SERVER\"/g" /config/airnotifier.conf + sed -i "s/mongohost = \"localhost\"/mongohost = \"$MONGO_SERVER\"/g" ./config.py fi if [ -n "$MONGO_PORT" ]; then - sed -i "s/mongoport = 27017/mongoport = $MONGO_PORT/g" /config/airnotifier.conf + sed -i "s/mongoport = 27017/mongoport = $MONGO_PORT/g" ./config.py +fi + +if [ ! -f "$LOGFILE" ]; then + touch "$LOGFILE" +fi + +if [ ! -f "$LOGFILE_ERR" ]; then + touch "$LOGFILE_ERR" fi -echo "Starting Airnotifier ..." -python airnotifier.py >> /var/log/airnotifier/airnotifier.log 2>> /var/log/airnotifier/airnotifier.err +echo "Installing AirNotifier ..." +pipenv run ./install.py +echo "Starting AirNotifier ..." +pipenv run ./app.py >> "$LOGFILE" 2>> "$LOGFILE_ERR"