Skip to content

Commit

Permalink
Adds release actions for web apps
Browse files Browse the repository at this point in the history
- adds instructions to build and run the web frontend/backend
  • Loading branch information
nkcr committed Nov 28, 2022
1 parent 9891200 commit e8db46e
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 108 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/go_release.yml

This file was deleted.

149 changes: 149 additions & 0 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: Releases

on:
release:
types: [published]

jobs:
memcoin:
name: release memcoin and .deb
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v3

- name: Use go
uses: actions/setup-go@v3
with:
go-version: '>=1.18'

- name: Install fpm
run: |
sudo apt-get update
sudo apt-get install ruby-dev build-essential
sudo gem install fpm -f
- name: build artifacts
# builds the binary and the .deb
run: make deb

- name: Publish release to aptly
env:
APTLY_USER: ${{ secrets.APTLY_USER }}
APTLY_PASSWORD: ${{ secrets.APTLY_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
./deb-package/upload-artifacts.sh deb-package/dist
- name: Update artifacts to Github's release
uses: softprops/action-gh-release@v1
with:
files: |
memcoin-*
deb-package/dist/*
backend:
name: release the web backend
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./web/backend

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18

- name: Get the version
id: get_version
run: |
echo ::set-output name=version::$(echo ${GITHUB_REF/refs\/tags\//})
echo ::set-output name=version_file::web-backend-$(echo ${GITHUB_REF/refs\/tags\//} | tr . _)
echo "::set-output name=shortsha::$(git rev-parse --short ${GITHUB_SHA})"
echo "::set-output name=buildurl::${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
echo "::set-output name=date::$(date +'%d/%m/%y %H:%M')"
- name: install
run: |
npm install
- name: transpile
env:
NODE_ENV: production
run: |
./node_modules/.bin/tsc --outDir ./build/
- name: Pack folder
run: |
npm prune --production
mkdir ${{ steps.get_version.outputs.version_file }}
cd ${{ steps.get_version.outputs.version_file }}
cp -r ../build/* .
cp -r ../node_modules .
cp -r ../dbUtils.js .
cp -r ../config.env.template .
- name: Create tar.gz
run: |
tar -czvf ${{ steps.get_version.outputs.version_file }}.tar.gz ${{ steps.get_version.outputs.version_file }}
- name: Upload release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: web/backend/${{ steps.get_version.outputs.version_file }}.tar.gz

fontend:
name: release the web frontend
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./web/frontend

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18

- name: Get the version
id: get_version
run: |
echo ::set-output name=version::$(echo ${GITHUB_REF/refs\/tags\//})
echo ::set-output name=version_file::web-frontend-$(echo ${GITHUB_REF/refs\/tags\//} | tr . _)
echo "::set-output name=shortsha::$(git rev-parse --short ${GITHUB_SHA})"
echo "::set-output name=buildurl::${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
echo "::set-output name=date::$(date +'%d/%m/%y %H:%M')"
- name: install
run: |
npm install
- name: save config variables
run: |
echo "REACT_APP_VERSION=${{ steps.get_version.outputs.version }}" >> .env.production
echo "REACT_APP_BUILD=${{ steps.get_version.outputs.shortsha }}" >> .env.production
echo "REACT_APP_BUILD_TIME=${{ steps.get_version.outputs.date }}" >> .env.production
- name: transpile
env:
NODE_ENV: production
HTTPS: true
BUILD_PATH: ./build/
CI: false
run: |
./node_modules/.bin/react-scripts build
- name: Create tar.gz
run: |
tar -czvf ${{ steps.get_version.outputs.version_file }}.tar.gz ./build
- name: Upload release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: web/frontend/${{ steps.get_version.outputs.version_file }}.tar.gz
131 changes: 101 additions & 30 deletions deb-package/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,72 @@
# Packaging D-Voting in an installable .deb file
# Run the web backend

## Requirements
You need to have node 18.x version.

- gem
- build-essential
- git
- fpm (`sudo gem install fpm`)
- go (see https://go.dev/doc/install)
1) Install dependencies and transpile:

```sh
sudo apt install rubygems build-essential git
cd web/frontend
npm install --production
NODE_ENV=production ./node_modules/.bin/tsc --outDir build
```

## Get the code
2) Copy `node_modules`, `config.env`, and `dbUtil.js` somewhere.

3) Run the web backend:

```sh
git clone --branch packaging https://github.com/dedis/d-voting.git --recursive
source x/y/config.env && \
NODE_ENV=production PORT=6000 NODE_PATH=x/y/node_modules \
/usr/bin/node /x/y/build/Server.js
```

## Build the deb package
`Server.js` is the result of the transpilation. Replace locations appropriately
and be sure to *export* variables in `config.env` (i.e do `export xx=yy`).
However it is recommended to use a service manager such as systemd to run the
app.

from the root folder, use make:
4) Use dbUtils.js

You can manually update the rights with `dbUtils.js`:

```sh
make deb
NODE_PATH=./node_modules node -e 'require("./dbUtils").listEls("../data/dvoting-users")'
```

Make sure that a git tag exist, i.e `git describe` shows your tag.
# Run the web frontend

The resulting .deb can be found in the `dist/` folder.
You need to have node 18.x version.

## Things to do after install
1) Install dependencies and transpile:

### Network config
```sh
cd web/frontend
npm install --production
NODE_ENV=production HTTPS=true BUILD_PATH=x/y/build ./node_modules/.bin/react-scripts build
```

2) Configure an HTTP server

You should server the `x/y/build` folder and proxy all requests on `/api` to the
web backend. For example with nginx:

```
location / {
root /x/y/build;
index index.html;
autoindex on;
try_files $uri /index.html;
}
location /api {
proxy_pass http://127.0.0.1:6000;
}
```

# Configure a network of nodes

## Network config

Ensure that the public address is correct. For instance, in
`/etc/dedis/dvoting/config.env`, replace:
Expand All @@ -49,7 +83,18 @@ export dela_public="//172.16.253.150:9000"

and don't forget to restart the service!

### Leader's node
```sh
service d-voting restart
```

## Create a roster

If you keep TLS encryption at the gRPC level, you must share the certificates
between the nodes. To do that you generate credentials on the first node, and
make all other nodes send their certificates to the first node using the
credentials.

**generate credentials** (on the first node):

Get the token and certificate (24h * 30 = 720):

Expand All @@ -64,7 +109,7 @@ This result, which looks like as follow, will be given to node's operators:
--token b6VhdQEPXKOtZHpng8E8jw== --cert-hash oNeyrA864P2cP+TT6IE6GvkeEI/Ec4rOlZWEWiQkQKk=
```

### Participants (node's operators)
**share certificates** (all other nodes):

Join the network. This operation will make the node share its certificate to the
MASTER node, which, in turn, will share its known certificates to the node. Note
Expand All @@ -78,21 +123,21 @@ sudo memcoin --config /var/opt/dedis/dvoting/data/dela minogrpc join \

Example of `<MASTER NODE ADDRESS>`: `'//172.16.253.150:9000'`

Get the node's address and public key:
## Setup the chain

First get the address of all nodes by running:

```sh
sudo memcoin --config /var/opt/dedis/dvoting/data/dela ordering export
```

This will yield a base64 encoded string `<ADDRESS>:<PUB KEY>`.

It will have to be provided to EPFL.

## Setup the chain, from EPFL
From the first node.

**1: Create the chain**:

Do not forget to include ourself, the EPFL node!
Include ALL nodes, the first and all other nodes.

```sh
sudo memcoin --config /var/opt/dedis/dvoting/data/dela ordering setup \
Expand All @@ -103,6 +148,8 @@ sudo memcoin --config /var/opt/dedis/dvoting/data/dela ordering setup \

**2: grant access for each node to sign transactions on the evoting smart contract**:

To be done on each node.

```sh
PK=<> # taken from the "ordering export", the part after ":"
sudo memcoin --config /var/opt/dedis/dvoting/data/dela pool add \
Expand All @@ -115,13 +162,37 @@ sudo memcoin --config /var/opt/dedis/dvoting/data/dela pool add \
--args access:command --args GRANT
```

You should also grant access to the master key.
# Package D-Voting in an installable .deb file

### Test
A .deb package is created by the CI upon the creation of a release. You might
want to check `deb-package/upload-artifacts.sh` and the `go_release.yml` action.

## Requirements

- gem
- build-essential
- git
- fpm (`sudo gem install fpm`)
- go (see https://go.dev/doc/install)

```sh
sudo memcoin --config /var/opt/dedis/dvoting/data/dela e-voting scenarioTest \
--proxy-addr1 "http://192.168.232.133:9080" \
--proxy-addr2 "http://192.168.232.134:9080" \
--proxy-addr3 "http://192.168.232.135:9080"
sudo apt install rubygems build-essential git
```

## Get the code

```sh
git clone https://github.com/dedis/d-voting.git
```

## Build the deb package

from the root folder, use make:

```sh
make deb
```

Make sure that a git tag exist, i.e `git describe` shows your tag.

The resulting .deb can be found in the `dist/` folder.
Loading

0 comments on commit e8db46e

Please sign in to comment.