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

Added both react frontend and a Dockerized build/dev environment #2

Merged
merged 11 commits into from
Feb 28, 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
4 changes: 0 additions & 4 deletions .env-template

This file was deleted.

5 changes: 5 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
JURY_NAME=
JURY_ADMIN_PASSWORD=

MONGODB_USER=
MONGODB_PASS=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.env
.env
/data
6 changes: 4 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"jsxSingleQuote": false,
"tabWidth": 4
}
"singleQuote": true,
"tabWidth": 4,
"printWidth": 100
}
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ serde = {version = "1", features = ["derive"] } # Used in the Map Data into Stru
dotenv = "0.15.0"
rand = "0.8.5"
async-trait = "0.1.59"
futures = "0.3"

[dependencies.rocket]
version = "0.5.0-rc.2"
features = ["json"]

[dependencies.rocket_dyn_templates]
version = "0.1.0-rc.2"
features = ["handlebars"]
features = ["handlebars"]

[[bin]]
name = "jury"
path = "src/main.rs"
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# STEP 0: Statically build node client
FROM node as client-builder
WORKDIR /client
COPY client/public public
COPY client/src src
COPY ["client/package.json", "client/yarn.lock", "client/tailwind.config.js", "client/tsconfig.json", "./"]

ARG NODE_ENV=production
ARG REACT_APP_JURY_NAME
ARG REACT_APP_JURY_URL

RUN yarn install --frozen-lockfile
RUN yarn build

# STEP 1: Compile backend
FROM rust as builder
WORKDIR /usr/src/jury

RUN apt update
RUN apt install libgsl-dev -y

# Jank way to cache built rust dependencies
RUN mkdir src
RUN echo "fn main() {}" > ./src/main.rs
COPY ["Cargo.toml", "Cargo.lock", "./"]
RUN cargo build --locked --release

# Then actually copy over the app and build it
COPY src src
COPY --from=client-builder /client/build public
COPY Rocket.toml .

ARG MONGODB_URI=$MONGODB_URI
ARG JURY_ADMIN_PASSWORD=$JURY_ADMIN_PASSWORD
ARG FILESERVER="/public"

RUN cargo install --locked --path .

# STEP 2: Main running container
FROM debian:bullseye-slim

ENV FILESERVER="/public"
ENV ROCKET_ADDRESS=0.0.0.0

EXPOSE $PORT

RUN apt-get update && apt-get install -y libgsl-dev && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/jury /usr/local/bin/jury
COPY --from=client-builder /client/build /public
CMD ["jury"]
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
# Jury

[WIP] A project designed to re-write Gavel using modern technologies aimed at optimizing the user experience of judges and admin users. This is NOT a rewrite of the underlying formulas from the [original Gavel by anishathalye](https://github.com/anishathalye/gavel). Refer to [this excellent article](https://www.anishathalye.com/2015/03/07/designing-a-better-judging-system/) for more details on the underlying math workings of Gavel!
A project designed to create a new pairwise judging system using modern technologies aimed at optimizing the user experience of judges and admin users. See the inspiration for this project: [Gavel by anishathalye](https://github.com/anishathalye/gavel). Refer to [this excellent article](https://www.anishathalye.com/2015/03/07/designing-a-better-judging-system/) for more details on the underlying formulas of Gavel! The majority of our algorithm will be based off of research done in the field of [pairwise comparison](https://en.wikipedia.org/wiki/Pairwise_comparison).

# External System Requirements
# Deployment

> Note: This might be mitigated with the use of a dockerized development environment (WIP)
## With Docker

Run `docker compose up`

# Developing

## With Docker (Recommended!)

Requirements:

* [Docker](https://www.docker.com/)

Copy `.env.template` into `.env` and fill in the environmental variables

Simply run `docker compose -f docker-compose.dev.yml up` and open the page at `localhost:3000`

## Manual Installation

Requirements:

* [yarn](https://yarnpkg.com/)
* [cargo](https://doc.rust-lang.org/cargo/)
* [GNU Scientific Library (GSL)](https://www.gnu.org/software/gsl/)

Copy `.env.template` into `.env` and fill in the environmental variables. You will also need a `MONGODB_URI` field.
Additionally, copy `client/.env.template` into `client/.env` and copy over the relavent environmental variables from `.env`.
This is used to expose the correct environmental variables to the running instance of CRA.

Client dev server (PORT 3000):

```
cd client
yarn install
yarn start
```

Backend dev server (PORT 8000):

```
cargo run
```
3 changes: 3 additions & 0 deletions Rocket.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default]
address = "0.0.0.0"

2 changes: 2 additions & 0 deletions client/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_JURY_URL=
REACT_APP_JURY_NAME=
23 changes: 23 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
46 changes: 46 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
9 changes: 9 additions & 0 deletions client/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node as client-builder
WORKDIR /client

ENV REACT_APP_JURY_NAME=$REACT_APP_JURY_NAME
ENV REACT_APP_JURY_URL=$REACT_APP_JURY_URL

RUN yarn install --frozen-lockfile

CMD [ "yarn", "run", "start" ]
47 changes: 47 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/node": "^16.7.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"localforage": "^1.10.0",
"match-sorter": "^6.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.1",
"react-scripts": "5.0.1",
"tailwind-merge": "^1.9.1",
"typescript": "^4.4.2",
"universal-cookie": "^4.0.4"
},
"devDependencies": {
"esbuild": "^0.17.8",
"tailwindcss": "^3.2.6"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
File renamed without changes.
30 changes: 30 additions & 0 deletions client/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Jury</title>
<meta name="description" content="A modernized pairwise judging system" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous" />
<link
href="https://fonts.googleapis.com/css2?family=Roboto+Mono&family=Rubik:wght@400;700&display=swap"
rel="stylesheet"
/>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
--></body>
</html>
21 changes: 21 additions & 0 deletions client/src/Home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Button from './components/Button';
import Container from './components/Container';

const App = () => {
return (
<Container>
<h1 className="text-7xl font-bold text-center mb-4">Jury</h1>
<h2 className="text-primary text-3xl text-center font-bold mb-24">
{process.env.REACT_APP_JURY_NAME}
</h2>
<Button href="/judge/login" type="primary">
Judging Portal
</Button>
<Button href="/admin/login" type="text">
Admin Portal
</Button>
</Container>
);
};

export default App;
Loading