Skip to content

Commit

Permalink
hotfix for js loading issues (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
The0zzy authored Jan 23, 2024
2 parents a09d742 + 192ab44 commit 5ee1c2d
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 164 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Docker Build
name: Build Docker Image

on:
workflow_dispatch:
pull_request:
branches:
- none
push:
branches:
- main
Expand Down Expand Up @@ -54,3 +51,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
file: './docker/dockerfile'
33 changes: 13 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,37 @@ If you're not familiar with Django or Wagtail, it might be good to start with [w

You need to install the following applications on your system

- [Python](https://www.python.org/downloads/)
- [NodeJS / npm package manager](https://nodejs.org/en/download)
- [Python](https://www.python.org/downloads/) [^3.11]
- [Docker](https://www.docker.com)

### Setup
## Todo
- [ ] docker `pre-commit` hooks in docker environment
- all hooks except `commit-msg-validator` are working.

- Create a Python Virtual Environment and activate it
### Setup
- Clone in repo and cd into it
```
py -m venv ./python-venvs/bfportal
./python-venvs/bfportal/Scripts/activate
git clone https://gh.bfportal.gg/
```
- Install [poetry](https://python-poetry.org/docs/#installation) for dependency management
```
curl -sSL https://install.python-poetry.org | python3 -
```
- Install python dependencies
- Install project dependencies
```
cd bfportal.gg
poetry install
```
- Install the pre-commit hooks by running
```
pre-commit install --install-hooks
```
- Install npm dependencies
```
cd bfportal.gg/bfportal
npm install
```

- Copy the `.env.template` file to `.env`
- (optional) Create a [discord application](https://discord.com/developers/applications) for OAuth2 and copy the client id and secret
- Paste the client id and secret in `.env` file to `DISCORD_CLIENT_ID` and `DISCORD_SECRET` respectively
- From the repositories root directory build the necessary docker images and run the platform
```
docker-compose --profile dev_local up
docker-compose up
```
- The website should become available at `127.0.0.1:8000`

Expand All @@ -115,17 +111,14 @@ You need to install the following applications on your system

You need to install the following applications on your system

- [Python](https://www.python.org/downloads/)
- [Python](https://www.python.org/downloads/) [^3.11]
- [NodeJS / npm package manager](https://nodejs.org/en/download)
- [PostgreSQL](https://www.postgresql.org/)

### Setup

- Create a Python Virtual Environment and activate it
```
py -m venv ./python-venvs/bfportal
./python-venvs/bfportal/Scripts/activate
```
<!-- no need to create venv as poetry will create one -->

- Install [poetry](https://python-poetry.org/docs/#installation) for dependency management
```
curl -sSL https://install.python-poetry.org | python3 -
Expand Down
3 changes: 0 additions & 3 deletions bfportal/bfportal/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,10 @@
{% endblock %}
{# Global javascript #}
<script src="{% static 'js/jquery.min.js' %}"
integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js"
integrity="sha512-57oZ/vW8ANMjR/KQ6Be9v/+/h6bq9/l3f0Oc7vn6qMqyhvPd1cvKBRWWpzu0QoneImqr2SkmO4MSqU+RpHom3Q=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"
integrity="sha512-z4OUqw38qNLpn1libAN9BsoDx6nbNFio5lA6CuTp9NlK83b89hgyCVq+N5FdBJptINztxn1Z3SaKSKUS5UP60Q=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="{% static 'js/jquery.waypoints.js' %}"></script>
Expand Down
9 changes: 9 additions & 0 deletions bfportal/core/management/commands/playground.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from pathlib import Path

from django.core.management import BaseCommand
from loguru import logger


class Command(BaseCommand):
def handle(self, *args, **options):
logger.debug("This is a command to be used as a playground")
2 changes: 1 addition & 1 deletion bfportal/core/templates/core/home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<p class="shrink-0">Submit Experience</p>
</div>
</a>
<a href="/tutorials">
<a href="https://docs.bfportal.gg/" target="_blank">
<div class="flex flex-row text-white gap-x-1 min-w-fit items-center rounded px-1 hover:bg-card-bg transition duration-200 ease-in-out">
<img src="{% static 'svgs/pages/help_&_tutorials.svg' %}" alt="">
<p>Help & Tutorials</p>
Expand Down
2 changes: 1 addition & 1 deletion bfportal/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,5 @@ def events_view(request: HttpRequest):
"""Handles /events page"""
return render(
request,
"502.html",
"coming_soon.html",
)
145 changes: 10 additions & 135 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,131 +2,12 @@ version: "3.7"

services:

# Production environment services
db:
image: postgres:14
restart: always
profiles:
- production
volumes:
- postgress_db:/var/lib/postgresql/data

environment:
- POSTGRES_NAME=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: "10s"
timeout: "5s"
retries: 5
start_period: "10s"

bfportal_gg_production:
image: docker.pkg.github.com/battlefield-portal-community/bfportal.gg/main:latest
restart: always
command: bash -c "python manage.py migrate --noinput && python manage.py ensure_superuser --username bfportal --email [email protected] --password '${SU_PASSWD}' && python manage.py ensure_initialization && gunicorn --workers 4 --bind 0.0.0.0:${PRODUCTION_PORT}"
user: "33:33"
profiles:
- production
ports:
- "${PRODUCTION_PORT}:${PRODUCTION_PORT}"
volumes:
- type: "bind"
source: /var/www/bfportal-media
target: /app/media
environment:
- PRODUCTION_KEY=${PRODUCTION_KEY}
- DISCORD_CLIENT_ID=${DISCORD_CLIENT_ID}
- DISCORD_SECRET=${DISCORD_SECRET}
- DB_NAME=${DB_NAME}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- POSTGRES_HOST=db # takes precedent over .env file
- DEBUG=${DEBUG}
- APPROVAL_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_CHANNEL_WEBHOOK_ID=${APPROVAL_CHANNEL_WEBHOOK_ID}
- APPROVAL_SUCCESS_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_SUCCESS_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_SUCCESS_CHANNEL_WEBHOOK_ID=${APPROVAL_SUCCESS_CHANNEL_WEBHOOK_ID}
- PRODUCTION_HOST=${PRODUCTION_HOST}
- PRODUCTION_PORT=${PRODUCTION_PORT}
- OWNERS=${OWNERS}
depends_on:
- db
healthcheck:
test: curl -fk http://0.0.0.0:${PRODUCTION_PORT}/ || exit 1
interval: "60s"
timeout: "3s"
retries: 3
start_period: "5s"

# Dev environment services (on remote server)
db_devel:
image: postgres:14
restart: always
profiles:
- dev
volumes:
- postgress_db_devel:/var/lib/postgresql/data

environment:
- POSTGRES_NAME=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: "10s"
timeout: "5s"
retries: 5
start_period: "10s"

bfportal_gg_dev:
image: docker.pkg.github.com/battlefield-portal-community/bfportal.gg/dev:latest
restart: always
command: bash -c "python manage.py migrate --noinput && python manage.py ensure_superuser --username bfportal --email [email protected] --password '${SU_PASSWD}' && python manage.py ensure_initialization && gunicorn --workers 4 --bind 0.0.0.0:${DEVEL_PORT}"
user: "33:33"
profiles:
- dev
ports:
- "${DEVEL_PORT}:${DEVEL_PORT}"
volumes:
- type: "bind"
source: /var/www/bfportal-devel-media
target: /app/media
environment:
- PRODUCTION_KEY=${PRODUCTION_KEY}
- DISCORD_CLIENT_ID=${DISCORD_CLIENT_ID}
- DISCORD_SECRET=${DISCORD_SECRET}
- DB_NAME=${DB_NAME}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- POSTGRES_HOST=db_devel # takes precedent over .env file
- DEBUG=True
- APPROVAL_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_CHANNEL_WEBHOOK_ID=${APPROVAL_CHANNEL_WEBHOOK_ID}
- APPROVAL_SUCCESS_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_SUCCESS_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_SUCCESS_CHANNEL_WEBHOOK_ID=${APPROVAL_SUCCESS_CHANNEL_WEBHOOK_ID}
- PRODUCTION_HOST=${PRODUCTION_HOST}
- PRODUCTION_PORT=${PRODUCTION_PORT}
- OWNERS=${OWNERS}
- DEVEL_PORT=${DEVEL_PORT}
depends_on:
- db_devel
healthcheck:
test: curl -fk http://0.0.0.0:${DEVEL_PORT}/ || exit 1
interval: "60s"
timeout: "3s"
retries: 3
start_period: "5s"

# Dev environment services (on local machine)
db_dev_local:
db:
image: postgres:14
restart: always
volumes:
- postgress_db_dev_local:/var/lib/postgresql/data
profiles:
- dev_local
- postgres_db_dev_local:/var/lib/postgresql/data
environment:
- POSTGRES_NAME=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
Expand All @@ -138,16 +19,14 @@ services:
retries: 5
start_period: "10s"

bfportal_dev_local:
bfportal:
build:
context: .
dockerfile: Dockerfile
dockerfile: docker/Dockerfile
target: dev
restart: no
command: bash -c "python manage.py migrate --noinput && python manage.py ensure_superuser --username bfportal --email [email protected] --password 1234 && python manage.py ensure_initialization && python manage.py mock -u 10 -e 50 --noregen && python manage.py runserver 0.0.0.0:8000"
container_name: bfportal_dev_local
profiles:
- dev_local
ports:
- "8000:8000"
volumes:
Expand All @@ -158,7 +37,7 @@ services:
- DB_NAME=${DB_NAME}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- POSTGRES_HOST=db_dev_local # takes precedent over .env file
- POSTGRES_HOST=db # takes precedent over .env file
- DEBUG=True
- APPROVAL_CHANNEL_WEBHOOK_TOKEN=${APPROVAL_CHANNEL_WEBHOOK_TOKEN}
- APPROVAL_CHANNEL_WEBHOOK_ID=${APPROVAL_CHANNEL_WEBHOOK_ID}
Expand All @@ -175,26 +54,22 @@ services:
retries: 5
start_period: "10s"
depends_on:
- db_dev_local
- db

bfportal_dev_local_tailwind:
tailwind:
build:
context: .
dockerfile: Dockerfile
dockerfile: docker/dockerfile
target: dev
command: npm run watch
restart: always
container_name: bfportal_dev_local_tailwind
profiles:
- dev_local
volumes:
- ./bfportal:/app
depends_on:
bfportal_dev_local:
bfportal:
condition: service_healthy
stdin_open: true

volumes:
postgress_db_devel:
postgress_db:
postgress_db_dev_local:
postgres_db_dev_local:
Loading

0 comments on commit 5ee1c2d

Please sign in to comment.