From b691b631e92218150fe822744cb14d27bc7b0cc9 Mon Sep 17 00:00:00 2001 From: Rio6 Date: Sun, 12 Sep 2021 15:12:32 -0400 Subject: [PATCH 1/3] convert docker.sh to docker-compose and start ceod automatically --- .drone/auth1-setup.sh | 10 +++----- .drone/coffee-setup.sh | 6 ++--- .drone/mail-setup.sh | 4 +-- .drone/phosphoric-acid-setup.sh | 9 +++---- .drone/supervise.sh | 17 +++++++++++++ docker-compose.yml | 44 +++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 10 ++++++++ docker.sh | 41 ------------------------------ 8 files changed, 82 insertions(+), 59 deletions(-) create mode 100755 .drone/supervise.sh create mode 100644 docker-compose.yml create mode 100755 docker-entrypoint.sh delete mode 100755 docker.sh diff --git a/.drone/auth1-setup.sh b/.drone/auth1-setup.sh index 57baa61..a96d017 100755 --- a/.drone/auth1-setup.sh +++ b/.drone/auth1-setup.sh @@ -46,7 +46,7 @@ cp .drone/nsswitch.conf /etc/nsswitch.conf service nslcd start ldapadd -c -f .drone/data.ldif -Y EXTERNAL -H ldapi:/// if [ -z "$CI" ]; then - ldapadd -c -f .drone/uwldap_data.ldif -Y EXTERNAL -H ldapi:/// + ldapadd -c -f .drone/uwldap_data.ldif -Y EXTERNAL -H ldapi:/// ||: fi # KERBEROS @@ -95,12 +95,10 @@ done apt install -y netcat-openbsd # sync with phosphoric-acid -nc -l 0.0.0.0 9000 +nc -l 0.0.0.0 9000 & if [ -z "$CI" ]; then # sync with coffee - nc -l 0.0.0.0 9001 + nc -l 0.0.0.0 9001 & # sync with mail - nc -l 0.0.0.0 9002 + nc -l 0.0.0.0 9002 & fi - -sleep infinity diff --git a/.drone/coffee-setup.sh b/.drone/coffee-setup.sh index 454fc2c..02ecc55 100755 --- a/.drone/coffee-setup.sh +++ b/.drone/coffee-setup.sh @@ -18,7 +18,7 @@ service mysql stop sed -E -i 's/^(bind-address[[:space:]]+= 127.0.0.1)$/#\1/' /etc/mysql/mariadb.conf.d/50-server.cnf service mysql start cat </dev/null' HUP +trap 'running=0; kill -TERM $! 2>/dev/null' TERM INT +trap 'running=0; kill -KILL $! 2>/dev/null' EXIT + +while [ "$running" = 1 ]; do + "$@" & + wait + sleep "$TIMEOUT" +done diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7c4ea6f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,44 @@ +version: "3.6" + +x-common: &common + image: python:3.7-buster + volumes: + - .:$PWD + environment: + FLASK_APP: ceod.api + FLASK_ENV: development + working_dir: $PWD + entrypoint: + - ./docker-entrypoint.sh + +services: + auth1: + <<: *common + image: debian:buster + hostname: auth0 + command: auth1 + + coffee: + <<: *common + command: coffee + hostname: coffee + depends_on: + - auth1 + + mail: + <<: *common + command: mail + hostname: mail + depends_on: + - auth1 + + phosphoric-acid: + <<: *common + command: phosphoric-acid + hostname: phosphoric-acid + depends_on: + - auth1 + - coffee + - mail + +# vim: expandtab sw=2 ts=2 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..8d430b2 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/sh -e +host="$1" +[ -x ".drone/$host-setup.sh" ] && "./.drone/$host-setup.sh" + +if [ "$host" = auth1 ]; then + exec sleep infinity +else + python3 -m pip install -r requirements.txt -r dev-requirements.txt + exec ./.drone/supervise.sh flask run -h 0.0.0.0 -p 9987 +fi diff --git a/docker.sh b/docker.sh deleted file mode 100755 index 9c6fdf9..0000000 --- a/docker.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -set -x - -case $1 in - up) - if ! [ -d venv ]; then - docker run --rm -v "$PWD:$PWD" -w "$PWD" python:3.7-buster \ - sh -c "python -m venv venv && . venv/bin/activate && pip install -r dev-requirements.txt && pip install -r requirements.txt" - fi - docker network create ceod - for host in auth1 coffee mail phosphoric-acid; do - if [ $host = auth1 ]; then - image=debian:buster - else - image=python:3.7-buster - fi - docker run \ - --detach \ - --name $host \ - --hostname $host \ - --network ceod \ - --volume "$PWD:$PWD" \ - --workdir "$PWD" \ - --env FLASK_APP=ceod.api \ - --env FLASK_ENV=development \ - $image .drone/$host-setup.sh - done - ;; - down) - for host in auth1 coffee mail phosphoric-acid; do - docker kill $host - docker rm $host - done - docker network rm ceod - ;; - *) - echo 'Usage: docker.sh ' >&2 - exit 1 - ;; -esac -- 2.39.2 From f79fe6a6e0c2521d4c814c3b82c55ce568fad10b Mon Sep 17 00:00:00 2001 From: Rio6 Date: Sun, 12 Sep 2021 15:20:50 -0400 Subject: [PATCH 2/3] Update readme --- .drone/mail-setup.sh | 2 +- README.md | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.drone/mail-setup.sh b/.drone/mail-setup.sh index f962711..7d8384a 100755 --- a/.drone/mail-setup.sh +++ b/.drone/mail-setup.sh @@ -8,7 +8,7 @@ set -ex add_fqdn_to_hosts $(get_ip_addr $(hostname)) mail add_fqdn_to_hosts $(get_ip_addr auth1) auth1 -. venv/bin/activate +[ -f venv/bin/activate ] && . venv/bin/activate python tests/MockMailmanServer.py & python tests/MockSMTPServer.py & diff --git a/README.md b/README.md index ab010a5..8a1e8e9 100644 --- a/README.md +++ b/README.md @@ -10,26 +10,37 @@ overview of its architecture. If you are not modifying code related to email or Mailman, then you may use Docker containers instead, which are much easier to work with than the VM. ``` -docker.sh up +docker-compose up -d ``` This will create some containers with the bare minimum necessary for ceod to -run. Run `docker logs -f phosphoric-acid` and wait until you see the line -`sleep infinity`. Then attach to each of phosphoric-acid, mail and coffee, -and start ceod (see 'Running the application', below). Once inside a container, -make sure to `cd` into the current working directory on the host. - -To use ceo, run the following inside the phosphoric-acid container: +run, and start ceod on each of phosphoric-acid, mail, and coffee container. +You can check the containers status using: +```sh +docker-compose logs -f ``` -login - - -. venv/bin/activate + +To use ceo, run the following: +```sh +docker-compose exec phosphoric-acid bash +su ctdalek # optional, to run as normal user +kinit ctdalek # password is krb5 python -m ceo ``` This should bring up the TUI. +Normally, ceod should autoamtically restart when the source files are changed. +To manually restart the service, run: +```sh +docker-compose kill -s SIGHUP phosphoric-acid +``` + +To stop the containers, run: +```sh +docker-compose down +``` + ### VM -If you are making changes related to email or Mailman, you will need the full +If you need the full environment running in VM, follow the guide on [syscom dev environment](https://git.uwaterloo.ca/csc/syscom-dev-environment). This will setup all of the services needed for ceo to work. You should clone this repo in the phosphoric-acid container under ctdalek's home directory; you -- 2.39.2 From 2d55c5099d82f925ca48163c68e0b02c92ad3932 Mon Sep 17 00:00:00 2001 From: Rio6 Date: Tue, 14 Sep 2021 19:58:06 -0400 Subject: [PATCH 3/3] fix some PR issues --- .drone.yml | 2 ++ README.md | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index 1f6a0ab..0dee1cc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -28,10 +28,12 @@ services: image: debian:buster commands: - .drone/auth1-setup.sh + - sleep infinity - name: coffee image: debian:buster commands: - .drone/coffee-setup.sh + - sleep infinity trigger: branch: diff --git a/README.md b/README.md index 8a1e8e9..771f798 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ overview of its architecture. If you are not modifying code related to email or Mailman, then you may use Docker containers instead, which are much easier to work with than the VM. ``` -docker-compose up -d +docker-compose up -d # or without -d to run in the foreground ``` This will create some containers with the bare minimum necessary for ceod to run, and start ceod on each of phosphoric-acid, mail, and coffee container. @@ -22,9 +22,8 @@ docker-compose logs -f To use ceo, run the following: ```sh docker-compose exec phosphoric-acid bash -su ctdalek # optional, to run as normal user -kinit ctdalek # password is krb5 -python -m ceo +su ctdalek +python -m ceo # the password for kerobos is krb5 ``` This should bring up the TUI. @@ -38,6 +37,7 @@ To stop the containers, run: ```sh docker-compose down ``` +Alternatively, if you started docker-compose in the foreground, just press Ctrl-C. ### VM If you need the full environment running in VM, follow the guide on -- 2.39.2