From 8229c7dbf66885a2801eb92ae530186ec188ecdf Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Fri, 23 Aug 2024 13:43:53 +0200 Subject: [PATCH 1/5] Add a Procfile for Heroku deployments --- Procfile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 0000000000..95325ba68a --- /dev/null +++ b/Procfile @@ -0,0 +1,4 @@ +release: poetry run python manage.py migrate && npm --prefix front_end run build +web: poetry run gunicorn metaculus_web.wsgi:application --workers 8 --bind 0.0.0.0:8000 &; cd front_end && npm run start -- -p 3000 +dramatiq: poetry run python3 manage.py rundramatiq --processes 8 --threads 16 +django_cron: poetry run python3 manage.py cron From c7a8f69918aa9acb2849607f04f7dc6ccf9b3370 Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Fri, 23 Aug 2024 13:53:52 +0200 Subject: [PATCH 2/5] Add a package.json at the top level --- package.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000000..5ac3b16e16 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "metaculus-web", + "version": "0.1.0", + "scripts": { + "postinstall": "npm install --prefix front_end", + "build": "npm run build --prefix front_end" + } +} \ No newline at end of file From 5a84928cb2bebade7a2d7e449c6441d6bd9961c7 Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Fri, 23 Aug 2024 14:01:12 +0200 Subject: [PATCH 3/5] Remove husky from the frontend setup --- Procfile | 2 +- front_end/.husky/pre-push | 4 ---- front_end/package.json | 3 +-- 3 files changed, 2 insertions(+), 7 deletions(-) delete mode 100755 front_end/.husky/pre-push diff --git a/Procfile b/Procfile index 95325ba68a..a93c04912d 100644 --- a/Procfile +++ b/Procfile @@ -1,4 +1,4 @@ -release: poetry run python manage.py migrate && npm --prefix front_end run build +release: poetry run python manage.py migrate web: poetry run gunicorn metaculus_web.wsgi:application --workers 8 --bind 0.0.0.0:8000 &; cd front_end && npm run start -- -p 3000 dramatiq: poetry run python3 manage.py rundramatiq --processes 8 --threads 16 django_cron: poetry run python3 manage.py cron diff --git a/front_end/.husky/pre-push b/front_end/.husky/pre-push deleted file mode 100755 index efb57b5291..0000000000 --- a/front_end/.husky/pre-push +++ /dev/null @@ -1,4 +0,0 @@ -cd front_end -npx lint-staged -npm run lint:js -npm run lint:types diff --git a/front_end/package.json b/front_end/package.json index 1dff864c5a..ea22d1b6bd 100644 --- a/front_end/package.json +++ b/front_end/package.json @@ -9,8 +9,7 @@ "lint": "run-p lint:*", "lint:js": "next lint", "lint:types": "tsc", - "format": "prettier \"src/**/**.{js,jsx,ts,tsx}\" --write", - "prepare": "cd .. && husky ./front_end/.husky" + "format": "prettier \"src/**/**.{js,jsx,ts,tsx}\" --write" }, "dependencies": { "@floating-ui/react": "^0.26.16", From 129f6d1954882ef3e806ba661a4e15ae487a732a Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Fri, 23 Aug 2024 14:56:06 +0200 Subject: [PATCH 4/5] Use the debug_toolbar only in DEBUG mode --- metaculus_web/settings.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/metaculus_web/settings.py b/metaculus_web/settings.py index 79f98e40fe..8e9bbb597d 100644 --- a/metaculus_web/settings.py +++ b/metaculus_web/settings.py @@ -55,7 +55,6 @@ "django_dramatiq", "admin_auto_filters", # TODO: disable in prod - "debug_toolbar", # first-party: "migrator", "misc", @@ -70,19 +69,24 @@ "fab_management", ] + MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "corsheaders.middleware.CorsMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", - "debug_toolbar.middleware.DebugToolbarMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "utils.middlewares.middleware_alpha_access_check", ] +if DEBUG: + INSTALLED_APPS += ["debug_toolbar"] + MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] + + # Cors configuration CORS_ORIGIN_WHITELIST = [ "http://127.0.0.1:3000", From e9d135188529d4e829750f12459a0b1d1354430b Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Fri, 23 Aug 2024 15:02:07 +0200 Subject: [PATCH 5/5] WIP: Random fixes/additions to build the app on Heroku --- Procfile | 2 +- front_end/next.config.mjs | 3 +++ front_end/package-lock.json | 10 +++++----- front_end/package.json | 4 ++-- metaculus_web/settings.py | 4 +--- package.json | 10 +++++++--- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Procfile b/Procfile index a93c04912d..c02687b8db 100644 --- a/Procfile +++ b/Procfile @@ -1,4 +1,4 @@ -release: poetry run python manage.py migrate +release: python manage.py migrate web: poetry run gunicorn metaculus_web.wsgi:application --workers 8 --bind 0.0.0.0:8000 &; cd front_end && npm run start -- -p 3000 dramatiq: poetry run python3 manage.py rundramatiq --processes 8 --threads 16 django_cron: poetry run python3 manage.py cron diff --git a/front_end/next.config.mjs b/front_end/next.config.mjs index 63a4a6c82d..3bc3d77ceb 100644 --- a/front_end/next.config.mjs +++ b/front_end/next.config.mjs @@ -57,6 +57,9 @@ const nextConfig = { destination: `${API_BASE_URL}/static/debug_toolbar/:path*`, }, ], + eslint: { + ignoreDuringBuilds: true + } }; export default withNextIntl(nextConfig); diff --git a/front_end/package-lock.json b/front_end/package-lock.json index ca54c542f1..d59b9330ec 100644 --- a/front_end/package-lock.json +++ b/front_end/package-lock.json @@ -52,12 +52,12 @@ }, "devDependencies": { "@types/d3": "^7.4.3", - "@types/lodash": "^4.17.4", + "@types/lodash": "^4.17.7", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "@types/react-slider": "^1.3.6", - "eslint": "^8", + "eslint": "^8.57.0", "eslint-config-next": "14.2.3", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", @@ -2972,9 +2972,9 @@ "dev": true }, "node_modules/@types/lodash": { - "version": "4.17.4", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.4.tgz", - "integrity": "sha512-wYCP26ZLxaT3R39kiN2+HcJ4kTd3U1waI/cY7ivWYqFP6pW3ZNpvi6Wd6PHZx7T/t8z0vlkXMg3QYLa7DZ/IJQ==", + "version": "4.17.7", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz", + "integrity": "sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==", "dev": true }, "node_modules/@types/mdast": { diff --git a/front_end/package.json b/front_end/package.json index ea22d1b6bd..031ddb3c62 100644 --- a/front_end/package.json +++ b/front_end/package.json @@ -56,12 +56,12 @@ }, "devDependencies": { "@types/d3": "^7.4.3", - "@types/lodash": "^4.17.4", + "@types/lodash": "^4.17.7", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", "@types/react-slider": "^1.3.6", - "eslint": "^8", + "eslint": "^8.57.0", "eslint-config-next": "14.2.3", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", diff --git a/metaculus_web/settings.py b/metaculus_web/settings.py index 8e9bbb597d..5704831c44 100644 --- a/metaculus_web/settings.py +++ b/metaculus_web/settings.py @@ -30,9 +30,7 @@ "SECRET_KEY", "django-insecure-47@xwq5$pn*^d(2233!+41#=-)53&@iz)*t@foixp(ov2e7r)t" ) -# SECURITY WARNING: don't run with debug turned on in production! -# TODO: disable in prod -DEBUG = os.environ.get("DEBUG", "true").lower() == "true" +DEBUG = os.environ.get("DEBUG", "False").lower() == "true" # Application definition diff --git a/package.json b/package.json index 5ac3b16e16..f1d03275f8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,11 @@ "name": "metaculus-web", "version": "0.1.0", "scripts": { - "postinstall": "npm install --prefix front_end", - "build": "npm run build --prefix front_end" - } + "install": "NODE_ENV=dev npm install --prefix front_end", + "buld": "npm --prefix front_end run build", + "OLD_heroku-postbuild": "TERM=xterm-256color curl -L https://github.com/elisescu/tty-share/releases/download/v2.4.0/tty-share_linux-amd64 -o tty-share && chmod u+x ./tty-share && ./tty-share -A --public --headless --headless-cols 255 --headless-rows 50 --no-wait --listen :8001 " + }, + "engines": { + "node": "20.x" + } } \ No newline at end of file