Skip to content

Commit

Permalink
Add docker build.
Browse files Browse the repository at this point in the history
  • Loading branch information
abizjak committed Dec 20, 2023
1 parent 511656f commit 91fcbe5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 21 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ The following examples are available.

- [simple age verification](./simpleAgeVerification/) demonstrates in a simple use case of verifiying the users age with the browser wallet.

- [euroe-demo](./euroe-demo/) demonstrates an example frontend and wallet
interactions of a store that sells restricted items, and supports payment in
EUROe tokens (or generally any CIS2 token).

## Setup

Some projects uses submodules, to initialize or update those, run:
Expand Down
3 changes: 3 additions & 0 deletions euroe-demo/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/*
.yarn/*
!.yarn/releases/*.cjs
49 changes: 28 additions & 21 deletions euroe-demo/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
# React + TypeScript + Vite
# EUROe usage demo

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
This dapp exemplifies how to do age verification together with payment using
EUROe, or any other CIS2, token.

Currently, two official plugins are available:
Note that only the **frontend** is here. This frontend does not verify age
proofs, it just accepts them. In a real production scenario the proofs would of
course be verified, linked to an account, and a session token generated to allow
usage of the store for that session.

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
To develop use

## Expanding the ESLint configuration
```
yarn dev
```

which will start a development server and print the address on which it is
listening. Use `yarn fmt` and `yarn lint` before committing to ensure consistent
formatting and adherence to common style.

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
To build for production run
```
yarn build
```

- Configure the top-level `parserOptions` property like this:
which will produce the artifacts in the `dist` folder.

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
};

## Docker image

To build a docker image run

```
docker build -f scripts/Dockerfile .
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
from this directory (i.e., directory the README file is located in).
12 changes: 12 additions & 0 deletions euroe-demo/scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG build_image="node:20-slim"
FROM ${build_image} AS build
WORKDIR /app
COPY package.json yarn.lock .yarnrc.yml ./
COPY .yarn/releases/*.cjs ./.yarn/releases/
RUN corepack yarn install
COPY . .
RUN corepack yarn build

FROM nginx
COPY --from=build ./app/dist ./usr/share/nginx/html
COPY ./scripts/nginx.conf /etc/nginx/conf.d/default.conf
42 changes: 42 additions & 0 deletions euroe-demo/scripts/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Enable Gzip
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
application/xml
application/wasm
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml
image/jpeg;

gzip_static on;

gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;

server {
listen 80 default;
server_name _;
root /usr/share/nginx/html;

# Set expires max on static file types
location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm|wasm)$ {
expires max;
root /usr/share/nginx/html;
access_log off;
}
}

0 comments on commit 91fcbe5

Please sign in to comment.