Skip to content

Commit

Permalink
Merge pull request #60 from freifunkMUC/docker-compose
Browse files Browse the repository at this point in the history
Added docker-compose
  • Loading branch information
awlx authored Sep 8, 2021
2 parents 4e1453d + 1537bea commit d0b382e
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 6 deletions.
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ dmypy.json
.pyre/

# Bazel local cache/files ignore.
bazel-*
bazel-*

# docker-compose
.env
docker-compose.override.yaml
# docker-compose volumes
/volumes
# docker-compose config
/config

# config file
wgkex.yaml
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
FROM l.gcr.io/google/bazel:latest AS builder

WORKDIR /srv/wgkex
WORKDIR /wgkex

COPY . ./

RUN ["bazel", "build", "//wgkex/broker:app"]
RUN ["bazel", "build", "//wgkex/worker:app"]
RUN ["cp", "-rL", "bazel-bin", "bazel"]

FROM python:3.8
WORKDIR /srv/wgkex
FROM python:3
WORKDIR /wgkex

COPY --from=builder /srv/wgkex/bazel /srv/wgkex/
COPY --from=builder /wgkex/bazel /wgkex/

COPY entrypoint /entrypoint

EXPOSE 5000
CMD ["./wgkex/broker/app"]

ENTRYPOINT ["/entrypoint"]
CMD ["broker"]
15 changes: 15 additions & 0 deletions docker-compose.override.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.9"

services:
mqtt:
#profiles: ["do-not-start"]
#volumes:
# - ./config/mosquitto:/mosquitto/config
broker:
#profiles: ["do-not-start"]
#volumes:
# - ./config/broker/wgkex.yaml:/etc/wgkex.yaml
worker:
profiles: ["do-not-start"]
#volumes:
# - ./config/broker/wgkex.yaml:/etc/wgkex.yaml
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3"

services:
mqtt:
image: eclipse-mosquitto:1.6
restart: unless-stopped
volumes:
#- ./config/mosquitto:/mosquitto/config
- ./volumes/mosquitto/data:/mosquitto/data
- ./volumes/mosquitto/log:/mosquitto/log
ports:
- "9001:9001"

broker:
build: .
image: wgkex
command: broker
restart: unless-stopped
ports:
- "5000:5000"
#volumes:
#- ./config/broker/wgkex.yaml:/etc/wgkex.yaml
environment:
WGKEX_DOMAINS: ${WGKEX_DOMAINS-ffmuc_freising, ffmuc_gauting, ffmuc_muc_cty, ffmuc_muc_nord, ffmuc_muc_ost, ffmuc_muc_sued, ffmuc_muc_west, ffmuc_uml_nord, ffmuc_uml_ost, ffmuc_uml_sued, ffmuc_uml_west, ffmuc_welt}
WGKEX_DOMAIN_PREFIX: ${WGKEX_DOMAIN_PREFIX-ffmuc_}
WGKEX_DEBUG: ${WGKEX_DEBUG-DEBUG}
MQTT_BROKER_URL: ${MQTT_BROKER_URL-mqtt}
MQTT_BROKER_PORT: ${MQTT_BROKER_PORT-1883}
MQTT_USERNAME: ${MQTT_USERNAME-}
MQTT_PASSWORD: ${MQTT_PASSWORD-}
MQTT_KEEPALIVE: ${MQTT_KEEPALIVE-5}
MQTT_TLS: ${MQTT_TLS-False}

worker:
build: .
image: wgkex
command: worker
restart: unless-stopped
#volumes:
#- ./config/worker/wgkex.yaml:/etc/wgkex.yaml
environment:
WGKEX_DOMAINS: ${WGKEX_DOMAINS-ffmuc_freising, ffmuc_gauting, ffmuc_muc_cty, ffmuc_muc_nord, ffmuc_muc_ost, ffmuc_muc_sued, ffmuc_muc_west, ffmuc_uml_nord, ffmuc_uml_ost, ffmuc_uml_sued, ffmuc_uml_west, ffmuc_welt}
WGKEX_DOMAIN_PREFIX: ${WGKEX_DOMAIN_PREFIX-ffmuc_}
WGKEX_DEBUG: ${WGKEX_DEBUG-DEBUG}
MQTT_BROKER_URL: ${MQTT_BROKER_URL-mqtt}
MQTT_BROKER_PORT: ${MQTT_BROKER_PORT-1883}
MQTT_USERNAME: ${MQTT_USERNAME-}
MQTT_PASSWORD: ${MQTT_PASSWORD-}
MQTT_KEEPALIVE: ${MQTT_KEEPALIVE-5}
MQTT_TLS: ${MQTT_TLS-False}
50 changes: 50 additions & 0 deletions entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -e

: ${WGKEX_DOMAINS:="ffmuc_freising, ffmuc_gauting, ffmuc_muc_cty, ffmuc_muc_nord, ffmuc_muc_ost, ffmuc_muc_sued, ffmuc_muc_west, ffmuc_uml_nord, ffmuc_uml_ost, ffmuc_uml_sued, ffmuc_uml_west, ffmuc_welt"}
: ${WGKEX_DOMAIN_PREFIX:="ffmuc_"}
: ${WGKEX_DEBUG:="DEBUG"}
: ${MQTT_BROKER_URL:="mqtt"}
: ${MQTT_BROKER_PORT:="1883"}
: ${MQTT_USERNAME:=""}
: ${MQTT_PASSWORD:=""}
: ${MQTT_KEEPALIVE:="5"}
: ${MQTT_TLS:="False"}

mk_config() {
if [ ! -e /etc/wgkex.yaml ] ; then
(
echo "domains:"
IFS=", "
for i in $WGKEX_DOMAINS; do
echo " - $i"
done
cat <<EOF
log_level: $WGKEX_DEBUG
domain_prefix: $WGKEX_DOMAIN_PREFIX
mqtt:
broker_url: $MQTT_BROKER_URL
broker_port: $MQTT_BROKER_PORT
username: $MQTT_USERNAME
password: $MQTT_PASSWORD
keepalive: $MQTT_KEEPALIVE
tls: $MQTT_TLS
EOF
unset IFS
) > /etc/wgkex.yaml
fi
}

mk_config

case "$1" in
broker)
exec ./wgkex/broker/app
;;
worker)
exec ./wgkex/worker/app
;;
esac

exec "$@"

14 changes: 14 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copy or rename this file to .env and modify if for your needs

#WGKEX_DOMAINS="ffmuc_freising, ffmuc_gauting, ffmuc_muc_cty, ffmuc_muc_nord, ffmuc_muc_ost, ffmuc_muc_sued, ffmuc_muc_west, ffmuc_uml_nord, ffmuc_uml_ost, ffmuc_uml_sued, ffmuc_uml_west, ffmuc_welt"
#WGKEX_DOMAIN_PREFIX="ffmuc_"
#WGKEX_DEBUG="DEBUG"

#MQTT_BROKER_URL="mqtt"
#MQTT_BROKER_PORT="1883"
#MQTT_USERNAME=""
#MQTT_PASSWORD=""
#MQTT_KEEPALIVE="5"
#MQTT_TLS="False"


0 comments on commit d0b382e

Please sign in to comment.