curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs -yCan check version with:
node -vNot sure if this is necessary on production...
npm install node-sassThis requires some manual steps, I don't know how to automate some of them. Probably easiest to use a later version of Ubuntu. We don't really need 3.12.
sudo apt update
sudo apt upgrade -y
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12 python3.12-venv python3.12-dev -ymkdir venvs
python3.12 -m venv venvs/registration
source venvs/registration/bin/activateEventually should be release on pypi
wget https://github.com/Depart-de-Sentier/dds_registration/archive/refs/heads/main.zip
unzip main.zip
rm main.zip
mv dds_registration-main registration
pip install uwsgi
cd registration
pip install -e .Tomás please fix this :)
You also need to run the SASS preprocessor, which will create the static/CACHE directory. This also needs to be copied over to var/www.
npm install gulp
npm run update-assetsCreate /etc/nginx/sites-available/events.d-d-s.ch with the following content:
server {
server_name events.d-d-s.ch;
access_log /var/log/nginx/events.d-d-s.ch.access.log;
error_log /var/log/nginx/events.d-d-s.ch.error.log;
location ~ /.well-known {
allow all;
}
location /static {
alias /var/www/registration/static;
}
location / {
proxy_pass http://127.0.0.1:8076;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
}
}
sudo ln -s /etc/nginx/sites-available/events.d-d-s.ch /etc/nginx/sites-enabled/
sudo systemctl restart nginxsudo certbot --nginx -d events.d-d-s.ch --agree-tos --email cmutel@gmail.comThe registration site needs a token.json filepath specified as the environment variable in the same directory as the running script (this is how the "simple" Google OAuth system works...). Generating this file needs to be done on a system where you can use the web browser to authenticate yourself. The base "credentials.json" file was generated following the defined procedure and can be downloaded from Google Cloud.
You can generate token.json with (needs credentials.json):
from google_auth_oauthlib.flow import InstalledAppFlow
# If modifying these scopes, delete the file token.json.
SCOPES = ["https://www.googleapis.com/auth/gmail.modify"]
flow = InstalledAppFlow.from_client_secrets_file(
"credentials.json", SCOPES
)
# Opens web browser
creds = flow.run_local_server(port=0)
with open("token.json", "w") as token:
token.write(creds.to_json())Can generate secret keys via
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'
export GOOGLE_TOKEN_FILEPATH=""
export DEBUG=0
export SECRET_KEY=""
export REGISTRATION_SALT=""Initial database creation and admin user setup:
python manage.py migrate
python manage.py createsuperuserTo run as a one-off for testing (in the venv):
uwsgi --http :8076 --wsgi-file wsgi.py(run from the source directory or adjust path of wsgi.py)
Better to set up a system.d service. Create /etc/systemd/system/dds-registration.service with content:
# /etc/systemd/system/dds-registration.service
[Unit]
Description=DdS events registration
After=network.target
[Service]
Type=simple
User=registration
WorkingDirectory=/home/registration
ExecStart=/home/registration/venvs/registration/bin/uwsgi --http :8076 --wsgi-file /home/registration/registration/dds_registration/wsgi.py
Restart=always
Environment=GOOGLE_TOKEN_FILEPATH=""
Environment=DEBUG=0
Environment=SECRET_KEY=""
Environment=REGISTRATION_SALT=""
[Install]
WantedBy=multi-user.target
Get the permissions right:
sudo chmod 755 /etc/systemd/system/dds-registration.service
sudo chown root:root /etc/systemd/system/dds-registration.serviceIf this is your first time, you need to enable the service:
sudo systemctl enable dds-registrationOtherwise, if you changed the config, you need to reload the system.d config:
sudo systemctl daemon-reloadThen you can start the service:
sudo systemctl start dds-registrationYou must login to the admin portal and configure the Site or the URLs will break!