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

Packaging #64

Merged
merged 36 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d119f51
added fpm config
jbsv Mar 8, 2022
6d89219
can build unikernel and memcoin
jbsv Mar 9, 2022
0b5d247
update fpm script to copy binaries
jbsv Mar 9, 2022
ae3193d
added packaging documentation
jbsv Mar 9, 2022
f52ed9d
start dvoting service
jbsv Mar 9, 2022
fe78c88
use ip instead of ifconfig in qemu-guest
jbsv Mar 9, 2022
ea5e677
setup dvoting service
jbsv Mar 10, 2022
2f84662
use root for now to start the dvoting service in systemd
jbsv Mar 10, 2022
d16e385
added separate dvoting node service
jbsv Mar 11, 2022
8d3d1b0
start-dvoting script
jbsv Mar 11, 2022
4075cfb
Can start unikernel
jbsv Mar 14, 2022
64e0864
can start services
jbsv Mar 15, 2022
d93b09d
roll back changes in qemu_guest
jbsv Mar 16, 2022
6916467
dvoting user as sudo
jbsv Mar 16, 2022
e6ff823
improved config
jbsv Mar 16, 2022
1666dd7
added unikernel into after/before scripts
jbsv Mar 16, 2022
a82ab09
can use vx.y.z versioning
jbsv Mar 17, 2022
da0e5de
added access ID file
jbsv Mar 17, 2022
fe0f591
added proxy and prometheus addresses
jbsv Mar 17, 2022
22f8625
remove daemon.sock before install
jbsv Mar 17, 2022
783a4d3
added make deb
jbsv Mar 17, 2022
0468c07
force remove of daemon.sock
jbsv Mar 17, 2022
7b55628
updates git module path
nkcr Mar 18, 2022
8d1e423
added symb link to memcoin
jbsv Mar 18, 2022
8535b76
Adds updates to make the setup run on detached VMs
nkcr Mar 18, 2022
5362a2c
Fixes the tests
nkcr Mar 18, 2022
a951ef5
Merge pull request #66 from dedis/updates-multiple-vm-checks
nkcr Mar 18, 2022
a7291d0
Addresses Pierluca's comment
nkcr Mar 21, 2022
5a80d0f
changes after review
jbsv Mar 21, 2022
cd58deb
more changes after review
jbsv Mar 21, 2022
04e5e85
fixed config.env
jbsv Mar 21, 2022
2c1fe16
tidy up config.env after review
jbsv Mar 22, 2022
684e812
can install deb with configs
jbsv Mar 22, 2022
7150e1e
update deployement doc
jbsv Mar 22, 2022
002dc1f
improved deployment doc
jbsv Mar 22, 2022
a73ad11
Merge remote-tracking branch 'origin/unikernel-combine-shares' into p…
jbsv Mar 22, 2022
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ web/app/node_modules
.idea

memcoin
deb-package/deb
deb-package/dist
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "contracts/evoting/unikernel/unikraft"]
path = contracts/evoting/unikernel/unikraft
url = https://github.com/unikraft/unikraft
[submodule "contracts/evoting/unikernel/libs/lwip"]
path = contracts/evoting/unikernel/libs/lwip
url = https://github.com/unikraft/lib-lwip
[submodule "contracts/evoting/unikernel/libs/newlib"]
path = contracts/evoting/unikernel/libs/newlib
url = https://github.com/unikraft/lib-newlib
[submodule "contracts/evoting/unikernel/libs/libsodium"]
path = contracts/evoting/unikernel/libs/libsodium
url = https://github.com/cs-pub-ro/lib-libsodium
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ test_integration:
go test ./integration

build:
go build -ldflags="-X $(versionFlag) -X $(timeFlag)" ./cli/memcoin
go build -ldflags="-X $(versionFlag) -X $(timeFlag)" ./cli/memcoin

