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

Docker support + Minor README improvement #14

Merged
merged 7 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions opl-secret-ballot/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
node_modules/
*.log
.cache
.bashrc
CedarMist marked this conversation as resolved.
Show resolved Hide resolved
.local
.bash_history
.npm
.bashrc
63 changes: 63 additions & 0 deletions opl-secret-ballot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))

# Runs a local ephemeral docker instance, with current dir bind-mounted to /src
DOCKER=docker run --rm -it --hostname=opl -u `id -u`:`id -g` -e HISTFILESIZE=0 -e HOME=/src --network=host -w /src -v $(ROOT_DIR):/src node:lts
CedarMist marked this conversation as resolved.
Show resolved Hide resolved

DOCKER_PNPM=.local/share/pnpm/pnpm
PNPM=pnpm

all:
@echo If you\'re not using Docker, run:
@echo
@echo " $$ make build"
@echo
@echo Or, to run open a shell development inside a Docker container:
@echo
@echo " $$ make docker-shell"
@echo
@echo And then build the project as if you were not using Docker:
@echo
@echo " node@opl:~$$ make build"
@echo

CedarMist marked this conversation as resolved.
Show resolved Hide resolved
node_modules backend/node_modules frontend/node_modules:
$(PNPM) install

$(DOCKER_PNPM):
$(DOCKER) bash -c 'curl -fsSL https://get.pnpm.io/install.sh | SHELL=bash sh -'

.PHONY: build
build: build-backend build-frontend

.PHONY: build-backend
build-backend: backend/node_modules
$(PNPM) run -C backend build:compile
$(PNPM) run -C backend build:cjs
$(PNPM) run -C backend build:esm

.PHONY: build-frontend
build-frontend: frontend/node_modules
$(PNPM) run -C frontend build

.PHONY: frontend-dev
frontend-dev:
$(PNPM) run -C frontend dev

.PHONY: backend-deploy
backend-deploy:
cd backend && $(PNPM) hardhat deploy-local --network localhost

.PHONY: backend-node
backend-node:
cd backend && $(PNPM) hardhat node

.PHONY: docker-shell
docker-shell: $(DOCKER_PNPM)
$(DOCKER) bash

.PHONY: clean
CedarMist marked this conversation as resolved.
Show resolved Hide resolved
clean:
rm -rf .bash_history .npm package-lock.json package.json .local .cache .bashrc .config
rm -rf node_modules functions/node_modules frontend/node_modules backend/node_modules
rm -rf backend/typechain-types backend/cache backend/artifacts backend/lib
rm -rf frontend/dist
CedarMist marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 26 additions & 5 deletions opl-secret-ballot/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## Secret Ballot Lite
This is a demo or light weight version of [opl-secret-ballot](https://github.com/oasislabs/opl-secret-ballot).

There are two key smart contracts that we will deploy, one interacting with a host chain such as Binance and one interacting with OPL or an enclave on Sapphire.
There are two key smart contracts that we will deploy, one interacting with a host chain
such as Binance and one interacting with OPL or an enclave on Sapphire.

### Backend

Expand Down Expand Up @@ -37,7 +38,8 @@ pnpm run build

### Local Development

We will use [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview) and [Hardhat-deploy](https://github.com/wighawag/hardhat-deploy) to simplify development.
We will use [Hardhat](https://hardhat.org/hardhat-runner/docs/getting-started#overview)
and [Hardhat-deploy](https://github.com/wighawag/hardhat-deploy) to simplify development.

Start local Hardhat network
```sh
Expand All @@ -60,8 +62,8 @@ and
VITE_DAO_V1_ADDR=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
```

Additionally, we will need a [Pinata](https://www.pinata.cloud) API [key](https://docs.pinata.cloud/pinata-api/authentication) to access the pinning
service with which we store our ballots as JSON.
Additionally, we will need a [Pinata](https://www.pinata.cloud) API [key](https://docs.pinata.cloud/pinata-api/authentication)
to access the pinning service with which we store our ballots as JSON.

```yaml
VITE_PINATA_JWT=
Expand All @@ -74,4 +76,23 @@ npm run dev

Navigate to http://localhost:5173, and you should be able to create a new poll.

You can use one of the deployed test accounts and associated private key with MetaMask.
You can use one of the pre-funded test accounts and associated private key with MetaMask,
use 'Add a network manually' with these parameters to connect to your local Hardhat node:

* Network name: `Hardhat`
* New RPC URL: `http://127.0.0.1:8545/`
* Chain ID: `1337` (or leave blank to auto-detect)
* Currency symbol: `TEST` (or leave blank)

### Docker + Makefile

If you prefer to run everything safely inside inside a Docker container,
a Makefile is provided for your convenience:

```
make docker-shell # Bash shell inside container
node@opl:~$ make build
node@opl:~$ make backend-node & # Run local Hardhat node
node@opl:~$ make backend-deploy # Deploy contracts to local node
node@opl:~$ make frontend-dev & # Run VITE development server
```