Skip to content

Commit b816cea

Browse files
authored
Docker setup (#4)
* Dockerize * fix flake8 * update * update entrypoint and dataset setup, make cache optional * update instructions add auto-restart to Docker Compose * remove debian setup
1 parent a673154 commit b816cea

26 files changed

+262
-105
lines changed

Makefile

+42-38
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,55 @@
1-
# =================================================================
1+
###############################################################################
22
#
3-
# Authors: Tom Kralidis <[email protected]>
3+
# Copyright (C) 2025 Tom Kralidis
44
#
5-
# Copyright (c) 2024 Tom Kralidis
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
69
#
7-
# Permission is hereby granted, free of charge, to any person
8-
# obtaining a copy of this software and associated documentation
9-
# files (the "Software"), to deal in the Software without
10-
# restriction, including without limitation the rights to use,
11-
# copy, modify, merge, publish, distribute, sublicense, and/or sell
12-
# copies of the Software, and to permit persons to whom the
13-
# Software is furnished to do so, subject to the following
14-
# conditions:
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
1514
#
16-
# The above copyright notice and this permission notice shall be
17-
# included in all copies or substantial portions of the Software.
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1817
#
19-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21-
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23-
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24-
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26-
# OTHER DEALINGS IN THE SOFTWARE.
27-
#
28-
# =================================================================
18+
###############################################################################
19+
20+
DOCKER_COMPOSE_ARGS=--project-name msc-wis2node --file docker-compose.yml --file docker-compose.override.yml
21+
22+
build:
23+
sudo docker compose $(DOCKER_COMPOSE_ARGS) build
24+
25+
force-build:
26+
sudo docker compose $(DOCKER_COMPOSE_ARGS) build --no-cache
2927

30-
# Ubuntu
31-
SR3_CONFIG=${HOME}/.config/sr3
28+
up:
29+
sudo docker compose $(DOCKER_COMPOSE_ARGS) up
3230

33-
# Mac OSX
34-
#SR3_CONFIG=${HOME}/Library/Application\ Support/sr3
31+
down:
32+
sudo docker compose $(DOCKER_COMPOSE_ARGS) down
3533

36-
check:
37-
@echo "SR3 configuration directory: ${SR3_CONFIG}"
34+
restart: down up
3835

39-
install: setup
40-
cp msc_wis2node/publisher.py $(SR3_CONFIG)/plugins
41-
cp deploy/default/sarracenia/dd.weather.gc.ca-all.conf $(SR3_CONFIG)/subscribe
36+
login:
37+
docker exec -it msc-wis2node-management /bin/bash
4238

43-
setup:
44-
mkdir -p $(SR3_CONFIG)/plugins
45-
mkdir -p $(SR3_CONFIG)/subscribe
39+
dev:
40+
sudo docker compose $(DOCKER_COMPOSE_ARGS) --file docker-compose.dev.yml up
41+
42+
reinit-backend:
43+
docker exec -it msc-wis2node-management sh -c "msc-wis2node setup --force"
44+
45+
logs:
46+
sudo docker compose $(DOCKER_COMPOSE_ARGS) logs --follow
4647

4748
clean:
48-
rm -fr $(SR3_CONFIG)/plugins/publisher.py
49-
rm -fr $(SR3_CONFIG)/subscribe/dd.weather.gc.ca-all.conf
49+
docker system prune -f
50+
docker volume prune -f
51+
52+
rm:
53+
docker volume rm $(shell docker volume ls --filter name=msc-wis2node -q)
5054

51-
.PHONY: check install setup clean
55+
.PHONY: build up dev login down restart reinit-backend force-build logs rm clean

README.md

+42-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ source bin/activate
2828

2929
# clone codebase and install
3030
git clone https://github.com/ECCC-MSC/msc-wis2node.git
31-
cd msc-wis2node
31+
cd msc-wis2node/msc-wis2node-management
3232
python3 setup.py install
3333

3434
# install sarracenia configurations
@@ -55,9 +55,9 @@ vim local.env # update accordingly
5555
# MSC_WIS2NODE_BROKER_USERNAME: username of the MQTT broker to publish to=admin
5656
# MSC_WIS2NODE_BROKER_PASSWORD: password of the MQTT broker to publish to
5757
# MSC_WIS2NODE_MSC_DATAMART_AMQP: URL to MSC Datamart notification service
58-
# MSC_WIS2NODE_DATASET_CONFIG: filepath where MSC dataset definitions are managed
5958
# MSC_WIS2NODE_DISCOVERY_METADATA_ZIP_URL: URL to SSC GitLab zipfile of MSC discovery metadata
6059
# MSC_WIS2NODE_TOPIC_PREFIX: base topic prefix for publication (i.e. origin/a/wis2/ca-eccc-msc)
60+
# MSC_WIS2NODE_CACHE: optional memcache instance
6161

6262
source local.env
6363

@@ -80,7 +80,46 @@ msc-wis2node dataset delete-metadata --metadata-id 12345
8080

8181
### Docker
8282

83-
Instructions to run msc-wis2node via Docker can be found in the [`docker`](docker) directory.
83+
The Docker setup uses Docker and Docker Compose to manage the following services:
84+
85+
- **msc-wis2node-cache**: memcache caching for data update detection (optional)
86+
- **msc-wis2node-management**: management service to subscribe to MSC Datamart/HPFX and re-publish to WIS2
87+
88+
See [`msc-wis2node.env`](msc-wis2node.env) for default environment variable settings.
89+
90+
To adjust service ports, edit [`docker-compose.override.yml`](docker-compose.override.yml) accordingly.
91+
92+
The [`Makefile`](Makefile) in the root directory provides options to manage the Docker Compose setup.
93+
94+
```bash
95+
# build all images
96+
make build
97+
98+
# build all images (no cache)
99+
make force-build
100+
101+
# start all containers
102+
make up
103+
104+
# start all containers in dev mode
105+
make dev
106+
107+
# view all container logs in realtime
108+
make logs
109+
110+
# login to the msc-wis2node-management container
111+
make login
112+
113+
# restart all containers
114+
make restart
115+
116+
# shutdown all containers
117+
make down
118+
119+
# remove all volumes
120+
make rm
121+
```
122+
84123

85124
## Development
86125

debian/changelog

-5
This file was deleted.

debian/compat

-1
This file was deleted.

debian/control

-14
This file was deleted.

debian/copyright

-24
This file was deleted.

debian/msc-wis2node.install

-1
This file was deleted.

debian/rules

-14
This file was deleted.

debian/source/format

-1
This file was deleted.

docker-compose.override.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
###############################################################################
2+
#
3+
# Copyright (C) 2025 Tom Kralidis
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
###############################################################################
19+
20+
services:
21+
msc-wis2node-cache:
22+
ports:
23+
- 11211:11211

docker-compose.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
###############################################################################
2+
#
3+
# Copyright (C) 2025 Tom Kralidis
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
###############################################################################
19+
20+
services:
21+
msc-wis2node-cache:
22+
image: memcached:latest
23+
container_name: msc-wis2node-cache
24+
env_file:
25+
- msc-wis2node.env
26+
restart: unless-stopped
27+
msc-wis2node-management:
28+
image: msc-wis2node-management
29+
container_name: msc-wis2node
30+
build:
31+
context: msc-wis2node-management/
32+
env_file:
33+
- msc-wis2node.env
34+
restart: unless-stopped

msc-wis2node-management/Dockerfile

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
###############################################################################
2+
#
3+
# Copyright (C) 2025 Tom Kralidis
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#
18+
###############################################################################
19+
20+
FROM ubuntu:jammy
21+
22+
LABEL maintainer="[email protected]"
23+
24+
ARG SR3_CONFIG /home/msc-wis2node/.config/sr3
25+
26+
ENV TZ="Etc/UTC" \
27+
DEBIAN_FRONTEND="noninteractive" \
28+
DEBIAN_PACKAGES="bash curl git python3-pip python3-setuptools sudo vim" \
29+
MSC_WIS2NODE_DATASET_CONFIG=/home/msc-wis2node/datasets.yml
30+
31+
# copy the app
32+
COPY ./ /app
33+
34+
RUN apt-get update -y && \
35+
# install dependencies
36+
apt-get install -y ${DEBIAN_PACKAGES} && \
37+
pip3 install --no-cache-dir -r /app/requirements.txt && \
38+
# install msc-wis2node
39+
cd /app && \
40+
pip3 install -e . && \
41+
chmod +x /app/docker/entrypoint.sh && \
42+
# cleanup
43+
apt autoremove -y && \
44+
apt-get -q clean && \
45+
rm -rf /var/lib/apt/lists/* && \
46+
# add msc-wis2node user
47+
useradd -ms /bin/bash msc-wis2node && \
48+
adduser msc-wis2node sudo && \
49+
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
50+
# install sr3 components
51+
mkdir -p /home/msc-wis2node/.config/sr3/plugins && \
52+
mkdir -p /home/msc-wis2node/.config/sr3/subscribe && \
53+
cp msc_wis2node/publisher.py /home/msc-wis2node/.config/sr3/plugins/publisher.py && \
54+
cp deploy/default/sarracenia/dd.weather.gc.ca-all.conf /home/msc-wis2node/.config/sr3/subscribe/dd.weather.gc.ca-all.conf
55+
56+
USER msc-wis2node
57+
WORKDIR /home/msc-wis2node
58+
59+
ENTRYPOINT [ "/app/docker/entrypoint.sh" ]

msc-wis2node-management/MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include README.md LICENSE requirements.txt

msc-wis2node-management/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# msc-wis2node
2+
3+
Python package to perform MSC WIS2 Node management functions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
###############################################################################
3+
#
4+
# Copyright (C) 2025 Tom Kralidis
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
###############################################################################
20+
21+
echo "START /entrypoint.sh"
22+
23+
printenv | grep -v "no_proxy" > /tmp/environment
24+
sudo sh -c 'cat /tmp/environment >> /etc/environment'
25+
rm -f /tmp/environment
26+
27+
echo "Setting up MSC dataset config"
28+
msc-wis2node dataset setup
29+
30+
echo "starting sr3..."
31+
sr3 --logStdout start subscribe/dd.weather.gc.ca-all && sleep infinity
32+
33+
echo "END /entrypoint.sh"
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)