Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ dist-newstyle/
result/app.js
result/index.js
result/dao.js
cabal.log
cabal.log
.env
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Revision history for encoins-frontend

## 0.1.1.6

* Add dockerfile to build ghcjs-8.6.5
* Refactor build scripts
* Add instruction for running all services for frontend within tmux session
* Update README
* Add wrappers for docker command
* Use '.env' for managing env vars.
* Refactor file structure of scripts and docs.

## 0.1.1.5

* Add one more way to make cloud key, the key is making out of connected wallet sign.
Expand Down
120 changes: 120 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
FROM ubuntu:16.04

RUN rm /bin/sh && ln -s /bin/bash /bin/sh

## ensure locale is set during build
ENV LANG=C.UTF-8

## Haskell environment
RUN echo 'deb http://ppa.launchpad.net/hvr/ghc/ubuntu xenial main' > \
/etc/apt/sources.list.d/ghc.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F6F88286 && \
apt-get update && \
apt-get install -y --no-install-recommends \
zlib1g-dev \
libtinfo-dev \
libsqlite3-0 \
libsqlite3-dev \
ca-certificates \
build-essential \
libgmp-dev \
autoconf \
automake \
curl \
g++ \
python3 \
git

# ENV PATH=/root/.cabal/bin:/root/.local/bin:/opt/cabal/bin:/opt/ghc/8.6.5/bin:$PATH

## node.js
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install -y nodejs

# Install micro editor
RUN curl https://getmic.ro | bash
RUN mv micro /usr/local/bin

# Set host $USER as default in docker container
ARG uid
ARG username

RUN echo "uid: $uid"
RUN echo "username: $username"

ENV USER=${username}

ENV UID=${uid}

RUN echo "UID: $UID"
RUN echo "USER: $USER"

RUN adduser --uid $UID $USER
USER $USER

ENV HOME=/home/$USER
WORKDIR $HOME

# Install ghc-8.6.5 and cabal-2.4.1.0. This cabal version wanted for build ghcjs.
RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | \
BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \
BOOTSTRAP_HASKELL_GHC_VERSION=8.6.5 \
sh
ENV PATH=$HOME/.ghcup/bin:$HOME/.cabal:$HOME/.cabal/bin:$PATH

RUN ghcup install cabal 2.4.1.0 && ghcup set cabal 2.4.1.0

## build GHCJS

RUN cabal update

RUN cabal install alex-3.2.6
RUN cabal install happy-1.19.9

RUN git clone https://github.com/ghcjs/ghcjs.git

WORKDIR $HOME/ghcjs

RUN git checkout 04c61d21e13fcbd5de8ca03bea5bc81a862d83d3

RUN git submodule update --init --recursive

RUN ./utils/makePackages.sh

RUN ./utils/makeSandbox.sh

RUN cabal install

ENV PATH=$HOME/ghcjs/.cabal-sandbox/bin:$PATH

RUN ghcjs-boot -v2 -s ./lib/boot/

# Prepare to work with a project

RUN ghcup install cabal 3.2.0.0 && ghcup set cabal 3.2.0.0

WORKDIR $HOME

ARG docker_cabal_cache
ARG docker_frontend
ARG docker_website
ARG docker_webapp
ARG docker_webdao

ENV DOCKER_CABAL_CACHE=${docker_cabal_cache}
ENV DOCKER_FRONTEND=${docker_frontend}
ENV DOCKER_WEBSITE=${docker_website}
ENV DOCKER_WEBAPP=${docker_webapp}
ENV DOCKER_WEBDAO=${docker_webdao}

RUN mkdir $DOCKER_CABAL_CACHE
RUN mkdir $DOCKER_FRONTEND
RUN mkdir $DOCKER_WEBSITE
RUN mkdir $DOCKER_WEBAPP
RUN mkdir $DOCKER_WEBDAO

ENV CABAL_DIR=$DOCKER_CABAL_CACHE

ADD ./script/docker_entrypoint.sh ./docker_entrypoint.sh

ENTRYPOINT ["./docker_entrypoint.sh"]
107 changes: 72 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,99 @@
# ENCOINS Frontend

## Prepare environment

1. `mkdir .env`
2. Add env vars to `.env` with format `ENV_NAME=ENV_VALUE`.
If you add all, remove duplicates

