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

Add docker to all components. #1

Merged
merged 4 commits into from
Jan 22, 2025
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,16 @@ This will start the server on port 3001, the client devserver is set up to proxy

The server may take about 15 seconds (or more depending on your machine) to start up because it loads the wasm engine and modules before starting the http server.

Check that the server is running correctly by visiting http://localhost:3001/ in the browser. If that loads, then the UI should also be able to run bots and tournaments via the API.
Check that the server is running correctly by visiting http://localhost:3001/ in the browser. If that loads, then the UI should also be able to run bots and tournaments via the API.

### Use dockerized version to run locally

Run:
```sh
docker compose -f docker-compose.yaml up
```

If there were changes after the initial build, you can rebuild the image with:
```sh
docker compose -f docker-compose.yaml up --build
```
1 change: 1 addition & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
30 changes: 30 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Build stage
FROM node:latest AS builder

WORKDIR /app
COPY ./ .

RUN corepack enable
RUN yarn install
RUN yarn build

# Nginx stage
FROM nginx:latest

# Set the working directory for Nginx
WORKDIR /app

# Copy the build output from the builder stage to Nginx's default directory
COPY --from=builder /app/dist /usr/share/nginx/html

RUN mkdir /usr/share/nginx/html/snippy
RUN mv /usr/share/nginx/html/assets /usr/share/nginx/html/snippy/assets

# Optionally copy a custom Nginx config (if you have one)
COPY ./nginx.conf /etc/nginx/nginx.conf

# Expose port 80 to access the app
EXPOSE 80

# Nginx will automatically serve the content
CMD ["nginx", "-g", "daemon off;"]
77 changes: 11 additions & 66 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,15 @@
# Getting Started with Create React App
# Client application

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

## Available Scripts
```sh
yarn start
yarn build
yarn lint
yarn lint-fix
yarn deploy
```

In the project directory, you can run:
## Running locally

### `npm start`

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

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm 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.

### `npm run 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.

### `npm run 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/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Either run `yarn start` or use the container instructions on the main README.
58 changes: 58 additions & 0 deletions client/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# The "events" section is required by Nginx
events {
worker_connections 1024; # Maximum number of simultaneous connections
}

http {
# Basic HTTP setup
include /etc/nginx/mime.types;
default_type application/octet-stream;

upstream backend {
server wasi-runner:3001;
}

server {
listen 80;

# Serve static files from /usr/share/nginx/html
root /usr/share/nginx/html;

# Default index file
index index.html;

# Redirect any request to / to index.html (for SPA routing)
location / {
try_files $uri $uri/ /index.html;
}

# Proxy requests to /api to wasi-runner:3000
location /api/ {
proxy_pass http://backend;

# WebSocket headers
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

# Preserve host and real IP headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# Optional timeout settings for WebSockets
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}

# Optional: Add headers to cache static assets for better performance
location ~* \.(?:css|js|html|svg|woff2?|ttf|eot)$ {
try_files $uri =404;
add_header Cache-Control "public, max-age=31536000, immutable";
}

# Optional: Handle 404 errors gracefully
error_page 404 /index.html;
}
}
12 changes: 9 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@g-loot/react-tournament-brackets": "^1.0.30",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be deprecated.

"@mui/icons-material": "^5.14.18",
"@mui/material": "^5.14.18",
"@types/jest": "^29.5.8",
Expand All @@ -17,7 +16,9 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.19.0",
"styled-components": "^6.1.1",
"react-svg-pan-zoom": "^3.13.1",
"react-tournament-brackets": "^1.0.40",
"styled-components": "^6.1.14",
"typescript": "^5.2.2",
"web-vitals": "^2.1.4"
},
Expand All @@ -42,5 +43,10 @@
"prettier": "^3.1.0",
"vite": "^5.0.0"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"overrides": {
"react-tournament-brackets": {
"styled-components": "$styled-components"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I had to bump styled-components for some reason or the npm version I'm using is detecting that it conflicts with the version styled-components required from react-tournament-brackets. This seems to work anyway.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems to be a version mismatch in the devdependencies not the dependencies that matter. I might look into resolving this but it's fine. :)

}
}
}
2 changes: 1 addition & 1 deletion client/src/Tournament.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CircularProgress from '@mui/material/CircularProgress'
import { SingleEliminationBracket } from '@g-loot/react-tournament-brackets'
import { SingleEliminationBracket } from 'react-tournament-brackets'

import './Tournament.css'

Expand Down
Loading