Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full dockerization of UDMI local setup #932

Merged
merged 62 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
bc19b1c
Documentation cleanup
grafnu Jul 11, 2024
8d3aff7
Fix spelling
grafnu Jul 11, 2024
6bcf585
Spelling fix
grafnu Jul 11, 2024
17ef1b1
Merge branch 'master' into documentation
grafnu Jul 11, 2024
e79f077
Purge images
grafnu Jul 12, 2024
8543fe4
Basic containerization
grafnu Jul 12, 2024
fb04adf
mango docker runner
grafnu Jul 12, 2024
73b9bfc
Adding etcd basics
grafnu Jul 12, 2024
e6558fd
Don't hardcode local site model
grafnu Jul 12, 2024
8a2053d
Progressing on docker udmis
grafnu Jul 15, 2024
058c528
Iterating on docker container
grafnu Jul 15, 2024
e394639
More stuff
grafnu Jul 16, 2024
cd012a7
Working local dockerfile
grafnu Jul 16, 2024
273374e
Cleanup debugging
grafnu Jul 16, 2024
d926744
Working local docker startup
grafnu Jul 16, 2024
ec5b4f5
Fix udmis build
grafnu Jul 16, 2024
73dae45
Conditional copy
grafnu Jul 16, 2024
7ef04c9
Fix startup stuff
grafnu Jul 16, 2024
af68e26
Fix startup
grafnu Jul 16, 2024
62de7f2
Merge branch 'udmil' into documentation
grafnu Jul 16, 2024
c6a1791
Docs update
grafnu Jul 16, 2024
14e6a53
Cleanup
grafnu Jul 16, 2024
1e98bfd
Fix cert check for pubber
grafnu Jul 16, 2024
f4f4894
FIx startup conditions
grafnu Jul 16, 2024
c268ebf
Fix local block logic
grafnu Jul 16, 2024
db5046a
Remove udmis/sbin
grafnu Jul 16, 2024
3e5d412
Don't validate validation events
grafnu Jul 17, 2024
03805fc
Merge branch 'master' into udmil
grafnu Jul 17, 2024
45f9bbc
Cleanup dockerfiles
grafnu Jul 17, 2024
c65f55f
Basic validator container
grafnu Jul 17, 2024
0289061
Working registrar docker
grafnu Jul 18, 2024
99e8308
Disabling precommit
grafnu Jul 18, 2024
042829b
More working now with moar pubber
grafnu Jul 18, 2024
365a6fb
Automatically sign cert
grafnu Jul 18, 2024
a2328cb
Fixing startup
grafnu Jul 18, 2024
0b51e3f
Updating example outputs
grafnu Jul 18, 2024
e1797e1
Trying to make udmis target work
grafnu Jul 18, 2024
78961ee
Working pubber tls
grafnu Jul 18, 2024
175efcb
Cleanup
grafnu Jul 18, 2024
fe1f98f
Dont setup_base
grafnu Jul 18, 2024
d5905d2
Working sequencer run
grafnu Jul 18, 2024
8afabf9
Docs cleanup
grafnu Jul 18, 2024
8ce724d
Minor cleanup
grafnu Jul 18, 2024
feb3779
Fix some instructions
grafnu Jul 19, 2024
1eafd05
Updating docs
grafnu Jul 19, 2024
83916a0
Updating output files
grafnu Jul 19, 2024
8c8b5bc
Fix pubber output
grafnu Jul 19, 2024
ec20169
Test tweaks
grafnu Jul 19, 2024
07fdf11
log location
grafnu Jul 19, 2024
a01ec61
Documentation update
grafnu Jul 19, 2024
55c5808
Restore conditional venv activate
grafnu Jul 19, 2024
16dbe8b
Properly format header
grafnu Jul 19, 2024
33a9660
Spelling
grafnu Jul 19, 2024
eb91d1a
Docs fix
grafnu Jul 19, 2024
6340818
Increase endpoint timeout
grafnu Jul 19, 2024
b477edf
Dependency fixing
grafnu Jul 19, 2024
c239aa5
Fix docs
grafnu Jul 19, 2024
ebc52da
Don't fail on missing files
grafnu Jul 19, 2024
6c7cee4
Merge branch 'master' into udmil
grafnu Jul 19, 2024
fa6d674
Generate keys for gateway
grafnu Jul 20, 2024
90d1472
Move mosquitto log location
grafnu Jul 20, 2024
7d8ebfc
Fix mosquitto_logs
grafnu Jul 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ jobs:
run: more out/pubber.log* pubber/out/*.json | cat
- name: udmis log
if: ${{ !cancelled() }}
run: cat out/udmis*.log || true
run: cat /tmp/udmis.log || true
- name: itemized test post-process
if: ${{ !cancelled() }}
run: egrep ' test .* after .*s ' out/sequencer.log-* | tee out/timing_itemized.out
Expand All @@ -204,7 +204,7 @@ jobs:
name: Baseline Tests
runs-on: ubuntu-latest
needs: pretest
timeout-minutes: 10
timeout-minutes: 15
if: vars.TARGET_PROJECT != ''
env:
TARGET_PROJECT: ${{ vars.TARGET_PROJECT }}
Expand Down Expand Up @@ -280,7 +280,7 @@ jobs:
sudo more /etc/mosquitto/* /etc/mosquitto/conf.d/* || true
- name: udmis log
if: ${{ !cancelled() }}
run: cat out/udmis*.log
run: cat /tmp/udmis.log
- name: mosquitto logs
if: ${{ !cancelled() }}
run: cat /var/log/mosquitto/mosquitto.log || true
Expand All @@ -298,7 +298,7 @@ jobs:
name: Endpoint Redirection
runs-on: ubuntu-latest
needs: [ pretest, baseline ]
timeout-minutes: 10
timeout-minutes: 15
if: vars.TARGET_PROJECT != ''
env:
TARGET_PROJECT: ${{ vars.TARGET_PROJECT }}
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ credentials.json
/udmis/var/
/udmis/profile/
/udmis/.idea/libraries/
/udmis/udmi_bin/
/udmis/udmi_etc/
/selfie/build/
/pubber/build/
/pubber/out/
Expand Down
4 changes: 2 additions & 2 deletions bin/container
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ git_repo=${git_prefix#*.com:}

GCP_PROJECT=$(gcloud config get project)
REPOSITORY=ghcr.io/${git_repo}
TEMPLATES=$(cd etc; ls k8s_*.yaml)
TEMPLATES=$(cd etc; ls k8s_*.yaml) || true

NOCHECK=
[[ ${1:-} == "--no-check" ]] && NOCHECK=1 && shift
Expand Down Expand Up @@ -91,7 +91,7 @@ if [[ -n $prep ]]; then
rm -rf var tmp && mkdir -p var tmp

cp -f etc/*.json var/ || true
cp -a ../schema tmp/
cp -a ../schema build/

bin/build

Expand Down
38 changes: 0 additions & 38 deletions bin/docker_udmis

This file was deleted.

9 changes: 8 additions & 1 deletion bin/keygen
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ else
SUBJ=client
fi

TARGET_HOST=localhost
if [[ $type =~ ^CERT/ || $type =~ ^CA/ ]]; then
TARGET_HOST=${type#*/}
type=${type%/*}
echo Generating $type with altname $TARGET_HOST
fi

CA_CRT=$CA_DIR/ca.crt
CA_SRL=$CA_DIR/ca.srl
CA_KEY=$CA_DIR/rsa_private.pem
OPTS_509=/tmp/x509opts.txt

echo "subjectAltName=DNS:localhost, IP:127.0.0.1" > $OPTS_509
echo "subjectAltName=DNS:${TARGET_HOST}, IP:127.0.0.1, DNS:localhost" > $OPTS_509
x509opts="-days 3650 -extfile $OPTS_509"

if [[ $type == CA ]]; then
Expand Down
3 changes: 1 addition & 2 deletions bin/mosquctl_log
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/bin/bash -e

UDMI_ROOT=$(dirname $0)/..
source $UDMI_ROOT/etc/shell_common.sh
cd $UDMI_ROOT

LOG_FILE=/var/log/mosquitto/mosquitto.log

source $UDMI_ROOT/etc/shell_common.sh

if [[ $# != 1 ]]; then
echo Usage: $0 client_id_prefix
false
Expand Down
9 changes: 8 additions & 1 deletion bin/pubber
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ echo Cleaning output directory $UDMI_ROOT/pubber/out/$serial_no
rm -rf $UDMI_ROOT/pubber/out/$serial_no

echo Building pubber...
$UDMI_ROOT/pubber/bin/build
[[ ! -d $UDMI_ROOT/pubber/src ]] || $UDMI_ROOT/pubber/bin/build

echo Running tools version $udmi_version

Expand Down Expand Up @@ -172,6 +172,13 @@ fi

jq --slurpfile endpoint $ENDPOINT_TMP '.endpoint = $endpoint[0]' $tmp_config | sponge $tmp_config

if [[ -f ${site_model:-}/reflector/ca.crt && -n ${project_target:-} ]]; then
echo Checking for signed device certificate...
certs=(${site_model}/devices/${target_id}/*.crt) || true
[[ -f $certs ]] || $UDMI_ROOT/bin/keygen CERT/${project_target} ${site_model}/devices/${target_id}/
ls -l ${site_model}/devices/${target_id}/*.crt
fi

# Run in the background to force new process group and get PID
$UDMI_ROOT/pubber/bin/run $tmp_config &
PUB_PID=$!
Expand Down
4 changes: 1 addition & 3 deletions bin/sequencer
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fi

cat $SEQUENCER_CONFIG

validator/bin/build
[[ ! -d $UDMI_ROOT/validator/src ]] || $UDMI_ROOT/validator/bin/build

echo $JAVA_CMD
result=0
Expand All @@ -192,5 +192,3 @@ fgrep RESULT $site_model/out/devices/$device_id/RESULT.log | \
more $site_model/out/devices/$device_id/RESULT.log $SCHEMA_OUT | cat

bin/sequencer_report $site_model $device_id

bin/check_version
11 changes: 10 additions & 1 deletion bin/setup_base
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
ROOT_DIR=$(realpath $(dirname $0)/..)
cd $ROOT_DIR

sudo apt-get install -y moreutils expect mosquitto mosquitto-clients
if [[ -n $(which apt-get) ]]; then
update_cmd="apt-get install -y"
extra_packages=""
else
update_cmd="apk add"
# Some extra packages are necessary for alpine based docker builds.
extra_packages="linux-headers g++ gcc"
fi

sudo $update_cmd $extra_packages moreutils expect python3-dev mosquitto mosquitto-clients

python3 --version
python3 -m venv venv
Expand Down
11 changes: 4 additions & 7 deletions bin/setup_ca
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ source $UDMI_ROOT/etc/shell_common.sh
CERT_DIR=/etc/mosquitto/certs/
sudo rm -f $CERT_DIR/*

[[ $# != 1 ]] && fail $0 site_model
[[ $# != 2 ]] && fail $0 site_model hostname

site_model=$(realpath $1)
target=$2

cd $UDMI_ROOT

bin/keygen CA $site_model/reflector
bin/keygen CERT $site_model/reflector
bin/keygen CA/$target $site_model/reflector
bin/keygen CERT/$target $site_model/reflector

echo Importing server certs from $site_model...
sudo cp $site_model/reflector/ca.* $CERT_DIR/
sudo cp $site_model/reflector/rsa_private.* $CERT_DIR/
sudo chgrp -R mosquitto $CERT_DIR
sudo chmod 0640 $CERT_DIR/rsa_private.*
ls -l $CERT_DIR




7 changes: 4 additions & 3 deletions bin/start_etcd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

IMAGE=quay.io/coreos/etcd:v3.5.13
BINDIR=/tmp/etcd
ETCD_LOG=/tmp/etcd.log

echo pwd: $(pwd)

Expand All @@ -11,11 +12,11 @@ $BINDIR/etcd -version

$BINDIR/etcd -listen-client-urls=http://0.0.0.0:2379 \
-advertise-client-urls=http://127.0.0.1:2379 \
> etcd.log 2>&1 &
> $ETCD_LOG 2>&1 &
ETCD_PID=$!

echo Waiting 10s for etcd to start...
echo Waiting 10s for etcd to start, log in $ETCD_LOG
sleep 10
[[ -d /proc/$ETCD_PID ]] || (cat etcd.log && fail starting etcd)
[[ -d /proc/$ETCD_PID ]] || (cat $ETCD_LOG && echo error starting etcd && false)

echo Completed etcd startup.
12 changes: 10 additions & 2 deletions bin/start_local
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,34 @@ if [[ -d var/ && ! -d etc/ ]]; then
fi

cd $UDMI_ROOT
UDMIS_LOG=/tmp/udmis.log
mkdir -p out
date > $UDMIS_LOG

if [[ ! $project_spec =~ ^//mqtt/ ]]; then
echo Not a local setup, doing nothing!
echo Not a local setup, doing nothing! || tee -a $UDMIS_LOG
exit 0
fi

project_target=${project_spec##*/}
site_config=$site_model/cloud_iot_config.json
registry_id=$(jq -r .registry_id $site_config)${UDMI_REGISTRY_SUFFIX:-}