Envvar wanted everywhere:
- HOST_ENCOINS - absolute path to directory where all encoins projects sit, that is parent directory to encoins projects.

Envvars for building `ghcjs`:
- DOCKER_CABAL_CACHE=$HOME/.docker_cabal_cache
- DOCKER_FRONTEND=$HOME/frontend
- GHCJS_IMAGE=ghcjs865
- USER_ID=$(id -u)
- USER_NAME=$(id -u -n)

Envvars for running docker container:
- GHCJS_IMAGE=ghcjs865
- DOCKER_CABAL_CACHE=$HOME/.docker_cabal_cache
- DOCKER_FRONTEND=$HOME/frontend
- HOST_CABAL_CACHE=$HOST_ENCOINS/.docker_cabal_cache
- HOST_FRONTEND=$HOST_ENCOINS/encoins-frontend

Envvars special for `./script/build_and_copy.sh`
- HOST_WEBSITE=$HOST_ENCOINS/Website
- HOST_WEBAPP=$HOST_ENCOINS/Webapp
- HOST_WEBDAO=$HOST_ENCOINS/DAO
- DOCKER_WEBSITE=$HOME/Website
- DOCKER_WEBAPP=$HOME/Webapp
- DOCKER_WEBDAO=$HOME/DAO

Envvars for development within tmux:
- EXTERNAL_DATA - absolute path to external disk, if you keep data of cardano-node and kupo there (optional)
- HOST_FRONTEND=$HOST_ENCOINS/encoins-frontend
- TOOL_APP="$HOST_ENCOINS/encoins-tools/testnet-preprod/apps/encoins"
- TOOL_SCRIPT="$HOST_ENCOINS/encoins-tools/testnet-preprod/scripts"
- FRONT_SESSION="encoins"
- WINDOW_APPS="apps"
- WINDOW_CARDANO="cardano"

## Install GHCJS locally

See instruction [GHCJS.md](GHCJS.md)
See instruction [GHCJS.md](./doc/GHCJS.md) for manual and docker methods.

## Building
## General information

- This project is based on cabal 3.2.0.0, GHC 8.6.5 and GHCJS 8.6 versions.
- HLS version for the setup is 1.8.0.0.
- The project is comprised by two packages `frontend` for constructing javascript part and `frontend-html` for constructing html part.
- For building both of them at once just run `build.sh` that builds them and copy results to `result` folder.

## Development
## Building frontend for production

1. For building just the `frontend-html` part of the project use commands:
- `./script/build.sh` builds `frontend` and `frontend-html` and copy result to `result` folder.
- `./script/build_and_copy.sh` is spacial version of `./script/build.sh` with deploy preparing.
- `./script/build_js.sh` builds `frontend` only.
- `./script/build_html.sh` builds `frontend-html` only (the same for prod and dev)

```shell
cabal run --project-file=frontend-html.project frontend-html
```
They generate html files to `result/` folder.
## Building frontend for development

2. Building `frontend` part of the project for mainnet use commands:
- `./script/build_dev_js.sh` builds `frontend` in preprod mode

```shell
cabal new-build --ghcjs frontend
```
to build all webpages. Copy `all.js` files to the respective files in `result/`.
## Launch frontend

