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

Draft: Creating branch to update node such that vite will work. #62

Merged
merged 8 commits into from
Feb 17, 2024
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
22 changes: 22 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BACKEND_IMAGE_NAME=socialpredict-backend-dev
BACKEND_CONTAINER_NAME=socialpredict-backend-container-dev
BACKEND_PORT=8080 # Internal
BACKEND_HOSTPORT=8086 # External

POSTGRES_CONTAINER_NAME=db-postgres-dev
DB_HOST=db
DB_PORT=5433 # port accessible on host machine
POSTGRES_PORT=5432 # port where postgres serves by default in container"$DB_PORT:$POSTGRES_PORT"
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DATABASE=devdb

FRONTEND_IMAGE_NAME=socialpredict-frontend-dev
FRONTEND_CONTAINER_NAME=socialpredict-frontend-dev
REACT_PORT=5173 # Internal
REACT_HOSTPORT=5173 # External

NGINX_IMAGE_NAME=socialpredict-nginx-dev
NGINX_CONTAINER_NAME=socialpredict-nginx-dev
NGINX_PORT=80 # Internal
NGINX_HOSTPORT=8089 # External
4 changes: 2 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ POSTGRES_DATABASE=devdb

FRONTEND_IMAGE_NAME=socialpredict-frontend-dev
FRONTEND_CONTAINER_NAME=socialpredict-frontend-dev
REACT_PORT=3000 # Internal
REACT_HOSTPORT=3000 # External
REACT_PORT=5173 # Internal
REACT_HOSTPORT=5173 # External

NGINX_IMAGE_NAME=socialpredict-nginx-dev
NGINX_CONTAINER_NAME=socialpredict-nginx-dev
Expand Down
7 changes: 4 additions & 3 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"socialpredict/middleware"
"socialpredict/migration"
"socialpredict/seed"
"socialpredict/server"
"socialpredict/util"
)
Expand All @@ -30,9 +31,9 @@ func main() {
migration.MigrateDB(db)

// Seed the admin user
// seed.SeedUsers(db)
// seed.SeedMarket(db)
// seed.SeedBets(db)
seed.SeedUsers(db)
seed.SeedMarket(db)
seed.SeedBets(db)

server.Start()
}
Expand Down
2 changes: 1 addition & 1 deletion backend/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func Start() {
// CORS handler
c := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:3000", "https://brierfoxforecast.ngrok.app", "http://localhost:8089"},
AllowedOrigins: []string{"http://172.29.0.10:5173/", "https://brierfoxforecast.ngrok.app", "http://localhost:8089"},
AllowedMethods: []string{"GET", "POST", "OPTIONS"},
AllowedHeaders: []string{"Content-Type", "Authorization"},
})
Expand Down
24 changes: 22 additions & 2 deletions compose-dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
#!/bin/bash

set -e
set -a

source .env.dev

# Start backend and database
docker-compose --env-file .env.dev up
# Function to check if a command exists
command_exists() {
type "$1" &> /dev/null
}

# Function to run Docker Compose using either docker-compose or docker compose
run_docker_compose() {
if command_exists docker-compose; then
echo "Using docker-compose..."
docker-compose --env-file .env.dev up
elif command_exists docker && docker compose version &> /dev/null; then
echo "Using docker compose..."
docker compose --env-file .env.dev up
else
echo "Error: Docker Compose is not installed."
exit 1
fi
}

# Start backend and database using the appropriate Docker Compose command
run_docker_compose
25 changes: 22 additions & 3 deletions compose-dev-down
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
#!/bin/bash

set -e

set -a
source .env.dev

# Start the database
docker-compose --env-file .env.dev down
# Function to check if a command exists
command_exists() {
type "$1" &> /dev/null
}

# Function to run Docker Compose down using either docker-compose or docker compose
run_docker_compose_down() {
if command_exists docker-compose; then
echo "Using docker-compose to shut down services..."
docker-compose --env-file .env.dev down
elif command_exists docker && docker compose version &> /dev/null; then
echo "Using docker compose to shut down services..."
docker compose --env-file .env.dev down
else
echo "Error: Docker Compose is not installed."
exit 1
fi
}

# Shut down services using the appropriate Docker Compose command
run_docker_compose_down
19 changes: 19 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
version: '3.8'

services:

db:
networks:
- custom_network

backend:
environment:
- ENVIRONMENT=development
Expand All @@ -13,6 +18,8 @@ services:
- ./.env.dev:/backend/.env.dev # mount this .env.dev file to keep dev env var's consistent
command: reflex -r '\.go$' -s -- sh -c './supervisor.sh'
tty: true
networks:
- custom_network

frontend:
environment:
Expand All @@ -25,6 +32,9 @@ services:
- ./frontend:/app # This line mounts your frontend directory to /app in the container
- /app/node_modules # This line prevents node_modules in the container from being overwritten
stdin_open: true
networks:
custom_network:
ipv4_address: 172.29.0.10 # Static IP for frontend

nginx:
environment:
Expand All @@ -37,3 +47,12 @@ services:
- .env.dev
volumes:
- ./nginx:/etc/nginx/
networks:
- custom_network

networks:
custom_network:
driver: bridge
ipam:
config:
- subnet: "172.29.0.0/16"
69 changes: 1 addition & 68 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,3 @@
# 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:

### `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)
* Need to update this with instructions for vite including port.
8 changes: 5 additions & 3 deletions frontend/frontend.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# syntax=docker/dockerfile:1.3-labs
FROM node:16.0.0
FROM node:21.0.0

RUN echo "No op change"

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .

EXPOSE 3000
CMD ["npm", "start"]
EXPOSE 5173
CMD ["npm", "run", "start"]
2 changes: 1 addition & 1 deletion frontend/package-lock.json

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

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"web-vitals": "^2.1.4"
},
"engines": {
"node": "16.0.0"
"node": "21.0.0"
},
"scripts": {
"start": "vite",
"start": "vite --host",
"build": "vite build",
"serve": "vite preview"
},
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const API_URL = 'https://brierfoxforecast.ngrok.app';
// export const API_URL = 'http://localhost:8089';
// export const API_URL = 'https://brierfoxforecast.ngrok.app';
export const API_URL = 'http://localhost:8089';
File renamed without changes.
2 changes: 1 addition & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ http {
}

location / {
proxy_pass http://frontend:3000/;
proxy_pass http://frontend:5173/;
}
}
}
2 changes: 1 addition & 1 deletion nginx/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ http {
}

location / {
proxy_pass http://frontend:3000/;
proxy_pass http://frontend:5173/;
}
}
}