deb: build
cd deb-package; ./build-deb.sh; cd ..
101 changes: 60 additions & 41 deletions contracts/evoting/unikernel/apps/combine_shares/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,53 @@ functionality provided by [libsodium](https://github.com/jedisct1/libsodium).

## Requirements

- To build the kernel:

```sh
sudo apt-get install git
sudo apt-get install make
sudo apt-get install gcc
sudo apt-get install libncurses-dev
sudo apt-get install flex
sudo apt-get install bison
sudo apt-get install unzip
sudo apt-get install socat
sudo apt-get install uuid-runtime
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils \
virtinst virt-manager
sudo apt install net-tools
sudo apt install bison build-essentials flex git libncurses-dev unzip
```

## Setup

Apart from the current repository, you also need to clone:
- To run the kernel in a debian VM, the following packages must be installed
in the VM:

* [Unikraft](https://github.com/unikraft/unikraft)
* [lwip](https://github.com/unikraft/lib-lwip)
* [newlib](https://github.com/unikraft/lib-newlib)
* [libsodium](https://github.com/unikraft/lib-libsodium)

Make sure each repository is on the `staging` branch.
```sh
sudo apt install \
bridge-utils \
fuse \
libvirt-clients \
libvirt-daemon-system \
qemu-kvm \
net-tools \
sgabios \
socat \
uuid-runtime \
virtinst \
virt-manager
```

For the libsodium library make sure the following change is included:
https://github.com/unikraft/lib-libsodium/pull/4.
## Setup

It is easiest to use a file hierarchy such as:

```tree
unikernel
┣ apps
┃ ┗ combine_shares
┣ libs
┃ ┣ libsodium
┃ ┣ lwip
┃ ┗ newlib
┗ unikraft
```
.
|-- apps/
| `-- app-smart-contract-config/
|-- libs/
| |-- lwip/
| |-- libsodium/
| `-- newlib/
`-- unikraft/

Please run the following command, which will clone the submodules in the above
illustrated paths:

```sh
git submodule update --init --recursive
```

If you use a file hierarhy different than the one above, then edit the
If you use a file hierarchy different than the one above, then edit the
`Makefile` file and update the variables to point to the correct location:

* Update the `UK_ROOT` variable to point to the location of the Unikraft clone.
Expand All @@ -62,11 +66,23 @@ If you get a `Cannot find library` error at one of the following steps, you may
need to add the `lib-` prefix to the libraries listed in the `LIBS` variable.
For instance, `$(UK_LIBS)/lwip` becomes `$(UK_LIBS)/lib-lwip`.

Here is the list of the required repositories that you also need as submodules:

* [libsodium](https://github.com/unikraft/lib-libsodium)
* [lwip](https://github.com/unikraft/lib-lwip)
* [newlib](https://github.com/unikraft/lib-newlib)
* [Unikraft](https://github.com/unikraft/unikraft)

For the libsodium library, the submodule still points to the source of the following PR:
https://github.com/unikraft/lib-libsodium/pull/4.

For the other libraries, please make sure that each repository is on the `staging` branch.

## Configure

Configure the build by running:
Configure the build by running in `contracts/evoting/unikernel/apps/combine_shares`:

```
```sh
make menuconfig
```

Expand All @@ -75,7 +91,7 @@ configuration is loaded from the `Config.uk` file. Then add support for 9pfs, by
selecting `Library Configuration` -> `vfscore: VFS Core Interface` -> `vfscore:
VFS Configuration`. The select `Automatically mount a root filesystem (/)` and
select `9pfs`. For the `Default root device` option fill `fs0`. You should end
up with an image such as the one in `9pfs_config.png`. Save the conifugration
up with an image such as the one in `9pfs_config.png`. Save the configuration
and exit.

As a result of this, a `.config` file is created.
Expand All @@ -85,21 +101,24 @@ A KVM unikernel image will be built from the configuration.

Build the unikernel KVM image by running:

```
```sh
make
```

The resulting image is in the `build/` subfolder, usually named
`build/app-smart-contract-config_kvm-x86_64`.
`build/combine_shares_kvm-x86_64`.

## Run

The resulting image is to be loaded as part of a KVM virtual machine with a
software bridge allowing outside network access to the server application. Start
the image by using the `run` script (you require `sudo` privileges):

```sh
./start-unikernel unikernel_paths
```
$ ./run

```output
[...]
Booting from ROM...
1: Set IPv4 address 172.44.0.2 mask 255.255.255.0 gw 172.44.0.1
Expand All @@ -126,15 +145,15 @@ the `mnt/` folder.
On another terminal, use `nc` to connect via TCP to the program and send the
commands:

```
$ nc 172.44.0.2 1024
```sh
nc 172.44.0.2 1024
ec_multiply
2c7be86ab07488ba43e8e03d85a67625cfbf98c8544de4c877241b7aaafc7fe3
```

The running program will print out a summary of received commands:

```
```sh
Received connection from 172.44.0.1:38596
Received: ec_multiply
Operation: ec_multiply
Expand Down
10 changes: 10 additions & 0 deletions contracts/evoting/unikernel/apps/combine_shares/config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# dela config
export dela_bin=".../cli/memcoin"
export dela_data=".../tmp/dela"
export dela_port="9000"

# unikernel config
export fs_mount="mnt/"
export kvm_image="./combine_shares_kvm-x86_64"
export qemu_script="./qemu-guest"
export network_config="./unikernel_network"
10 changes: 10 additions & 0 deletions contracts/evoting/unikernel/apps/combine_shares/create-bridge
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

paths=$1

source ${paths}
source ${network_config}

echo "Creating bridge ${bridge_iface} with IP address ${uk_gw} ..."
sudo brctl addbr "${bridge_iface}" || true
sudo ifconfig "${bridge_iface}" "${uk_gw}"
4 changes: 4 additions & 0 deletions contracts/evoting/unikernel/apps/combine_shares/network.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export uk_gw="172.44.0.1"
export uk_ip="172.44.0.2"
export uk_port="1024"
export bridge_iface="uk0"
6 changes: 3 additions & 3 deletions contracts/evoting/unikernel/apps/combine_shares/qemu-guest
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ usage()
echo " -x Run guest in background, a socket is created for the serial output"
echo " -P Create the guest in paused state"
echo " -t [TYPE] Set guest type: x86pc, x86q35, arm64v"
echo " -G [NAME] Set name of guest to NAME"
echo " -U [NAME] Set name of guest to NAME"
echo " -g [PORT] Run a GDB server for the guest at port PORT (e.g., 1234)"
echo " Note: QEMU process stays alive on guest shutdown/reset"
echo " -T [LOGFILE] Enable tracing of CPU events (fine-grained results with -W)"
Expand Down Expand Up @@ -480,7 +480,7 @@ usage()
echo " $0 -c 2 -m 2048 -b virbr0 -b virbr1 -q root.qcow2 -d /dev/sdb -d /dev/sdc"
}

while getopts :hnN:b:V:f:G:d:q:S:I:e:k:i:a:c:m:v:lrs:p:HxCDG:g:PT:WQ:M:t: OPT; do
while getopts :hnN:b:V:f:G:d:q:S:I:e:k:i:a:c:m:v:lrs:p:HxCDUG:g:PT:WQ:M:t: OPT; do
case ${OPT} in
v)
OPT_VIDEOVNC=0
Expand Down Expand Up @@ -666,7 +666,7 @@ EOF
C)
OPT_CTRLC=1
;;
G)
U)
ARG_GUESTNAME="${OPTARG}"
;;
Q)
Expand Down
15 changes: 0 additions & 15 deletions contracts/evoting/unikernel/apps/combine_shares/run

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

paths=$1

source ${paths}
source ${network_config}

echo "Starting KVM image connected to bridge interface ${bridge_iface} ..."
"${qemu_script}" -k "${kvm_image}" -e "${fs_mount}" -b "${bridge_iface}" -m 1024 -a "netdev.ipv4_addr=${uk_ip} netdev.ipv4_gw_addr=${uk_gw} netdev.ipv4_subnet_mask=255.255.255.0 -- ${uk_port}"
1 change: 1 addition & 0 deletions contracts/evoting/unikernel/libs/libsodium
Submodule libsodium added at 771b45
1 change: 1 addition & 0 deletions contracts/evoting/unikernel/libs/lwip
Submodule lwip added at 40f2c7
1 change: 1 addition & 0 deletions contracts/evoting/unikernel/libs/newlib
Submodule newlib added at 243a75
1 change: 1 addition & 0 deletions contracts/evoting/unikernel/unikraft
Submodule unikraft added at 1939bc
25 changes: 25 additions & 0 deletions deb-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Packaging D-Voting in an installable .deb file

## Requirements

- Install `gem` and [fpm](https://fpm.readthedocs.io/en/latest/installation.html):

```sh
sudo apt install rubygems build-essentials
sudo gem install fpm
```

- Build unikernel. See [how to build unikernel](../contracts/evoting/unikernel/apps/combine_shares/README.md):

```sh
cd contracts/evoting/unikernel/apps/combine_shares
git submodule update --init --recursive
make menuconfig
make
```

- Create .deb package:

```sh
make deb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it hard for make deb to automatically make the unikernel and do all of the above? If not, it might be worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not feasible yet, because there is a 'make menuconfig' step where we have to modify the config. We could dig into that to have a default config, but it might take quite some time for little value right now.

```
69 changes: 69 additions & 0 deletions deb-package/build-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#! /usr/bin/env bash
set -xe

# cleanup previous installations
rm -rf deb

# create binaries dir
INSTALL_DIR="deb/opt/dedis/dvoting/bin"
mkdir -p $INSTALL_DIR

# copy binaries to deb/opt/dedis/dvoting/bin
UKAPP_DIR="../contracts/evoting/unikernel/apps/combine_shares"
cp $UKAPP_DIR/create-bridge $INSTALL_DIR
cp $UKAPP_DIR/start-unikernel $INSTALL_DIR
cp $UKAPP_DIR/qemu-guest $INSTALL_DIR
cp $UKAPP_DIR/build/combine_shares_kvm-x86_64 $INSTALL_DIR

DVOTING_CLI_DIR=".."
cp $DVOTING_CLI_DIR/memcoin $INSTALL_DIR

# add config files
cp -a pkg/etc deb
cp -a pkg/lib deb
cp -a pkg/opt deb
cp -a pkg/var deb

# add folders
mkdir -p deb/var/log/dedis/dvoting

# adjust permissions
find deb ! -perm -a+r -exec chmod a+r {} \;

# get version from git without v prefix
GITVERSION=$(git describe --abbrev=0)
VERSION=${GITVERSION:1}
if [[ -z "${ITERATION}" ]]
then
ITERATION="0"
fi

# fpm needs an existing output directory
OUTPUT_DIR="dist"
mkdir -p $OUTPUT_DIR

fpm \
--force -t deb -a all -s dir -C deb -n dedis-dvoting -v ${VERSION} \
--iteration ${ITERATION} \
--deb-user dvoting \
--deb-group dvoting \
--depends bridge-utils \
--depends fuse \
--depends qemu-kvm \
--depends libvirt-daemon-system \
--depends net-tools \
--depends sgabios \
--depends socat \
--depends uuid-runtime \
--depends virtinst \
--depends virt-manager \
--before-install pkg/before-install.sh \
--after-install pkg/after-install.sh \
--before-remove pkg/before-remove.sh \
--after-remove pkg/after-remove.sh \
--url https://dedis.github.com/dedis/dvoting \
--description 'D-Voting package for Unicore' \
--package dist .

# cleanup
rm -rf ./deb
Loading