Alternatively, simply run
- Setup [`caddy2`](https://caddyserver.com/v2).

```shell
./build-frontend.sh
- Add `Caddyfile` to root of the frontend project if it doesn't
```
It will compile frontend and copy required files to `result/`.

1. Building frontend for preprod use flags `predao` and `preapp`

```shell
cabal new-build -f preapp -f predao --ghcjs frontend
http://localhost:3333 {
route * {
root * {$CADDY_ROOT}result
file_server *
}
}
```
or simply run

- Run frontend
```shell
./build-frontend-dev.sh
./script/run.sh
```
It will compile frontend in dev mode and copy required files to `result/`.

4. Rebuild frontend in dev mode and run it with caddy at once
## In a browser

```shell
run-dev.sh
```
- `http://localhost:3333/` - landing page
- `http://localhost:3333/app.html` - app page
- `http://localhost:3333/dao.html` - dao page

## Build and run frontend with docker

## Setup for local development
1. Check there is docker image named `ghcjs865` with command `docker images` or build it with docker method (see [CHCJS.md](./doc/GHCJS.md)).

Switch to cabal 3.2.0.0 and GHC 8.6.5 for HLS support (HLS version for the setup is 1.8.0.0).
2. `script/docker_run.sh` for prod (and `./scrript/docker_dev_run.sh` for dev) run `ghcjs865` container, bind cabal cache and frontend sources (prod version `docker_run.sh` binds Website, Webapp and Webdao as well)

Download [`caddy2`](https://caddyserver.com/v2).
3. Just for info. Entrypoint of ghcjs865 container is `./script/docker_entrypoint.sh` script which fine tunes infrastructure.

Run the server locally `caddy run`.
4. Inside docker run `./script/build_dev_js.sh` for dev or `./script/build_js.sh` for prod.

Open http://localhost:3333/ or http://localhost:3333/app.html or http://localhost:3333/dao.html in the browser to see the results!
5. Thanks to docker's volumes the things built in docker appear on the host, that is in result folder.
5 changes: 0 additions & 5 deletions build_html.sh

This file was deleted.

22 changes: 22 additions & 0 deletions doc/DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Tmux session for development

## Dev up

1. Tmux session uses `docker` to build the project.
If `ghcjs` installed locally you want to remove following line from `./dev_up.sh`:
`tmux send-keys -t $FRONT_SESSION:$WINDOW_APPS.4 "./script/docker_dev_run.sh" C-m ;`

2. Update paths variables in `.env` file, see README.md

2. Run `./script/dev_up.sh` script. After launching:
- wait for sync finishing of `node` and `kupo`
- run `wallet.sh` in `cardano` window
- run `encoins --run` in `apps` window to launch relay server
- run `./script/run.sh` in `apps` window to launch frontend
- run `./script/build_dev_js.sh` in apps window to rebuild frontend

## Dev down

Just killing session won't stop `node` and `kupo`.
To gracefully shutting down dev session you want to use following script `./script/dev_down.sh`

22 changes: 18 additions & 4 deletions GHCJS.md → doc/GHCJS.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
# GHCJS

## Docker method to build GHCJS-8.6 version.

1. Add envvars to `.env` file. See README.md

2. Run ghcjs builder from the root directory of frontend project (where dockerfile is):

```shell
./docker_build.sh
```

3. Important. `docker` command should run [without](https://docs.docker.com/engine/install/linux-postinstall/) root access.

## Manual method to build GHCJS-8.6 version.

(Update: it is not always reproducible)

System setup where installing ghcjs was succeeded. In another system setup the steps could be different.

OS: Manjaro 23.0.0 Uranos
Kernel: x86_64 Linux 6.4.6-1-MANJARO
DE: KDE 5.108.0 / Plasma 5.27.7

## GHC-8.6 version for encoins project

1. I use `ghcup` for tool management. Thus there should not exist (or be visible in a PATH) any alternative of cabal setup (for example in `/home/$USERNAME/.cabal` ) except ones that installed by `ghcup`.
0. I use `ghcup` for tool management. Thus there should not exist (or be visible in a PATH) any alternative of cabal setup (for example in `/home/$USERNAME/.cabal` ) except ones that installed by `ghcup`.
Also,no extra `ghc-pkg` setups, for example in `/usr/bin` PATH. Highly likely installed globally `happy` should have version `1.19.11`. Likely, in your case there are another toolings installed with different version that slips into GHCJS compiling.

1. GHCUP: GHC set to 8.6.5, Cabal set to 3.2.0.0
1. GHCUP: GHC set to 8.6.5, Cabal set to 3.2.0.0 (for ghcjs building it can be 2.4.1.0, for project building it can be switched to 3.2.0.0)
2. git clone --branch ghc-8.6 https://github.com/ghcjs/ghcjs.git
3. cd ghcjs
4. git submodule update --init --recursive
Expand Down
2 changes: 1 addition & 1 deletion frontend/encoins-frontend.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: encoins-frontend
version: 0.1.1.5
version: 0.1.1.6
build-type: Simple
author:
Vladimir Sinyakov
Expand Down
3 changes: 0 additions & 3 deletions generate-html.sh

This file was deleted.

18 changes: 0 additions & 18 deletions run_dev.sh

This file was deleted.

2 changes: 1 addition & 1 deletion build.sh → script/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

source utils.sh
source ./script/utils.sh

version=$(get_version)
printf "Current frontend version: %s" "$version"
Expand Down
Loading