Skip to content

Commit

Permalink
Merge pull request #26 from mc-putchar/dev
Browse files Browse the repository at this point in the history
From: dev To: main Subject: PMergeMe
  • Loading branch information
CarloCattano authored Sep 30, 2024
2 parents baae2fd + 6c2c9cb commit baf11cf
Show file tree
Hide file tree
Showing 108 changed files with 8,490 additions and 5,017 deletions.
26 changes: 13 additions & 13 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Server
DEPLOY=
DOMAIN=localhost
CLOUDFLARE_TUNNEL_TOKEN=
TUNNEL_ID=
DEPLOY= # <yespls/ > leave empty for localhost
DOMAIN=localhost # Or set domain for tunnel deployment
CLOUDFLARE_TUNNEL_TOKEN= # Cloudflare tunnel token or leave empty
TUNNEL_ID= # Cloudflare tunnel ID or leave empty
# Database
POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=db_transcendence # Set name for Postgres database
POSTGRES_USER= # Set username for Postgres database user
POSTGRES_PASSWORD= # Set password for Postgres database user
# Django
DJANGO_SECRET_KEY=
DJANGO_ALLOWED_HOSTS= # Django allowed hosts: comma separated, no []
DJANGO_TRUSTED_ORIGINS= # Django trusted origins: no trailing /
DJANGO_SECRET_KEY= # Django secret key
DJANGO_ALLOWED_HOSTS=localhost # Django allowed hosts: comma separated, no []
DJANGO_TRUSTED_ORIGINS=https://localhost # Django trusted origins: no trailing /
# OAuth
CLIENT_ID=
CLIENT_SECRET=
REDIRECT_URI=
CLIENT_ID= # OAuth client ID
CLIENT_SECRET= # OAuth client secret
REDIRECT_URI=https://localhost/redirect # same as registered OAuth redirect URI
# Blockchain
HARDHAT_PRIVATE_KEY=
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__pycache__
.env
*.env
.env_local
.env_deploy
.venv/
Expand All @@ -11,7 +11,7 @@ migrations
staticfiles
.venv
__pycache__
.env
*.env
pong/testenv
testenv
tags
Expand Down
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[submodule "ft_ascii"]
path = ft_ascii
url = git@github.com:CarloCattano/ft_ascii
branch = pong

