Skip to content

Commit 7d5e383

Browse files
authored
Merge pull request #132 from dedis/apt-package
deb packaging for dvoting (without unikernel)
2 parents ff7f119 + fb9120a commit 7d5e383

File tree

15 files changed

+321
-1
lines changed

15 files changed

+321
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ web/app/node_modules
66
.idea
77

88
memcoin
9+
deb-package/dist/**

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ test_integration:
2222
go test ./integration
2323

2424
build:
25-
go build -ldflags="-X $(versionFlag) -X $(timeFlag)" ./cli/memcoin
25+
go build -ldflags="-X $(versionFlag) -X $(timeFlag)" ./cli/memcoin
26+
27+
deb:
28+
GOOS=linux GOARCH=amd64 make build
29+
cd deb-package; ./build-deb.sh; cd ..

deb-package/README.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Packaging D-Voting in an installable .deb file
2+
3+
## Requirements
4+
5+
- gem
6+
- build-essential
7+
- git
8+
- fpm (`sudo gem install fpm`)
9+
- go (see https://go.dev/doc/install)
10+
11+
```sh
12+
sudo apt install rubygems build-essential git
13+
```
14+
15+
## Get the code
16+
17+
```sh
18+
git clone --branch packaging https://github.com/dedis/d-voting.git --recursive
19+
```
20+
21+
## Build the deb package
22+
23+
from the root folder, use make:
24+
25+
```sh
26+
make deb
27+
```
28+
29+
Make sure that a git tag exist, i.e `git describe` shows your tag.
30+
31+
The resulting .deb can be found in the `dist/` folder.
32+
33+
## Things to do after install
34+
35+
### Network config
36+
37+
Ensure that the public address is correct. For instance, in `network.env`, replace:
38+
```sh
39+
export dela_public="//localhost:9000"
40+
```
41+
with the node's public address:
42+
```sh
43+
export dela_public="//172.16.253.150:9000"
44+
```
45+
46+
### Leader's node
47+
48+
Get the token and certificate (24h * 30 = 720):
49+
50+
```sh
51+
sudo memcoin --config /var/opt/dedis/dvoting/data/dela minogrpc token \
52+
--expiration 720h
53+
```
54+
55+
This result, which looks like as follow, will be given to node's operators:
56+
57+
```
58+
--token b6VhdQEPXKOtZHpng8E8jw== --cert-hash oNeyrA864P2cP+TT6IE6GvkeEI/Ec4rOlZWEWiQkQKk=
59+
```
60+
61+
### Participants (node's operators)
62+
63+
Join the network. This operation will make the node share its certificate to the
64+
MASTER node, which, in turn, will share its known certificates to the node. Note
65+
that the certificates are stored in the DB, which means that this operation must
66+
be re-done in case the DB is reset.
67+
68+
```sh
69+
sudo memcoin --config /var/opt/dedis/dvoting/data/dela minogrpc join \
70+
--address <MASTER NODE ADDRESS> --token <TOKEN> --cert-hash <CERT HASH>
71+
```
72+
73+
Example of `<MASTER NODE ADDRESS>`: `'//172.16.253.150:9000'`
74+
75+
Get the node's address and public key:
76+
77+
```sh
78+
sudo memcoin --config /var/opt/dedis/dvoting/data/dela ordering export
79+
```
80+
81+
This will yield a base64 encoded string `<ADDRESS>:<PUB KEY>`.
82+
83+
It will have to be provided to EPFL.
84+
85+
## Setup the chain, from EPFL
86+
87+
**1: Create the chain**:
88+
89+
Do not forget to include ourself, the EPFL node!
90+
91+
```sh
92+
sudo memcoin --config /var/opt/dedis/dvoting/data/dela ordering setup \
93+
--member <RESULT FROM ordering export>\
94+
--member <...>
95+
...
96+
```
97+
98+
**2: grant access for each node to sign transactions on the evoting smart contract**:
99+
100+
```sh
101+
PK=<> # taken from the "ordering export", the part after ":"
102+
sudo memcoin --config /var/opt/dedis/dvoting/data/dela pool add \
103+
--key /home/user/master.key \
104+
--args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access \
105+
--args access:grant_id --args 0300000000000000000000000000000000000000000000000000000000000000 \
106+
--args access:grant_contract --args go.dedis.ch/dela.Evoting \
107+
--args access:grant_command --args all \
108+
--args access:identity --args $PK \
109+
--args access:command --args GRANT
110+
```
111+
112+
You should also grant access to the master key.
113+
114+
### Test
115+
116+
```sh
117+
sudo memcoin --config /var/opt/dedis/dvoting/data/dela e-voting scenarioTest \
118+
--proxy-addr1 "http://192.168.232.133:9080" \
119+
--proxy-addr2 "http://192.168.232.134:9080" \
120+
--proxy-addr3 "http://192.168.232.135:9080"
121+
```

deb-package/build-deb.sh

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#! /usr/bin/env bash
2+
set -xe
3+
4+
# cleanup previous installations
5+
rm -rf deb
6+
7+
# create binaries dir
8+
INSTALL_DIR="deb/opt/dedis/dvoting/bin"
9+
mkdir -p $INSTALL_DIR
10+
11+
DVOTING_CLI_DIR="$PWD/.."
12+
cp $DVOTING_CLI_DIR/memcoin $INSTALL_DIR
13+
14+
# Prometheus Node Exporter
15+
NE_DIR="deb/opt/exporter"
16+
NE_VERSION="1.3.1"
17+
mkdir -p ${NE_DIR}
18+
wget https://github.com/prometheus/node_exporter/releases/download/v${NE_VERSION}/node_exporter-${NE_VERSION}.linux-amd64.tar.gz
19+
tar xfz node_exporter-${NE_VERSION}.linux-amd64.tar.gz
20+
mv node_exporter-${NE_VERSION}.linux-amd64/* ${NE_DIR}/
21+
rm -rf node_exporter-${NE_VERSION}.linux-amd64*
22+
23+
# add config files
24+
cp -a pkg/etc deb
25+
cp -a pkg/lib deb
26+
cp -a pkg/opt deb
27+
cp -a pkg/var deb
28+
29+
# add folders
30+
mkdir -p deb/var/log/dedis/dvoting
31+
32+
# adjust permissions
33+
find deb ! -perm -a+r -exec chmod a+r {} \;
34+
35+
# get version from git without v prefix
36+
GITVERSION=$(git describe --abbrev=0 --tags)
37+
VERSION=${GITVERSION:1}
38+
if [[ -z "${ITERATION}" ]]
39+
then
40+
ITERATION="0"
41+
fi
42+
43+
# fpm needs an existing output directory
44+
OUTPUT_DIR="dist"
45+
mkdir -p $OUTPUT_DIR
46+
47+
fpm \
48+
--force -t deb -a all -s dir -C deb -n dedis-dvoting -v ${VERSION} \
49+
--iteration ${ITERATION} \
50+
--deb-user dvoting \
51+
--deb-group dvoting \
52+
--depends net-tools \
53+
--before-install pkg/before-install.sh \
54+
--after-install pkg/after-install.sh \
55+
--before-remove pkg/before-remove.sh \
56+
--after-remove pkg/after-remove.sh \
57+
--url https://dedis.github.com/dedis/dvoting \
58+
--description 'D-Voting package' \
59+
--package dist .
60+
61+
# cleanup
62+
rm -rf ./deb

deb-package/pkg/after-install.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
# fix permissions
4+
# dvoting:dedis will be applied automatically on sub dirs
5+
chown root:root /opt/dedis
6+
7+
# allow ls in sub dirs
8+
chmod 755 /opt/dedis
9+
chmod 755 /opt/exporter
10+
11+
chown root:root /lib/systemd/system
12+
13+
enable_service() {
14+
SERVICE=$1
15+
# Inspired from Debian packages (e.g. /var/lib/dpkg/info/openssh-server.postinst)
16+
# was-enabled defaults to true, so new installations run enable.
17+
if deb-systemd-helper --quiet was-enabled ${SERVICE}; then
18+
# Enables the unit on first installation, creates new
19+
# symlinks on upgrades if the unit file has changed.
20+
deb-systemd-helper enable ${SERVICE} >/dev/null || true
21+
else
22+
# Update the statefile to add new symlinks (if any), which need to be
23+
# cleaned up on purge. Also remove old symlinks.
24+
deb-systemd-helper update-state ${SERVICE} >/dev/null || true
25+
fi
26+
}
27+
28+
DVOTING_SERVICE=dvoting.service
29+
enable_service ${DVOTING_SERVICE}
30+
systemctl start ${DVOTING_SERVICE}
31+
32+
ln -s /opt/dedis/dvoting/bin/memcoin /usr/bin/memcoin
33+
34+
enable_service exporter.service
35+
systemctl start exporter.service

deb-package/pkg/after-remove.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
# Inspired from Debian packages (e.g. /var/lib/dpkg/info/openssh-server.postinst)
4+
# In case this system is running systemd, we make systemd reload the unit files
5+
# to pick up changes.
6+
if [ -d /run/systemd/system ] ; then
7+
systemctl --system daemon-reload >/dev/null || true
8+
fi
9+
10+
if [ -x "/usr/bin/deb-systemd-helper" ]; then
11+
deb-systemd-helper purge dvoting.service >/dev/null
12+
fi

deb-package/pkg/before-install.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
# create dvoting group
4+
if ! getent group dvoting >/dev/null; then
5+
groupadd -r dvoting
6+
fi
7+
8+
# create dedis group
9+
if ! getent group dedis >/dev/null; then
10+
groupadd -r dedis
11+
fi
12+
13+
# create dvoting user
14+
if ! getent passwd dvoting >/dev/null; then
15+
useradd -M -r -g dedis -d /var/opt/dedis/dvoting \
16+
-s /usr/sbin/nologin -c "D-Voting user" dvoting
17+
fi
18+
19+
# modify user to be in these groups
20+
usermod -aG dedis dvoting

deb-package/pkg/before-remove.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# stop service
4+
systemctl stop dvoting.service
5+
systemctl stop exporter.service
6+
7+
rm -f /usr/bin/memcoin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export proxy_addr="0.0.0.0:9080"
2+
export prometheus_addr="0.0.0.0:9100"
3+
export node_exporter_addr="0.0.0.0:9101"
4+
5+
export dela_listen="tcp://0.0.0.0:9000"
6+
export dela_public="//localhost:9000"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[Unit]
2+
Description=D-Voting Node Service
3+
After=network.target
4+
5+
[Service]
6+
User=dvoting
7+
8+
ExecStartPre=/bin/rm -f /var/opt/dedis/dvoting/data/dela/daemon.sock
9+
ExecStart=/opt/dedis/dvoting/bin/start-dvoting
10+
11+
KillSignal=SIGINT
12+
13+
Restart=on-failure
14+
RestartSec=5
15+
16+
[Install]
17+
WantedBy=multi-user.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=Prometheus Node Service
3+
4+
[Service]
5+
User=dvoting
6+
7+
ExecStart=/opt/dedis/dvoting/bin/start-exporter
8+
9+
KillSignal=SIGINT
10+
11+
Restart=on-failure
12+
RestartSec=1
13+
14+
[Install]
15+
WantedBy=multi-user.target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
sleep 5
4+
5+
source /opt/dedis/dvoting/config/config.env
6+
source /etc/dedis/dvoting/network.env
7+
8+
echo "Starting ${dela_bin} on ${dela_listen} using folder ${dela_data} ..."
9+
10+
LLVL=info ${dela_bin} --config ${dela_data} start --postinstall --promaddr ${prometheus_addr} --proxyaddr ${proxy_addr} --listen ${dela_listen} --public ${dela_public} --proxykey ${dela_proxy_pk}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
source /etc/dedis/dvoting/network.env
4+
5+
/opt/exporter/node_exporter --web.listen-address=${node_exporter_addr} --collector.systemd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# dela config
2+
export dela_bin="/opt/dedis/dvoting/bin/memcoin"
3+
export dela_data="/var/opt/dedis/dvoting/data/dela"
4+
export dela_proxy_pk=3c07e93b9d99032366f7d92697f8dc1337bf8bb617b3faa6389e94d18e3d0e40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000":"eyJFeHByZXNzaW9ucyI6eyJnby5kZWRpcy5jaC9kZWxhLkFjY2VzczphbGwiOnsiSWRlbnRpdGllcyI6W3siTmFtZSI6IkJMUy1DVVJWRS1CTjI1NiIsIkRhdGEiOiJRaEx0WXhPTmkvK0JDT25maDVBSHoyRmkraUxOSnFrVllpMGRPdnc4Y053MDBLMytoS25SNEVoWEUrcWE2bzlKK09wbHNjL2JMeDBSVU9NdmdVQ1VQQ0tDRFk0WC9iblBaNEpZblJNdDdmYURCVnhFRGpsVmVmZ3lGZy9MeWpXbGNlZkJvTTJ5Rlh4NWlZNTZyQTZHblBBMUowbE9ZdThibmU2OUZrQUhyVmM9In1dLCJNYXRjaGVzIjpbWzBdXX19fQ=="}

0 commit comments

Comments
 (0)