Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #113 from c4dt/archive
Browse files Browse the repository at this point in the history
add docker-compose
  • Loading branch information
ineiti committed May 3, 2023
2 parents 714b2c5 + 20e7393 commit e6d6855
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 71 deletions.
73 changes: 39 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
name: Build and push Docker image, create release

env:
DEPLOY_USER: stainless
DEPLOY_HOST: c4dtsrv1.epfl.ch
name: Build and push Docker image

on:
push:
branches:
- master
- main
pull_request:
branches:

jobs:
build:
name: "Test, build and push Docker image, deploy on c4dtsrv1"
name: Lint, build and test
runs-on: ubuntu-18.04

steps:
Expand Down Expand Up @@ -48,36 +44,45 @@ jobs:
with:
version: "3.19"

- name: Build
run: make backend-build webapp-build

- name: Test
run: |
make backend-test
make backend-serve-test
make webapp-test
run: make backend-test

- name: Build
run: |
make webapp-build
deploy-to-dockerhub:
name: Build and push Docker images
needs: build
if: github.event_name == 'push'
runs-on: ubuntu-18.04
steps:
- uses: docker/setup-buildx-action@v2
- uses: actions/setup-go@v2
with:
go-version: "1.17"
- uses: actions/setup-node@v2
with:
node-version: "10"
- uses: arduino/setup-protoc@v1
with:
version: "3.19"

- name: Push Docker image
if: github.event_name == 'push'
run: >
docker login
--username ${{ secrets.DOCKER_USERNAME }}
--password ${{ secrets.DOCKER_PASSWORD }} &&
docker push c4dt/service-stainless-backend:latest
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Prepare artifact
if: github.event_name == 'push'
run: |
tar -C ./webapp --xz --create --file dist.tar.xz --exclude '*.toml' ./dist
- uses: actions/checkout@v3

- name: Create release
id: create_release
if: github.event_name == 'push'
uses: "marvinpinto/action-automatic-releases@latest"
- run: make configs webapp-proto

- uses: docker/build-push-action@v4
with:
context: backend
push: true
tags: c4dt/service-stainless-backend:latest
- uses: docker/build-push-action@v4
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: "latest"
title: "Development build"
files: |
dist.tar.xz
context: webapp
push: true
tags: c4dt/service-stainless-backend:latest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/services/
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ $Dbackend/build/config_bevm.toml: $Dbackend/build/ident_bevm
/^bevm_instance_id:/ {printf("bevmInstanceID = \"%s\"\n", $$2)} \
' $^ > $@

$Swebapp-build $Swebapp-test $Swebapp-serve: $Dwebapp/src/assets/config_bevm.toml $Dwebapp/src/assets/conodes_stainless.toml
$Swebapp-build $Swebapp-test $Swebapp-serve: $Dwebapp/src/assets/configs/bevm.toml $Dwebapp/src/assets/configs/stainless.toml

$Dwebapp/src/assets/config_bevm.toml: $Dbackend/build/config_bevm.toml
$Dwebapp/src/assets/configs/bevm.toml: $Dbackend/build/config_bevm.toml | $Dwebapp/src/assets/configs/
cp $^ $@

$Dwebapp/src/assets/conodes_stainless.toml: $Dwebapp/src/assets/$(toml_filename)
$Dwebapp/src/assets/configs/stainless.toml: $Dwebapp/src/assets/configs/$(toml_filename) | $Dwebapp/src/assets/configs/
cp $^ $@

$Dsrc/Implementation/%_pb2.py: $Dprotobuf/%.proto
Expand All @@ -74,3 +74,9 @@ seq-diagram.png: seq-diagram.txt
ifneq ($S,)
all: $Sall
endif

.PHONY: configs
configs: webapp/src/assets/configs/byzcoin.toml
configs: webapp/src/assets/configs/bevm.toml
configs: webapp/src/assets/configs/conodes.toml
configs: webapp/src/assets/configs/stainless.toml
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@

Steps to run locally:

You first need to generate the node's configs
```
make webapp-build
make configs
```

Then, in one terminal, run:

If you want our prebuilt images
```
make webapp-serve
docker-compose pull
```
Else if you want to build the images yourself
```
make webapp-proto
docker-compose build
```

And in another terminal:

Launch it with
```
make backend-serve
docker-compose up
```

Finally, point your browser to `http://localhost:4200`.
And open a browser to http://localhost:80/stainless-demo/
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/
/cothority/
/proto/
44 changes: 23 additions & 21 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
FROM debian:stretch-slim
FROM golang:1 as builder