echo Starting etcd... | tee -a $UDMIS_LOG
bin/start_etcd

source $UDMI_ROOT/etc/mosquitto_ctrl.sh
mkdir -p $CERT_DIR

bin/setup_ca $site_model
echo Starting mosquitto on server $project_target | tee -a $UDMIS_LOG
bin/setup_ca $site_model $project_target
bin/start_mosquitto

$MOSQUITTO_CTRL deleteClient $SERV_USER
$MOSQUITTO_CTRL createClient $SERV_USER -p $SERV_PASS # No client_id to allow multiple backend connections.
$MOSQUITTO_CTRL addClientRole $SERV_USER service

echo Starting initializing site $site_model | tee -a $UDMIS_LOG
bin/mosquctl_site $site_model

if [[ -n ${UDMI_ALT_REGISTRY:-} ]]; then
Expand All @@ -55,6 +62,7 @@ fi
# Global access to logs for connection tracking by UDMIS.
sudo chmod a+r /var/log/mosquitto/mosquitto.log

echo Starting udmis proper... | tee -a $UDMIS_LOG
bin/start_udmis

echo Done with local server setup.
Expand Down
7 changes: 4 additions & 3 deletions bin/start_mosquitto
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ GROUP=mosquitto
UDMI_FILE=$ETC_DIR/conf.d/udmi.conf
PASS_FILE=$ETC_DIR/mosquitto.passwd
DYN_FILE=$ETC_DIR/dynamic_security.json
MOSQUITTO_LOG=/var/log/mosquitto/mosquitto.log