41 changes: 41 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--.-..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..-
/ .. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. . \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.
\ \/\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ .
\/ /`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'-'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`.
/ /\ / /\
/ /\ \ / /\ \
\ \/ / \ \/ /
\/ / \/ /
/ /\ ██████╗ █████╗ ██████╗ ██╗ ██████╗ ██████╗ █████╗ ████████╗████████╗ █████╗ ███╗ ██╗ ██████╗ / /\
/ /\ \ ██╔════╝██╔══██╗██╔══██╗██║ ██╔═══██╗ ██╔════╝██╔══██╗╚══██╔══╝╚══██╔══╝██╔══██╗████╗ ██║██╔═══██╗ / /\ \
\ \/ / ██║ ███████║██████╔╝██║ ██║ ██║ ██║ ███████║ ██║ ██║ ███████║██╔██╗ ██║██║ ██║ \ \/ /
\/ / ██║ ██╔══██║██╔══██╗██║ ██║ ██║ ██║ ██╔══██║ ██║ ██║ ██╔══██║██║╚██╗██║██║ ██║ \/ /
/ /\ ╚██████╗██║ ██║██║ ██║███████╗╚██████╔╝ ╚██████╗██║ ██║ ██║ ██║ ██║ ██║██║ ╚████║╚██████╔╝ / /\
/ /\ \ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ / /\ \
\ \/ / \ \/ /
\/ / ██╗ ██╗███████╗███╗ ██╗██████╗ ██╗ ██╗ █████╗ ██╗ ██╗██████╗ ███████╗███╗ ██╗ ██████╗███████╗ \/ /
/ /\ ██║ ██║██╔════╝████╗ ██║██╔══██╗██║ ██║ ██╔══██╗██║ ██║██╔══██╗██╔════╝████╗ ██║██╔════╝██╔════╝ / /\
/ /\ \ ███████║█████╗ ██╔██╗ ██║██████╔╝██║ ██║ ███████║██║ ██║██████╔╝█████╗ ██╔██╗ ██║██║ █████╗ / /\ \
\ \/ / ██╔══██║██╔══╝ ██║╚██╗██║██╔══██╗██║ ██║ ██╔══██║██║ ██║██╔══██╗██╔══╝ ██║╚██╗██║██║ ██╔══╝ \ \/ /
\/ / ██║ ██║███████╗██║ ╚████║██║ ██║██║ ███████╗██║ ██║╚██████╔╝██║ ██║███████╗██║ ╚████║╚██████╗███████╗ \/ /
/ /\ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═════╝╚══════╝ / /\
/ /\ \ / /\ \
\ \/ / ███╗ ███╗ █████╗ ██████╗ ████████╗██╗███╗ ██╗ ██████╗██╗ ██╗████████╗██╗ ██╗██████╗ █████╗ \ \/ /
\/ / ████╗ ████║██╔══██╗██╔══██╗╚══██╔══╝██║████╗ ██║ ██╔════╝██║ ██║╚══██╔══╝██║ ██║██╔══██╗██╔══██╗ \/ /
/ /\ ██╔████╔██║███████║██████╔╝ ██║ ██║██╔██╗ ██║ ██║ ██║ ██║ ██║ ██║ ██║██████╔╝███████║ / /\
/ /\ \ ██║╚██╔╝██║██╔══██║██╔══██╗ ██║ ██║██║╚██╗██║ ██║ ██║ ██║ ██║ ██║ ██║██╔══██╗██╔══██║ / /\ \
\ \/ / ██║ ╚═╝ ██║██║ ██║██║ ██║ ██║ ██║██║ ╚████║ ╚██████╗╚██████╔╝ ██║ ╚██████╔╝██║ ██║██║ ██║ \ \/ /
\/ / ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ \/ /
/ /\ / /\
/ /\ \ ████████╗██╗███╗ ███╗ ██████╗ ████████╗██╗ ███████╗██████╗ ███████╗ ██████╗ ███╗ ██╗██╗ / /\ \
\ \/ / ╚══██╔══╝██║████╗ ████║██╔═══██╗╚══██╔══╝██║ ██╔════╝██╔══██╗██╔════╝██╔════╝ ████╗ ██║██║ \ \/ /
\/ / ██║ ██║██╔████╔██║██║ ██║ ██║ ██║ █████╗ ██████╔╝█████╗ ██║ ███╗██╔██╗ ██║██║ \/ /
/ /\ ██║ ██║██║╚██╔╝██║██║ ██║ ██║ ██║ ██╔══╝ ██╔══██╗██╔══╝ ██║ ██║██║╚██╗██║██║ / /\
/ /\ \ ██║ ██║██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██║ ██║ ██║███████╗╚██████╔╝██║ ╚████║██║ / /\ \
\ \/ / ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ \ \/ /
\/ / \/ /
/ /\ / /\
/ /\.--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--.-..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..--..-
/ /\ \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. . \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.. \.
\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `'\ `
`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'-'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`--'`-
103 changes: 61 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,64 @@ COLOUR_MAGB := \033[1;35m
COLOUR_CYN := \033[36m
COLOUR_CYNB := \033[1;36m

.PHONY: up down start stop re debug swapmode clitest testlogin migrate clean collect schema tests help
.PHONY: help up down start stop re logs logs-django ps db-shell migrate debug clean shred collect schema newkey swapmode maintenance clitest testlogin tests

help: # Display this helpful message
@awk 'BEGIN { \
FS = ":.*#"; printf "Usage:\n\t$(COLOUR_CYNB)make $(COLOUR_MAGB)<target> \
$(COLOUR_END)\n\nTargets:\n"; } \
/^[a-zA-Z_0-9-]+:.*?#/ { \
printf "$(COLOUR_MAGB)%-16s$(COLOUR_CYN)%s$(COLOUR_END)\n", $$1, $$2 } ' \
Makefile

.env:
bash setup_wizard.sh

up: .env # Beam me up, Scotty
$(info "Aye, aye Cap'n!")
@echo -e "Deploying $(COLOUR_GREEN)${DOMAIN}$(COLOUR_END)"
@echo -e "Building and starting containers, with $(COLOUR_CYNB)$(DC)$(COLOUR_END) and $(COLOUR_MAGB)$(SRC)$(COLOUR_END)"
$(DC) -f $(SRC) $@ --build

@rm -f pong/static/maintenance.on
$(DC) -f $(SRC) $@ --build -d
down: # Bring 'em down
$(DC) -f $(SRC) $@

start: # Start containers and detach
$(DC) -f $(SRC) $@

stop: # Stop the containers, please
$(DC) -f $(SRC) $@
re: stop # Re-create containers
$(DC) -f $(SRC) up --build --force-recreate -d

logs: # Tail the logs
$(DC) -f $(SRC) logs --tail=100 -f
logs-django: # Tail the Django logs
$(DC) -f $(SRC) logs --tail=100 -f django
ps: # Show running containers
$(DC) -f $(SRC) ps
db-shell: # Run database shell
$(DC) -f $(SRC) exec db psql $(POSTGRES_DB) -U $(POSTGRES_USER)
migrate: # Make and run DB migrations
$(DC) -f $(SRC) stop
$(DC) -f $(SRC) run --build --rm -e SKIP_DEPLOYMENT=true django python manage.py makemigrations $(APPS)
$(DC) -f $(SRC) run --rm -e SKIP_DEPLOYMENT=true django python manage.py migrate
$(DC) -f $(SRC) stop

re: # Re-create containers
$(DC) -f $(SRC) up --build --force-recreate
clean: # clean docker system
docker system prune
shred: down # DROP database (Warning: all database data will be irreversibly lost! Consider making backup)
@docker volume rm $(NAME)_dbdata
@$(MAKE) -s newkey
@echo -e "$(COLOUR_GREEN)^^Here^^$(COLOUR_END) is a new Django key for you, if you need it"

.env:
bash setup_wizard.sh
collect: # Collect static files to be served
$(DC) -f $(SRC) run --rm --no-deps -e SKIP_DEPLOYMENT=true django python manage.py collectstatic --noinput --clear

debug: # DEBUG MODE
@echo -e 'using $(DC) and $(SRC)'
$(DC) -f $(SRC) --profile debug up --build
schema: # Output OpenAPI3 Schema into pong/schema.yml
$(DC) -f $(SRC) run --rm --no-deps -e SKIP_DEPLOYMENT=true django python manage.py spectacular --validate --color --file schema.yml
lolcat -a pong/schema.yml || cat pong/schema.yml

newkey: # Generate a new secret key for Django
$(DC) -f $(SRC) run --rm --no-deps -e SKIP_DEPLOYMENT=true django python manage.py shell -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"

swapmode: .env stop # Swap online/local mode (requires restart)
$(shell \
Expand All @@ -73,6 +106,17 @@ swapmode: .env stop # Swap online/local mode (requires restart)
fi )
$(info Mode swapped.)

maintenance:
touch pong/static/maintenance.on
$(DC) -f $(SRC) stop blockchain
$(DC) -f $(SRC) stop django
$(DC) -f $(SRC) stop db
$(DC) -f $(SRC) stop redis

debug: # DEBUG MODE
@echo -e 'using $(DC) and $(SRC)'
$(DC) -f $(SRC) --profile debug up --build

clitest: # CLI test
cd transcendCLI && source .venv/bin/activate && python $(CLI)

Expand All @@ -81,36 +125,11 @@ testlogin: # Selenium tests
docker exec ft_transcendence-django-1 python test_selenium.py
@echo "Test done"

migrate: # Make and run DB migrations
$(DC) -f $(SRC) stop
$(DC) -f $(SRC) run --build --rm django python manage.py makemigrations $(APPS)
$(DC) -f $(SRC) run --rm django python manage.py migrate
$(DC) -f $(SRC) stop

clean: # DROP database and create a new one
$(DC) -f $(SRC) start db
$(DC) -f $(SRC) exec db dropdb -U ${POSTGRES_USER} ${POSTGRES_DB}
$(DC) -f $(SRC) exec db createdb -U ${POSTGRES_USER} ${POSTGRES_DB}
$(DC) -f $(SRC) stop db

collect: # Collect static files to be served
$(DC) -f $(SRC) run --rm --no-deps django python manage.py collectstatic --noinput --clear

schema: # Output OpenAPI3 Schema into pong/schema.yml
$(DC) -f $(SRC) run --rm --no-deps django python manage.py spectacular --validate --color --file schema.yml
lolcat -a pong/schema.yml || cat pong/schema.yml

tests: # Run automated tests
$(DC) -f $(SRC) start
@echo "Testing smart contract"
@docker exec -it ft_transcendence-blockchain-1 sh -c "npx hardhat test"
$(DC) -f $(SRC) run --rm django python manage.py test
# $(DC) -f $(SRC) start
# @docker exec -it ft_transcendence-blockchain-1 sh -c "npx hardhat test"
@echo -e "$(COLOUR_MAGB)Testing smart contract$(COLOUR_END)"
$(DC) -f $(SRC) run --rm blockchain npx hardhat test
# $(DC) -f $(SRC) run --rm django python manage.py test # should run on separate test volume
$(DC) -f $(SRC) stop

help: # Display this helpful message
@awk 'BEGIN { \
FS = ":.*#"; printf "Usage:\n\t$(COLOUR_CYNB)make $(COLOUR_MAGB)<target> \
$(COLOUR_END)\n\nTargets:\n"; } \
/^[a-zA-Z_0-9-]+:.*?#/ { \
printf "$(COLOUR_MAGB)%-16s$(COLOUR_CYN)%s$(COLOUR_END)\n", $$1, $$2 } ' \
Makefile
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# _ft_transcendence_

[badges]
[![Uptime Robot status](https://img.shields.io/uptimerobot/status/m797505515-6190c28211f4dbd75e68ae49?up_message=ONLINE&up_color=green&down_message=DOWN&down_color=red&style=plastic&link=https%3A%2F%2Fstats.uptimerobot.com%2FiK804X9tfp)](https://stats.uptimerobot.com/iK804X9tfp)

> This project is about doing something you’ve never done before.
> Remind yourself the beginning of your journey in computer science.
> Look at you now. Time to shine!
<p style='text-align: center;'> -- en.subject.pdf (v.15) </p>
[IMAGE_PLACEHOLDER]
![IMAGE_PLACEHOLDER](pong/static/img/jinja-dashboard.png)

# _Description_:
Free open-source web platform, mainly for playing Pong games and tournaments.
Expand All @@ -20,17 +20,24 @@ Inspired by the classic Pong game of the 70s, infused with modern features and t
```
- Follow the Setup Wizard to configure the project for your instance.
Required information:
- valid Django secret key
- valid Django secret key (generate new one with `make newkey` )
- valid PostgreSQL information
- OAuth 42 client id and secret (if you want to use 42 OAuth)
- Hardhat network URL (if you want to use blockchain features)
- registered domain name, cloudflare tunnel token and tunnel id (if you want to deploy online)

- Alteratively, provide own .env file according to the .env.template

- Explore additional options with `make help`
- Explore additional options with
```bash
make help
```

# _Features_:

![Architecture](pong/static/img/napkin-design.png)
> Tip: `make swapmode` to switch between localhost and domain deployment
## _Live Chat_
- Chat with other online users in real time
- Send private messages to other users with `/pm <username> <message>`
Expand Down Expand Up @@ -86,3 +93,9 @@ potential extras:
1 - JWT and 2FA 1
```

for ft_ascii pong cli:
```git submodule update --init```


### Music:
[pixabay](https://pixabay.com/de/music/search/arcade/)
Loading

0 comments on commit baf11cf

Please sign in to comment.