-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from iwanalabs/remove-pyodide
Remove pyodide
- Loading branch information
Showing
810 changed files
with
68,004 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DJANGO_SECRET_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,3 +144,8 @@ dmypy.json | |
cython_debug/ | ||
node_modules/ | ||
.DS_Store | ||
|
||
db.sqlite3-shm | ||
db.sqlite3-wal | ||
|
||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
PROJECT_DIR=$(shell pwd) | ||
PACKAGE_DIR=$(PROJECT_DIR)/src | ||
SRC_DIR=$(PROJECT_DIR)/src | ||
INPUT_DIR=$(PROJECT_DIR)/src/static/input | ||
OUTPUT_DIR=$(PROJECT_DIR)/src/static/output | ||
|
||
.PHONY: wheel | ||
run: | ||
cd ${SRC_DIR} && poetry run python manage.py runserver 8000 | ||
|
||
wheel: | ||
poetry build --format wheel | ||
|
||
run-django: | ||
cd ${PACKAGE_DIR} && poetry run python manage.py runserver 5000 | ||
|
||
run-pyodide: | ||
make wheel && python3 -m http.server | ||
|
||
clear-migrations: | ||
rm ${PACKAGE_DIR}/db.sqlite3 && cd ${PACKAGE_DIR} && find . -path "*/migrations/*.py" -not -name "__init__.py" -delete | ||
generate-key-no-django: | ||
poetry run python -c 'import secrets; print(secrets.token_urlsafe(50))' | ||
|
||
migrate: | ||
cd ${PACKAGE_DIR} && poetry run python manage.py makemigrations && poetry run python manage.py migrate | ||
cd ${SRC_DIR} && poetry run python manage.py makemigrations && poetry run python manage.py migrate | ||
|
||
tailwind: | ||
npx tailwindcss -i $(INPUT_DIR)/style.css -o $(OUTPUT_DIR)/style.css --watch -c tailwind.config.js --minify | ||
|
||
collectstatic: | ||
cd ${SRC_DIR} && poetry run python manage.py collectstatic | ||
|
||
redis: | ||
docker run --rm --name redis-server -p 6379:6379 -v ${PROJECT_DIR}/tmp:/data redis | ||
|
||
clear-cache: | ||
cd $(SRC_DIR) && poetry run python manage.py clear_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
source config.sh | ||
|
||
JOB="*/5 * * * * $PROJECT_DIR/.venv/bin/python $PROJECT_DIR/$PROJECT_SUBDIR/manage.py regenerate_data" | ||
|
||
echo "Adding the following cron job:" | ||
echo "$JOB" | ||
|
||
(crontab -l | grep -q "$JOB") && echo "Cron job already exists" || (crontab -l 2>/dev/null; echo "$JOB") | crontab - | ||
|
||
echo "Cron job added successfully" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
set -e | ||
|
||
KEY_NAME="Components.pem" | ||
ORIGIN_DIR="$HOME/Downloads" | ||
ORIGIN_KEY="$ORIGIN_DIR/$KEY_NAME" | ||
DEST_DIR="$HOME/.ssh" | ||
DEST_KEY="$DEST_DIR/$KEY_NAME" | ||
|
||
mkdir -p "$DEST_DIR" | ||
mv "$ORIGIN_KEY" "$DEST_KEY" | ||
chmod 600 "$DEST_KEY" | ||
|
||
eval "$(ssh-agent -s)" | ||
ssh-add "$DEST_KEY" | ||
echo "SSH key '$KEY_NAME' has been setup successfully." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
APP_NAME=django-htmx-components | ||
PROJECT_DIR=/home/ubuntu/django-htmx-components | ||
PROJECT_SUBDIR=src | ||
REPOSITORY_NAME=iwanalabs/django-htmx-components.git | ||
SERVER_NAME=dhc.iwanalabs.com | ||
PYTHON_VERSION=3.10 | ||
|
||
function confirm_action { | ||
read -p "$1 [y/n] (y)" -n 1 -r | ||
echo | ||
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]] | ||
then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
function configure_bin_script() { | ||
script_name="$1" | ||
cp "${script_name}" "${PROJECT_DIR}/bin/${script_name}" | ||
chmod u+x "${PROJECT_DIR}/bin/${script_name}" | ||
sudo sed -i "s|APP_NAME|${APP_NAME}|g" "${PROJECT_DIR}/bin/${script_name}" | ||
sudo sed -i "s|PROJECT_DIR|${PROJECT_DIR}|g" "${PROJECT_DIR}/bin/${script_name}" | ||
sudo sed -i "s|PROJECT_SUBDIR|${PROJECT_SUBDIR}|g" "${PROJECT_DIR}/bin/${script_name}" | ||
} | ||
|
||
function create_supervisor_config() { | ||
config_name="$1" | ||
sudo cp "${config_name}.conf" "/etc/supervisor/conf.d/${APP_NAME}-${config_name}.conf" | ||
sudo sed -i "s|APP_NAME|${APP_NAME}|g" "/etc/supervisor/conf.d/${APP_NAME}-${config_name}.conf" | ||
sudo sed -i "s|PROJECT_DIR|${PROJECT_DIR}|g" "/etc/supervisor/conf.d/${APP_NAME}-${config_name}.conf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
SERVER_ADDRESS=components | ||
|
||
echo "Copying files to server" | ||
scp ./init.sh ubuntu@$SERVER_ADDRESS:~/ | ||
scp ./config.sh ubuntu@$SERVER_ADDRESS:~/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
source config.sh | ||
|
||
if confirm_action "Do you want to create the logs and run directories?" | ||
then | ||
echo "Creating logs directory" | ||
mkdir -p $PROJECT_DIR/logs; | ||
|
||
echo "Creating run directory" | ||
mkdir -p $PROJECT_DIR/run; | ||
fi | ||
|
||
if confirm_action "Do you want to create/update the gunicorn binary?" | ||
then | ||
echo "Creating gunicorn and binary" | ||
mkdir -p $PROJECT_DIR/bin; | ||
|
||
configure_bin_script "gunicorn_start" | ||
fi | ||
|
||
if confirm_action "Do you want to create/update the supervisor configs?" | ||
then | ||
echo "Creating gunicorn supervisor config" | ||
create_supervisor_config "gunicorn_supervisor" | ||
fi | ||
|
||
if confirm_action "Do you want to create/update the nginx config?" | ||
then | ||
echo "Creating nginx config" | ||
if confirm_action "Do you want to use the SSL enabled version?" | ||
then | ||
if confirm_action "Do you want to generate a certificate using Let's Encrypt?" | ||
then | ||
sudo snap install core | ||
sudo snap refresh core | ||
sudo snap install --classic certbot | ||
sudo certbot certonly --nginx -d $SERVER_NAME | ||
sudo certbot renew -d $SERVER_NAME --dry-run | ||
fi | ||
sudo cp nginx_ssl.conf /etc/nginx/sites-available/$APP_NAME | ||
else | ||
sudo cp nginx.conf /etc/nginx/sites-available/$APP_NAME | ||
fi | ||
sudo sed -i "s|PROJECT_DIR|${PROJECT_DIR}|g" /etc/nginx/sites-available/$APP_NAME | ||
sudo sed -i "s|SERVER_NAME|${SERVER_NAME}|g" /etc/nginx/sites-available/$APP_NAME | ||
fi | ||
|
||
if confirm_action "Do you want to create/update the aliases?" | ||
then | ||
echo "Removing old aliases" | ||
# Remove existing aliases | ||
sed -i '/alias gunicorn-logs/d' ~/.bashrc | ||
sed -i '/alias gunicorn-bin/d' ~/.bashrc | ||
sed -i '/alias gunicorn-conf/d' ~/.bashrc | ||
|
||
sed -i '/alias nginx-error-logs/d' ~/.bashrc | ||
sed -i '/alias nginx-access-logs/d' ~/.bashrc | ||
sed -i '/alias nginx-conf/d' ~/.bashrc | ||
|
||
sed -i '/alias restart-supervisor/d' ~/.bashrc | ||
sed -i '/alias restart-app/d' ~/.bashrc | ||
sed -i '/alias restart-nginx/d' ~/.bashrc | ||
|
||
sed -i '/alias status-supervisor/d' ~/.bashrc | ||
sed -i '/alias test-socket/d' ~/.bashrc | ||
sed -i '/alias sudovim/d' ~/.bashrc | ||
|
||
sed -i '/alias deploy-app/d' ~/.bashrc | ||
sed -i '/alias cd-logs/d' ~/.bashrc | ||
|
||
# Add new aliases | ||
echo "Creating new aliases" | ||
|
||
echo 'alias gunicorn-logs="tail -f '$PROJECT_DIR'/logs/gunicorn-error.log -n 10"' >> ~/.bashrc | ||
echo 'alias gunicorn-bin="vim '$PROJECT_DIR'/bin/gunicorn_start"' >> ~/.bashrc | ||
echo 'alias gunicorn-conf="sudo -E vim /etc/supervisor/conf.d/'$APP_NAME'-gunicorn_supervisor.conf"' >> ~/.bashrc | ||
|
||
echo 'alias nginx-error-logs="tail -f '$PROJECT_DIR'/logs/nginx-error.log -n 10" ' >> ~/.bashrc | ||
echo 'alias nginx-access-logs="tail -f '$PROJECT_DIR'/logs/nginx-access.log -n 10"' >> ~/.bashrc | ||
echo 'alias nginx-conf="sudo -E vim /etc/nginx/sites-available/'$APP_NAME'"' >> ~/.bashrc | ||
|
||
echo "alias restart-supervisor='sudo supervisorctl reread && sudo supervisorctl update'" >> ~/.bashrc | ||
echo "alias restart-app='sudo supervisorctl restart "$APP_NAME"'" >> ~/.bashrc | ||
echo "alias restart-nginx='sudo systemctl restart nginx'" >> ~/.bashrc | ||
|
||
echo "alias test-socket='curl --unix-socket $PROJECT_DIR/run/gunicorn.sock localhost'" >> ~/.bashrc | ||
echo "alias status-supervisor='sudo supervisorctl status'" >> ~/.bashrc | ||
echo "alias deploy-app='cd $PROJECT_DIR/deployment && bash deploy.sh'" >> ~/.bashrc | ||
echo "alias cd-logs='cd $PROJECT_DIR/logs'" >> ~/.bashrc | ||
fi | ||
|
||
# if users says yes, create a symlink to the nginx config | ||
if confirm_action "Do you want to create a symlink to the nginx config in sites-enabled?" | ||
then | ||
# don't create a symlink if it already exists | ||
if [ -L /etc/nginx/sites-enabled/$APP_NAME ] | ||
then | ||
echo "Symlink already exists" | ||
exit 0 | ||
else | ||
echo "Creating symlink" | ||
sudo ln -s /etc/nginx/sites-available/$APP_NAME /etc/nginx/sites-enabled | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
NAME=APP_NAME | ||
DIR=PROJECT_DIR | ||
APP_DIR=$DIR/PROJECT_SUBDIR | ||
USER=ubuntu | ||
GROUP=ubuntu | ||
WORKERS=3 | ||
DJANGO_SETTINGS_MODULE=config.settings | ||
DJANGO_WSGI_MODULE=config.wsgi | ||
VENV=$DIR/.venv/bin/activate | ||
BIND=unix:$DIR/run/gunicorn.sock | ||
LOG_LEVEL=error | ||
TIMEOUT=300 | ||
|
||
cd $APP_DIR | ||
source $VENV | ||
|
||
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE | ||
|
||
exec gunicorn ${DJANGO_WSGI_MODULE}:application \ | ||
--name $NAME \ | ||
--workers $WORKERS \ | ||
--user=$USER \ | ||
--group=$GROUP \ | ||
--bind=$BIND \ | ||
--log-level=$LOG_LEVEL \ | ||
--log-file=- \ | ||
--timeout $TIMEOUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[program:APP_NAME] | ||
command=PROJECT_DIR/bin/gunicorn_start | ||
user=ubuntu | ||
autostart=true | ||
autorestart=true | ||
redirect_stderr=true | ||
stdout_logfile=PROJECT_DIR/logs/gunicorn-error.log |
Oops, something went wrong.