mkdir -p /var/log/mosquitto/
sudo mkdir -p $(dirname $MOSQUITTO_LOG)

if [[ ! -f $UDMI_FILE ]]; then
echo Creating new $UDMI_FILE from template...
Expand Down Expand Up @@ -51,11 +52,11 @@ if [[ -n $(which systemctl) ]]; then
sudo systemctl restart mosquitto
else
# Raw mode for running (e.g.) in a docker container
mosquitto -c $ETC_DIR/mosquitto.conf > mosquitto.log 2>&1 &
mosquitto -c $ETC_DIR/mosquitto.conf > $MOSQUITTO_LOG 2>&1 &
MOSQUITTO_PID=$!
echo Waiting 10s for background mosquitto to start...
sleep 10
[[ -d /proc/$MOSQUITTO_PID ]] || (cat mosquitto.log && fail starting mosquitto)
[[ -d /proc/$MOSQUITTO_PID ]] || (cat $MOSQUITTO_LOG && fail starting mosquitto)
echo Completed mosquitto startup.
fi

Expand Down
5 changes: 2 additions & 3 deletions bin/start_udmis
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ fi

bin/container udmis prep --no-check || true

mkdir -p out
LOGFILE=out/udmis.log
LOGFILE=/tmp/udmis.log
date > $LOGFILE

