Use docker-compose to manage containers. (#19)
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
Use docker-compose to manage the containers, and start ceod automatically. The service can be restarted with SIGHUP sent by docker/docker-compose. Co-authored-by: Rio6 <rio.liu@r26.me> Reviewed-on: #19 Co-authored-by: Rio <r345liu@localhost> Co-committed-by: Rio <r345liu@localhost>
This commit is contained in:
parent
35e577b866
commit
f873d04139
|
@ -28,10 +28,12 @@ services:
|
||||||
image: debian:buster
|
image: debian:buster
|
||||||
commands:
|
commands:
|
||||||
- .drone/auth1-setup.sh
|
- .drone/auth1-setup.sh
|
||||||
|
- sleep infinity
|
||||||
- name: coffee
|
- name: coffee
|
||||||
image: debian:buster
|
image: debian:buster
|
||||||
commands:
|
commands:
|
||||||
- .drone/coffee-setup.sh
|
- .drone/coffee-setup.sh
|
||||||
|
- sleep infinity
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
|
|
|
@ -46,7 +46,7 @@ cp .drone/nsswitch.conf /etc/nsswitch.conf
|
||||||
service nslcd start
|
service nslcd start
|
||||||
ldapadd -c -f .drone/data.ldif -Y EXTERNAL -H ldapi:///
|
ldapadd -c -f .drone/data.ldif -Y EXTERNAL -H ldapi:///
|
||||||
if [ -z "$CI" ]; then
|
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
|
fi
|
||||||
|
|
||||||
# KERBEROS
|
# KERBEROS
|
||||||
|
@ -95,12 +95,10 @@ done
|
||||||
|
|
||||||
apt install -y netcat-openbsd
|
apt install -y netcat-openbsd
|
||||||
# sync with phosphoric-acid
|
# sync with phosphoric-acid
|
||||||
nc -l 0.0.0.0 9000
|
nc -l 0.0.0.0 9000 &
|
||||||
if [ -z "$CI" ]; then
|
if [ -z "$CI" ]; then
|
||||||
# sync with coffee
|
# sync with coffee
|
||||||
nc -l 0.0.0.0 9001
|
nc -l 0.0.0.0 9001 &
|
||||||
# sync with mail
|
# sync with mail
|
||||||
nc -l 0.0.0.0 9002
|
nc -l 0.0.0.0 9002 &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep infinity
|
|
||||||
|
|
|
@ -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
|
sed -E -i 's/^(bind-address[[:space:]]+= 127.0.0.1)$/#\1/' /etc/mysql/mariadb.conf.d/50-server.cnf
|
||||||
service mysql start
|
service mysql start
|
||||||
cat <<EOF | mysql
|
cat <<EOF | mysql
|
||||||
CREATE USER 'mysql' IDENTIFIED BY 'mysql';
|
CREATE USER IF NOT EXISTS 'mysql' IDENTIFIED BY 'mysql';
|
||||||
GRANT ALL PRIVILEGES ON *.* TO 'mysql' WITH GRANT OPTION;
|
GRANT ALL PRIVILEGES ON *.* TO 'mysql' WITH GRANT OPTION;
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -52,6 +52,4 @@ if [ -z "$CI" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# sync with phosphoric-acid
|
# sync with phosphoric-acid
|
||||||
nc -l 0.0.0.0 9000
|
nc -l 0.0.0.0 9000 &
|
||||||
|
|
||||||
sleep infinity
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ set -ex
|
||||||
add_fqdn_to_hosts $(get_ip_addr $(hostname)) mail
|
add_fqdn_to_hosts $(get_ip_addr $(hostname)) mail
|
||||||
add_fqdn_to_hosts $(get_ip_addr auth1) auth1
|
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/MockMailmanServer.py &
|
||||||
python tests/MockSMTPServer.py &
|
python tests/MockSMTPServer.py &
|
||||||
|
|
||||||
|
@ -18,6 +18,4 @@ apt install -y netcat-openbsd
|
||||||
auth_setup mail
|
auth_setup mail
|
||||||
|
|
||||||
# sync with phosphoric-acid
|
# sync with phosphoric-acid
|
||||||
nc -l 0.0.0.0 9000
|
nc -l 0.0.0.0 9000 &
|
||||||
|
|
||||||
sleep infinity
|
|
||||||
|
|
|
@ -5,9 +5,9 @@ set -ex
|
||||||
. .drone/common.sh
|
. .drone/common.sh
|
||||||
|
|
||||||
# set FQDN in /etc/hosts
|
# set FQDN in /etc/hosts
|
||||||
add_fqdn_to_hosts $(get_ip_addr $(hostname)) phosphoric-acid
|
add_fqdn_to_hosts "$(get_ip_addr $(hostname))" phosphoric-acid
|
||||||
add_fqdn_to_hosts $(get_ip_addr auth1) auth1
|
add_fqdn_to_hosts "$(get_ip_addr auth1)" auth1
|
||||||
add_fqdn_to_hosts $(get_ip_addr coffee) coffee
|
add_fqdn_to_hosts "$(get_ip_addr coffee)" coffee
|
||||||
# mail container doesn't run in CI
|
# mail container doesn't run in CI
|
||||||
if [ -z "$CI" ]; then
|
if [ -z "$CI" ]; then
|
||||||
add_fqdn_to_hosts $(get_ip_addr mail) mail
|
add_fqdn_to_hosts $(get_ip_addr mail) mail
|
||||||
|
@ -25,12 +25,11 @@ cp /etc/skel/* /users/skel/
|
||||||
|
|
||||||
# create directories for users
|
# create directories for users
|
||||||
for user in ctdalek regular1 exec1; do
|
for user in ctdalek regular1 exec1; do
|
||||||
mkdir /users/$user
|
mkdir -p /users/$user
|
||||||
chown $user:$user /users/$user
|
chown $user:$user /users/$user
|
||||||
done
|
done
|
||||||
|
|
||||||
sync_with coffee
|
sync_with coffee
|
||||||
if [ -z "$CI" ]; then
|
if [ -z "$CI" ]; then
|
||||||
sync_with mail
|
sync_with mail
|
||||||
sleep infinity
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# A script that supervises a program. The program is restarted TIMEOUT second after it exits.
|
||||||
|
# SIGHUP restarts the program
|
||||||
|
# SIGTERM and SIGINT stops the program
|
||||||
|
|
||||||
|
TIMEOUT=1
|
||||||
|
|
||||||
|
running=1
|
||||||
|
trap 'kill -TERM $! 2>/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
|
37
README.md
37
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
|
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 containers instead, which are much easier to work with than the VM.
|
||||||
```
|
```
|
||||||
docker.sh up
|
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
|
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
|
run, and start ceod on each of phosphoric-acid, mail, and coffee container.
|
||||||
`sleep infinity`. Then attach to each of phosphoric-acid, mail and coffee,
|
You can check the containers status using:
|
||||||
and start ceod (see 'Running the application', below). Once inside a container,
|
```sh
|
||||||
make sure to `cd` into the current working directory on the host.
|
docker-compose logs -f
|
||||||
|
|
||||||
To use ceo, run the following inside the phosphoric-acid container:
|
|
||||||
```
|
```
|
||||||
login
|
|
||||||
<username is ctdalek, password is krb5>
|
To use ceo, run the following:
|
||||||
<cd into your directory OUTSIDE the container>
|
```sh
|
||||||
. venv/bin/activate
|
docker-compose exec phosphoric-acid bash
|
||||||
python -m ceo
|
su ctdalek
|
||||||
|
python -m ceo # the password for kerobos is krb5
|
||||||
```
|
```
|
||||||
This should bring up the TUI.
|
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
|
||||||
|
```
|
||||||
|
Alternatively, if you started docker-compose in the foreground, just press Ctrl-C.
|
||||||
|
|
||||||
### VM
|
### 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).
|
[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 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
|
this repo in the phosphoric-acid container under ctdalek's home directory; you
|
||||||
|
|
|
@ -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
|
|
@ -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
|
41
docker.sh
41
docker.sh
|
@ -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 <up|down>' >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
Loading…
Reference in New Issue