Skip to content

Commit 9f745b4

Browse files
committed
Dockerize
1 parent a673154 commit 9f745b4

25 files changed

+204
-40
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+
docker compose $(DOCKER_COMPOSE_ARGS) build
24+
25+
force-build:
26+
docker compose $(DOCKER_COMPOSE_ARGS) build --no-cache
2927

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

33-
# Mac OSX
34-
#SR3_CONFIG=${HOME}/Library/Application\ Support/sr3
31+
down:
32+
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+
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+
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

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

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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
23+
container_name: msc-wis2node-cache
24+
env_file:
25+
- msc-wis2node.env
26+
msc-wis2node:
27+
container_name: msc-wis2node
28+
build:
29+
context: msc-wis2node-management
30+
env_file:
31+
- msc-wis2node.env
32+
volumes:
33+
- ./datasets.yml:/opt/msc-wis2node/conf/datasets.yml

msc-wis2node-management/Dockerfile

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
30+
# copy the app
31+
COPY ./ /app
32+
33+
RUN apt-get update -y && \
34+
# install dependencies
35+
apt-get install -y ${DEBIAN_PACKAGES} && \
36+
pip3 install --no-cache-dir -r /app/requirements.txt && \
37+
# install msc-wis2node
38+
cd /app && \
39+
pip3 install -e . && \
40+
chmod +x /app/docker/entrypoint.sh && \
41+
# cleanup
42+
apt autoremove -y && \
43+
apt-get -q clean && \
44+
rm -rf /var/lib/apt/lists/* && \
45+
# add msc-wis2node user
46+
useradd -ms /bin/bash msc-wis2node && \
47+
adduser msc-wis2node sudo && \
48+
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
49+
# install sr3 components
50+
mkdir -p $SR3_CONFIG/plugins && \
51+
mkdir -p $SR3_CONFIG/subscribe && \
52+
cp msc_wis2node/publisher.py $SR3_CONFIG/plugins && \
53+
cp deploy/default/sarracenia/dd.weather.gc.ca-all.conf $SR3_CONFIG/subscribe
54+
55+
USER msc-wis2node
56+
WORKDIR /home/msc-wis2node
57+
58+
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
echo "START /entrypoint.sh"
21+
22+
set +e
23+
24+
echo "starting sr3..."
25+
26+
sr3 --logStdout --debug foreground subscribe/dd.weather.gc.ca-all && sleep infinity
27+
28+
echo "END /entrypoint.sh"
File renamed without changes.
File renamed without changes.

msc_wis2node/env.py msc-wis2node-management/msc_wis2node/env.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
DATASET_CONFIG = os.environ.get('MSC_WIS2NODE_DATASET_CONFIG')
3232
TOPIC_PREFIX = os.environ.get('MSC_WIS2NODE_TOPIC_PREFIX', 'origin/a/wis2')
3333
DISCOVERY_METADATA_ZIP_URL = os.environ.get('MSC_WIS2NODE_DISCOVERY_METADATA_ZIP_URL') # noqa
34+
CACHE = os.environ.get('MSC_WIS2NODE_CACHE')
3435
CENTRE_ID = os.environ.get('MSC_WIS2NODE_CENTRE_ID')
3536
WIS2_GDC = os.environ.get('MSC_WIS2NODE_WIS2_GDC')
3637

msc_wis2node/publisher.py msc-wis2node-management/msc_wis2node/publisher.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@
1717
#
1818
###############################################################################
1919

20+
from copy import deepcopy
2021
from datetime import date, datetime, timezone
2122
from fnmatch import fnmatch
2223
import json
2324
import logging
2425
import re
26+
import sqlite
2527
from typing import Union
2628
import uuid
2729

2830
from paho.mqtt import publish
31+
from pymemcache.client import base as memcache_base
2932
from pywis_pubsub.publish import create_message
3033
from sarracenia.flowcb import FlowCB
3134
import yaml
3235

3336
from msc_wis2node.env import (BROKER_HOSTNAME, BROKER_PORT, BROKER_USERNAME,
34-
BROKER_PASSWORD, CENTRE_ID, DATASET_CONFIG,
37+
BROKER_PASSWORD, CACHE, CENTRE_ID, DATASET_CONFIG,
3538
TOPIC_PREFIX)
3639
from msc_wis2node.util import get_mqtt_client_id, get_mqtt_tls_settings
3740

@@ -74,6 +77,7 @@ class WIS2Publisher:
7477
def __init__(self):
7578
"""initialize"""
7679

80+
self.cache = memcache_base.Client(CACHE]
7781
self.datasets = []
7882
self.tls = None
7983

@@ -178,6 +182,14 @@ def publish_to_wis2(self, dataset: dict, url: str) -> None:
178182
url=url
179183
)
180184

185+
LOGGER.debug('Checking for data update')
186+
if message['properties']['data_id'] in self.cache:
187+
update_link = deepcopy(message['links'][0])
188+
update_link['rel'] = 'update'
189+
message['links'].append(update_link)
190+
else:
191+
self.cache.append(messages['properties']['data_id']
192+
181193
cache = dataset.get('cache', True)
182194
if not cache:
183195
LOGGER.info(f'Setting properties.cache={cache}')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

msc-wis2node.env

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ export MSC_WIS2NODE_BROKER_PORT=8883
33
export MSC_WIS2NODE_BROKER_USERNAME=username
44
export MSC_WIS2NODE_BROKER_PASSWORD=password
55
export MSC_WIS2NODE_MSC_DATAMART_AMQP=amqps://dd.weather.gc.ca
6-
export MSC_WIS2NODE_DATASET_CONFIG=/opt/msc-wis2node/conf/datasets.yaml
6+
export MSC_WIS2NODE_DATASET_CONFIG=/opt/msc-wis2node/conf/datasets.yml
77
export MSC_WIS2NODE_DISCOVERY_METADATA_ZIP_URL=https://example.org/discovery-metadata.zip
8+
export MSC_WIS2NODE_CACHE=msc-wis2node-cache:11211
89
export MSC_WIS2NODE_CENTRE_ID=ca-eccc-msc
910
export MSC_WIS2NODE_TOPIC_PREFIX=origin/a/wis2

0 commit comments

Comments
 (0)