From 90194cd778ed36daefad946f92e789ca2cfec685 Mon Sep 17 00:00:00 2001 From: Kun Li Date: Tue, 20 Feb 2024 16:37:10 +0100 Subject: [PATCH 1/2] deploy dockerized UI --- docker-compose.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8f79b95..64d8ef3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,10 @@ -version: '3' +version: "3" services: + webapp: + image: kunlium/luceweb + ports: + - 8000:80 + restart: unless-stopped ganache_db: image: trufflesuite/ganache:v7.7.3 @@ -14,7 +19,6 @@ services: volumes: - ${STORAGE_PATH:-./data}/ganache_db:/ganache_db - postgres_db: image: postgres restart: unless-stopped @@ -81,11 +85,10 @@ services: # - GRANT_SUDO=yes # - JUPYTER_ENABLE_LAB=yes - # ethereum-node: # image: ethereum/client-go # ports: # - "30303:30303" # command: "--rpc --rpcaddr 0.0.0.0" # volumes: - # - ./data/ethereum:/root/.ethereum \ No newline at end of file + # - ./data/ethereum:/root/.ethereum From c0e6d8a2e20a524f4f479832cab1387439579888 Mon Sep 17 00:00:00 2001 From: Kun Li Date: Wed, 21 Feb 2024 15:39:02 +0100 Subject: [PATCH 2/2] Fix brownie compile in docker, make the whole stack deployment work with docker --- .dockerignore | 21 ++++ Dockerfile | 23 ++-- README.md | 14 +++ docker-compose.dev.yml | 65 +++++++++++ docker-compose.yml | 68 ++++++------ luce_vm/Vagrantfile | 101 ------------------ .../luce/lucehome/settings_psql.py | 8 +- requirements.txt | 10 ++ 8 files changed, 157 insertions(+), 153 deletions(-) create mode 100644 .dockerignore create mode 100644 docker-compose.dev.yml delete mode 100644 luce_vm/Vagrantfile create mode 100644 requirements.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bfe9061 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +# Ignore MacOS files +.DS_Store + +# Ignore logs +*.log +nohup.out +.vsco +de/ +.idea +data/ + +# JS +node_modules/ +db.sqlite3 + +# Python +__pycache__/ +.pytest_cache/ +.ipynb_checkpoints/ + +luce_vm/brownie/build diff --git a/Dockerfile b/Dockerfile index 36b8a8b..7f7cce2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9 +FROM --platform=linux/amd64 python:3.9 USER root WORKDIR /luce @@ -8,16 +8,10 @@ ENV USE_TZ=False RUN apt-get update && \ apt-get install -y wget build-essential software-properties-common libssl-dev postgresql-client libpq-dev -RUN pip install eth-brownie -RUN pip install Django==4.1.12 -RUN pip install django-filter -RUN pip install django-extensions -RUN pip install djangorestframework -RUN pip install django-cors-headers -RUN pip install psycopg2 -RUN pip install matplotlib -RUN pip install django-haystack -RUN pip install Sphinx + +ADD ./requirements.txt . +RUN pip install -r requirements.txt + # Install Ethereum # RUN add-apt-repository -y ppa:ethereum/ethereum && \ # apt update && \ @@ -31,16 +25,15 @@ RUN pip install Sphinx RUN brownie pm install OpenZeppelin/openzeppelin-contracts@4.8.0 -COPY luce_vm/scripts/entrypoint.sh /entrypoint.sh +ADD ./luce_vm/scripts/entrypoint.sh /entrypoint.sh RUN chmod 744 /entrypoint.sh # brownie networks add [environment] [id] host=[host] [KEY=VALUE, ...] RUN brownie networks add LUCE luce host=http://ganache_db:8545 chainid=72 - - COPY . . -# RUN cd luce_vm/brownie && brownie compile + +RUN cd luce_vm/brownie && brownie compile # RUN pip install -e . diff --git a/README.md b/README.md index d93ca5b..7f4ae6e 100644 --- a/README.md +++ b/README.md @@ -112,3 +112,17 @@ please deploy a LUCERegistry contract in `admin/deployRegistry/` endpoint. For how to maintain the documentation, please refer to: [Documentation mantaince](./docs/README.MD) For how to develop in LUCE, please refer to: [LUCE development tips](./manual/LUCE%20Development%20tips.MD) + +1. Start the database and blockchain in docker for development: + +```bash +docker compose -f docker-compose.dev.yml up +``` + +2. Start the backend: + +```bash + +``` + +3. Start the frontend: diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..d58f122 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,65 @@ +version: "3" + +# Docker compose to use top deploy database in development +# Backend and webapp are expected to be run separately + +services: + image: kunlium/luceweb + ports: + - 8001:80 + restart: unless-stopped + + ganache_db: + image: trufflesuite/ganache:v7.7.3 + restart: unless-stopped + command: -l 300000000 --database.dbPath /ganache_db --chain.chainId 72 -h 0.0.0.0 --wallet.accounts "0xd49df1af2d195c2c56cb4aa9119d188889c8c28c011501a339a1eafcdcb790d8, 1000000000000000000000000" --wallet.accounts "0x56c6de6fd54438dbb31530f5fdeeaada0b1517880c91dfcd46a4e5fec59a9c79, 1000000000000000000000000" "0xcd4fc6fe57bb44764562df4abae6e9673a4b9db250ea94a0a42ac8500e0275eb, 1000000000000000000000000" + ports: + - 8545:8545 + # environment: + # - VIRTUAL_PORT=8545 + # - VIRTUAL_HOST=ganache.luce.137.120.31.102.nip.io + # - LETSENCRYPT_HOST=ganache.luce.137.120.31.102.nip.io + volumes: + - ${STORAGE_PATH:-./data}/ganache_db:/ganache_db + + postgres_db: + image: postgres + restart: unless-stopped + depends_on: + - ganache_db + ports: + - 5432:5432 + environment: + - POSTGRES_PASSWORD=luce123456 + - POSTGRES_USER=luce + - POSTGRES_DB=lucedb + volumes: + - ${STORAGE_PATH:-./data}/postgres_db:/var/lib/postgresql/data + - ./luce_vm/scripts/init_postgres.sh:/docker-entrypoint-initdb.d/init_postgres.sh + + zkp_service: + build: ./luce_vm/js + ports: + - 8888:8888 + + # jupyterlab: + # # image: jupyter/base-notebook + # build: ./luce_vm/jupyter + # restart: unless-stopped + # user: root + # ports: + # - 8888:8888 + # volumes: + # - ./luce_vm/jupyter:/home/jovyan/work + # environment: + # - JUPYTER_TOKEN=password + # - GRANT_SUDO=yes + # - JUPYTER_ENABLE_LAB=yes + + # ethereum-node: + # image: ethereum/client-go + # ports: + # - "30303:30303" + # command: "--rpc --rpcaddr 0.0.0.0" + # volumes: + # - ./data/ethereum:/root/.ethereum diff --git a/docker-compose.yml b/docker-compose.yml index 64d8ef3..fcb70bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,9 +3,43 @@ services: webapp: image: kunlium/luceweb ports: - - 8000:80 + - 8001:80 restart: unless-stopped + luce_server: + build: + context: . + # NOTE: required when building on Mac M1/M2 + # platform: linux/amd64 + # entrypoint: sleep infinity + depends_on: + - postgres_db + - ganache_db + ports: + - 8000:8000 + restart: unless-stopped + # volumes: + # - ./:/luce + environment: + - JUPYTER_TOKEN=luce + # Nginx reverse proxy + - VIRTUAL_PORT=8000 + - VIRTUAL_HOST=luce.137.120.31.102.nip.io + - LETSENCRYPT_HOST=luce.137.120.31.102.nip.io + # PostgreSQL config + - DJANGO_USE_PSQL=true + - POSTGRES_PASSWORD=luce123456 + - POSTGRES_USER=luce + - POSTGRES_DB=lucedb + # Ganache config + - GANACHE_PORT=8545 + # Ideally the users/password should be defined here + # And automatically added to the database at start + - PROVIDER_USER=provider@luce.com + - PROVIDER_PASSWORD=provider + - REQUESTER_USER=requester@luce.com + - REQUESTER_PASSWORD=requester + ganache_db: image: trufflesuite/ganache:v7.7.3 restart: unless-stopped @@ -39,38 +73,6 @@ services: ports: - 8888:8888 - luce_server: - build: . - # image: vjaiman/luce - depends_on: - - postgres_db - - ganache_db - # ports: - # - 8000:8000 - restart: unless-stopped - # entrypoint: tail -f /dev/null - volumes: - - ./:/luce - environment: - - JUPYTER_TOKEN=luce - # Nginx reverse proxy - - VIRTUAL_PORT=8000 - - VIRTUAL_HOST=luce.137.120.31.102.nip.io - - LETSENCRYPT_HOST=luce.137.120.31.102.nip.io - # PostgreSQL config - - DJANGO_USE_PSQL=true - - POSTGRES_PASSWORD=luce123456 - - POSTGRES_USER=luce - - POSTGRES_DB=lucedb - # Ganache config - - GANACHE_PORT=8545 - # Ideally the users/password should be defined here - # And automatically added to the database at start - - PROVIDER_USER=provider@luce.com - - PROVIDER_PASSWORD=provider - - REQUESTER_USER=requester@luce.com - - REQUESTER_PASSWORD=requester - # jupyterlab: # # image: jupyter/base-notebook # build: ./luce_vm/jupyter diff --git a/luce_vm/Vagrantfile b/luce_vm/Vagrantfile deleted file mode 100644 index 93db8d3..0000000 --- a/luce_vm/Vagrantfile +++ /dev/null @@ -1,101 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - - -# LuceVM Setup -Vagrant.configure("2") do |config| - - - config.vm.define "lucevm", primary: true do |lucevm| - - # Use pre-provisioned custom box - lucevm.vm.box = "arnoan/lucevm" - lucevm.vm.box_check_update = true - config.vm.provision :docker - - - # ==== PORT CONFIGURATION ==== - - # Apache Web Server - lucevm.vm.network :forwarded_port, guest: 80, host: 4567 - - # Jupyter Notebook - lucevm.vm.network :forwarded_port, guest: 8888, host: 8888 - - # Jupyter Notebook Alternative Port - lucevm.vm.network :forwarded_port, guest: 8889, host: 8889 - - # Ganache Blockchain - #lucevm.vm.network :forwarded_port, guest: 8545, host: 8545 - - # Django - Open a few ports for testing multiple servers - lucevm.vm.network :forwarded_port, guest: 8000, host: 8000 - lucevm.vm.network :forwarded_port, guest: 8001, host: 8001 - lucevm.vm.network :forwarded_port, guest: 8002, host: 8002 - - # ==== VirtualBox CONFIGURATION ==== - - lucevm.vm.provider "virtualbox" do |vb| - - # Amount of memory used by VM (1GB) - vb.memory = "1024" - #vb.memory = "2048" - vb.cpus = 1 - - # Display VirtualBox GUI when booting the machine - #vb.gui = true - - # Disable creation of log file - vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] - - # Hard-code virtual ethernet cable connection - # This prevents SSH auth method: private key from getting stuck - vb.customize ["modifyvm", :id, "--cableconnected1", "on"] - end - - # ==== ADDITIONAL CONFIGURATION ==== - - # Set up shared network interface - lucevm.vm.network "private_network", ip: "192.168.72.2" - - # Disable checking for new vbguest updates - if Vagrant.has_plugin?("vagrant-vbguest") - lucevm.vbguest.auto_update = false - end - - # ==== SCRIPTS TO RUN AFTER STARTUP ==== - - lucevm.vm.provision :shell, path: "./scripts/bootstrap_custom_lucevm.sh" - - end - -end - - -# PostgreSQL/LuceDB Setup -Vagrant.configure("2") do |config| - - config.vm.define "lucedb", autostart: false do |lucedb| - - # Use pre-provisioned custom box - lucedb.vm.box = "arnoan/lucedb" - lucedb.vm.box_check_update = true - - # Disable checking for new vbguest updates - if Vagrant.has_plugin?("vagrant-vbguest") - lucedb.vbguest.auto_update = false - end - - # Migrated these configurations from old v1 format - lucedb.vm.hostname = "postgresql" - lucedb.vm.synced_folder ".", "/mnt/bootstrap" - - # Set up shared network interface - lucedb.vm.network "private_network", ip: "192.168.72.3" - lucedb.vm.network :forwarded_port, guest: 5432, host: 15432 - - lucedb.vm.provision :shell, path: "./scripts/bootstrap_custom_lucedb.sh" - - end - -end \ No newline at end of file diff --git a/luce_vm/luce_django/luce/lucehome/settings_psql.py b/luce_vm/luce_django/luce/lucehome/settings_psql.py index bd1fe0d..33668e4 100644 --- a/luce_vm/luce_django/luce/lucehome/settings_psql.py +++ b/luce_vm/luce_django/luce/lucehome/settings_psql.py @@ -3,15 +3,15 @@ # This will override the DATABASES variable in settings.py # Use Postgresql Database: -#connect to database: psql -U vagrant --port 5432 -d lucedb +# connect to database: psql -U vagrant --port 5432 -d lucedb import os if os.environ.get('SIMULATION') == 'true': DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'lucedb', - 'USER': 'vagrant', - 'PASSWORD': 'luce', + 'USER': 'luce', + 'PASSWORD': 'luce123456', 'HOST': '127.0.0.1', 'PORT': '5432', } @@ -26,4 +26,4 @@ 'HOST': 'postgres_db', 'PORT': '5432', } - } \ No newline at end of file + } diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a7c40cb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +eth-brownie +Django ==4.1.12 +django-filter +django-extensions +djangorestframework +django-cors-headers +psycopg2 +matplotlib +django-haystack +Sphinx