export ETCD_CLUSTER=localhost
Expand All @@ -32,7 +31,7 @@ export SSL_SECRETS_DIR=/etc/mosquitto/certs
UDMIS_DIR=udmis
[[ -d $UDMIS_DIR ]] || UDMIS_DIR=..

sudo PATH=$PATH -E $UDMIS_DIR/bin/run $UDMIS_DIR/etc/local_pod.json > $LOGFILE 2>&1 &
sudo PATH=$PATH -E $UDMIS_DIR/bin/run $UDMIS_DIR/etc/local_pod.json >> $LOGFILE 2>&1 &

PID=$!

Expand Down
6 changes: 3 additions & 3 deletions bin/test_mosquitto
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CLNT_USER=kiwi
CLNT_PASS=possum
CLNT_ID=$registry_id/client

sudo chmod a+r $CERT_DIR/rsa_private.*
sudo chmod a+r $CERT_DIR/rsa_private.* || true
bin/keygen CERT $CLIENT_DIR

CLIENT_OPTS="-i $CLNT_ID -u $CLNT_USER -P $CLNT_PASS --cafile $CA_CERT --cert $CLIENT_DIR/rsa_private.crt --key $CLIENT_DIR/rsa_private.pem"
Expand All @@ -51,7 +51,7 @@ mosquitto_pub $CLIENT_OPTS -t $topic -m "Hello Racket"
sleep 1

echo Checking received message
fgrep Racket out/mosquitto.sub
fgrep Racket out/mosquitto.sub || fail did not find expected message

hash_pass=$(sha256sum < $site_path/devices/$device_id/rsa_private.pkcs8)
dev_pass=${hash_pass:0:8}
Expand Down Expand Up @@ -113,7 +113,7 @@ echo Received messages:
cat out/mosquitto.sub | cut -c -120

echo Checking received end message
fgrep Rudolph out/mosquitto.sub
fgrep Rudolph out/mosquitto.sub || fail did not find expected message

echo Checking messages for matching serial no $serial_no
received_no=$(fgrep operational out/mosquitto.sub | head -n 1 | sed -E 's/^[^{]+//' | jq -r .system.serial_no)
Expand Down
2 changes: 1 addition & 1 deletion bin/toolrun
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OUT_DIR=$UDMI_ROOT/out
mkdir -p $OUT_DIR
rm -f $OUT_DIR/$util_name.log

$UDMI_ROOT/validator/bin/build
[[ ! -d $UDMI_ROOT/validator/src ]] || $UDMI_ROOT/validator/bin/build

JAVA_CLASS=com.google.daq.mqtt.util.Dispatcher

Expand Down
2 changes: 0 additions & 2 deletions bin/validator
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,3 @@ cat $site_file
echo Running tools version $udmi_version

$UDMI_ROOT/validator/bin/validate $site_file $* 2>&1 | tee $OUT_DIR/validator.log

bin/check_version
Loading