From ece58399a5e8e5cfaff0f18ebae94f993206bfee Mon Sep 17 00:00:00 2001 From: Euan Date: Mon, 15 Jan 2024 20:40:54 +0000 Subject: [PATCH 1/2] hitting DNS issues --- backend/Dockerfile | 7 +++++-- backend/main.go | 4 ++-- docker-compose.yml | 18 ++++++++++++++++-- frontend/Dockerfile | 3 ++- frontend/package.json | 2 +- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 0de4502d7..564467c89 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,13 +1,16 @@ -FROM golang:1.20.2-alpine3.16 AS build +FROM golang:1.21-alpine AS build WORKDIR /work COPY . . RUN \ --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg/mod \ - go build -o backend backend.go + go build -o backend FROM alpine:3.16 AS final COPY --from=build /work/backend /bin/backend +ENV HOSTNAME backend +EXPOSE 8080 + WORKDIR / ENTRYPOINT ["/bin/backend"] diff --git a/backend/main.go b/backend/main.go index 44b75dd73..ac5b6dbbe 100644 --- a/backend/main.go +++ b/backend/main.go @@ -15,7 +15,7 @@ func CORSConfig(localEnv bool) cors.Config { corsConfig := cors.DefaultConfig() if localEnv { log.Println("Local mode - Disabling CORS nonsense") - corsConfig.AllowOrigins = []string{"https://www.openweightlifting.org", "http://localhost:3000"} + corsConfig.AllowOrigins = []string{"https://www.openweightlifting.org", "http://localhost:3000", "http://frontend-app:3000", "*"} } else { corsConfig.AllowOrigins = []string{"https://www.openweightlifting.org"} } @@ -74,7 +74,7 @@ func CacheMeOutsideHowBoutDat() { func main() { apiServer := buildServer() go CacheMeOutsideHowBoutDat() - err := apiServer.Run() + err := apiServer.Run("backend:8080") // listen and serve on if err != nil { log.Fatal("Failed to run server") } diff --git a/docker-compose.yml b/docker-compose.yml index 1c28fadb5..b9838c477 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,24 +6,38 @@ services: restart: always build: context: ./backend + expose: + - "8080" ports: - "8080:8080" + networks: + - backend-network volumes: - ./backend/event_data:/event_data environment: + - HOSTNAME=backend - PORT=8080 command: local client: - container_name: next-app + container_name: frontend-app build: context: ./frontend args: - - API=http://localhost:8080 + - API=http://backend:8080 + expose: + - "3000" ports: - "3000:3000" + networks: + - backend-network depends_on: - backend environment: - NODE_ENV=development - CHOKIDAR_USEPOLLING=true + + +networks: + backend-network: + driver: bridge \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 2576ce522..0d34aed3e 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,5 +1,5 @@ # base image -FROM node:18.7.0 +FROM node:18.4-alpine ARG API ENV API $API @@ -15,5 +15,6 @@ COPY . . # build RUN --mount=type=cache,target=/usr/src/app/.next/cache npm run build +EXPOSE 3000 # start app CMD ["npm", "run", "dev"] diff --git a/frontend/package.json b/frontend/package.json index 9eddfb51a..2a1dd9e15 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "API=http://localhost:8080 next dev", + "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint", From 1e57e45ae7d08a0993e581811f0c9ebfaa97a0f2 Mon Sep 17 00:00:00 2001 From: Euan Date: Wed, 17 Jan 2024 21:59:48 +0000 Subject: [PATCH 2/2] improved readme --- README.md | 55 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3a36c1099..0fbec0bc3 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,64 @@ # OpenWeightlifting +This is the monorepo for the OpenWeightlifting.org project. The aim of this project is to build a database of the latest Olympic Weightlifting results from all around the world. This originally started from a scraping tool and quickly grew into what you see here now. All the results within the database were pulled directly from the event results pages from the National Governing Body of that nation. We try to avoid manual data entry so this is all done with our tooling written in Python. -[![codecov](https://codecov.io/gh/euanwm/OpenWeightlifting/branch/development/graph/badge.svg?token=CX7H10ZNLM)](https://codecov.io/gh/euanwm/OpenWeightlifting) +There's always some questions around certain design decisions in this project so we'll address them now. + +### Why Golang for the backend? +Originally it was Python but the build time was terrible and the response times were slow. Not only that but the memory usage was high. Golang was chosen because it's fast, has a low memory footprint and the build times are quick. It's also a language that's easy to pick up and learn. We migrated from Python to Golang within in a week of picking up the language. + +### Why NextJS for the frontend? +This was a bit of a no brainer. We wanted to use React and NextJS (TS) is a great framework for it. The amount of features around rounting, server side rendering and static site generation is great. While it can also serve as a backend, we've chosen to keep the backend and frontend separate due the performance benefits of having a dedicated backend. ## Local Testing -We've added a docker-compose file to make it easier to test locally. This will spin up a local instance of the backend and frontend services. In production, these services are deployed separately. +Majority of the contributors on this are FE developers, so we've containerised the front and backend portions of the project. To get going quickly with the project, you'll need to have docker installed. + +### Frontend Development (NextJS) +From the root of the project, run the following commands to spin up a backend container and launch the frontend. +```bash +docker compose up -d backend +cd frontend +npm install +npm run dev +``` +While the backend service is running, you'll also be able to run the FE API call tests against it. ```bash -docker-compose build -docker-compose up +npm run test ``` -When you get bored and want to kill it... +Once you're done, you can stop the backend container with the following command. ```bash -docker-compose down +docker compose down ``` -### Backend-only +### Backend Development (Golang) When launching the backend service you'll need to toggle the CORS flag which is done be adding the 'local' argument when calling the executable. ```bash go build backend.go ./backend local ``` -### Frontend-only -We prefer to use npm for the frontend stuff. +## Database Management (Python) +To pull the latest results from the all relevant federations, we've added a Makefile with a few commands to make it easier. You'll need to have pipenv installed to run the commands. +### Pulling the latest results ```bash -npm install -npm run dev +make update_database +``` + +### Staging the latest results +This came about so if you have a messy amount of unstaged changes, you can stage them all and then commit them in one go. +```bash +make stage_csv ``` -### Updating the database -To pull the latest results from the all relevant federations, you'll need to run the following command from the python_tools directory: +### Checking the database +In order to reduce the amount of checks at runtime, we've added a check to make sure the database is in a good state. This will check for duplicate entries and missing data. ```bash -pipenv install -pipenv run python backend_cli.py --update all +make check_db ``` -### License +# License Done this under the BSD-3-Clause license. Simply because it's what the sport80 library is under and i'm hella lazy. -### Contributing +# Contributing If you want to contribute, please do! We're always looking for more people to help out. If you're not sure where to start, check out the issues page and join the discord server. https://discord.gg/kqnBqdktgr \ No newline at end of file