COPY build/*.go build/go.* /src/main/
COPY *.go go.* /backend/
COPY cothority/ /backend/cothority/
COPY proto/ /backend/proto/
COPY stainless/ /backend/stainless/

RUN cd /src/main && go build -v -o /conode

FROM debian:bookworm-slim as runner

# See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199
RUN mkdir -p /usr/share/man/man1
# libgomp is needed for z3
RUN apt-get update; \
apt-get install --no-install-recommends --yes \
procps \
openjdk-8-jre-headless \
libgomp1 \
unzip \
; apt-get clean
# Backports needed for 'npm'...
RUN echo 'deb http://deb.debian.org/debian stretch-backports main' >> /etc/apt/sources.list
RUN apt-get update; \
apt-get install --target-release stretch-backports --no-install-recommends --yes \
npm \
; apt-get clean
RUN npm install --global solc@0.5.10

COPY build/conode.Linux.x86_64 /usr/local/bin/conode
RUN apt update \
&& apt install --no-install-recommends --yes \
procps \
openjdk-17-jre-headless \
libgomp1 \
npm \
unzip \
&& apt clean
RUN npm install --global solc@0.5

COPY build/cvc4 /usr/local/bin/

COPY build/stainless.zip /tmp/
RUN unzip -d /usr/local/bin /tmp/stainless.zip && rm -f /tmp/stainless.zip
# see https://github.com/epfl-lara/smart/issues/12
RUN chmod o+r /usr/local/bin/lib/scalaz3-unix-64-2.12.jar

COPY --from=builder /conode /usr/local/bin/conode

ENTRYPOINT ["/usr/local/bin/conode"]
54 changes: 54 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: "3"

services:
conode-1:
image: c4dt/service-stainless-backend:latest
build:
context: backend
volumes:
- ./backend/build/conode-1:/config
network_mode: host
command: "-d 2 -c /config/private.toml server"
environment:
- CONODE_SERVICE_PATH=/config
- DEBUG_COLOR=true
conode-2:
image: c4dt/service-stainless-backend:latest
build:
context: backend
network_mode: host
volumes:
- ./backend/build/conode-2:/config
command: "-d 2 -c /config/private.toml server"
environment:
- CONODE_SERVICE_PATH=/config
- DEBUG_COLOR=true
conode-3:
image: c4dt/service-stainless-backend:latest
build:
context: backend
network_mode: host
volumes:
- ./backend/build/conode-3:/config
command: "-d 2 -c /config/private.toml server"
environment:
- CONODE_SERVICE_PATH=/config
- DEBUG_COLOR=true
conode-4:
image: c4dt/service-stainless-backend:latest
build:
context: backend
network_mode: host
volumes:
- ./backend/build/conode-4:/config
command: "-d 2 -c /config/private.toml server"
environment:
- CONODE_SERVICE_PATH=/config
- DEBUG_COLOR=true
demo:
image: c4dt/service-stainless-demo:latest
build:
context: webapp
network_mode: host
volumes:
- ./webapp/src/assets:/webapp/assets
2 changes: 2 additions & 0 deletions webapp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/dist/
/node_modules/
1 change: 1 addition & 0 deletions webapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
16 changes: 16 additions & 0 deletions webapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:16-alpine AS builder

WORKDIR /webapp

COPY package*.json .
RUN npm ci

COPY . .
RUN npx ng build --prod

FROM joseluisq/static-web-server:2 AS runner

COPY --from=builder /webapp/dist /webapp

WORKDIR /webapp
ENV SERVER_ROOT=/webapp
Empty file removed webapp/src/assets/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions webapp/src/assets/configs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*.toml
3 changes: 2 additions & 1 deletion webapp/src/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cothority/
/proto.d.ts
/proto.js
8 changes: 4 additions & 4 deletions webapp/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import toml from "toml";
import { StainlessRPC } from "src/lib/stainless";

const ROSTER_FILE = "conodes.toml";
const STAINLESS_ROSTER_FILE = "conodes_stainless.toml";
const BYZCOIN_CONFIG_FILE = "config.toml";
const BEVM_CONFIG_FILE = "config_bevm.toml";
const STAINLESS_ROSTER_FILE = "stainless.toml";
const BYZCOIN_CONFIG_FILE = "byzcoin.toml";
const BEVM_CONFIG_FILE = "bevm.toml";

export class Config {
static async init(): Promise<Config> {
Expand Down Expand Up @@ -62,7 +62,7 @@ export class Config {
}

private static async getAsset(name: string): Promise<string> {
const resp = await fetch(`assets/${name}`);
const resp = await fetch(`assets/configs/${name}`);
if (!resp.ok) {
return Promise.reject(new Error(`Load ${name}: ${resp.status}`));
}
Expand Down

0 comments on commit e6d6855

Please sign in to comment.