Parcourir la source

[enh] Script to create a dev env from prod env

ljf il y a 7 ans
Parent
commit
e0e5b14508
3 fichiers modifiés avec 139 ajouts et 1 suppressions
  1. 12 1
      README.md
  2. 67 0
      coin-dev
  3. 60 0
      dev_settings.py

+ 12 - 1
README.md

@@ -1,3 +1,14 @@
 # coin-extra
 
-Create a coin environnement with data from a coin_ynh setup
+Create a coin environnement with data from a coin_ynh setup
+
+```
+yunohost app install https://github.com/YunoHost-Apps/coin_ynh --debug
+cd /vagrant
+git clone https://code.ffdn.org/ARN/coin -b arnprod
+git clone https://code.ffdn.org/ARN/coin-extra
+cd coin-extra
+chmod u+x coin-dev
+scp adherents.arn-fai.net:~/dump.sql ../dump.sql
+./coin-dev -g ../coin -r
+```

+ 67 - 0
coin-dev

@@ -0,0 +1,67 @@
+#!/bin/bash
+
+set -eu
+
+COIN_DIR=/opt/coin
+NGINX_COIN_FILE=/etc/nginx/conf.d/coin.local.d/coin.conf
+
+function use_git() {
+    local COIN_GIT=$(realpath $1)
+	if [ -f "${COIN_DIR}/manage.py" ] || [ -L "${COIN_DIR}/manage.py" ]; then
+        cp ${COIN_DIR}/coin/settings_local.py ${COIN_DIR}/settings_local.py || true
+		for subpath in $(ls ${COIN_GIT}/); do 
+            rm -Rf ${COIN_DIR}/$subpath || true 
+            ln -s ${COIN_GIT}/$subpath ${COIN_DIR}/$subpath
+        done
+        cp ${COIN_DIR}/settings_local.py ${COIN_DIR}/coin/settings_local.py
+	    bash --init-file <(echo "cd ${COIN_DIR}; source venv/bin/activate; pip install -r requirements.txt; exit")
+	fi
+}
+
+function restore() {
+    # Restore db
+    if [ -f $(pwd)/../dump.sql ]; then
+		PGPASSWORD=$(grep -oP "'PASSWORD': '\K[^']+" ${COIN_DIR}/coin/settings_local.py) dropdb -Ucoin coin || true
+		sudo su -c "createdb -O coin coin" - postgres
+        PGPASSWORD=$(grep -oP "'PASSWORD': '\K[^']+" ${COIN_DIR}/coin/settings_local.py) psql -Ucoin coin < $(pwd)/../dump.sql
+	fi
+
+    # Restore settings
+    if [ -f $(pwd)/dev_settings.py ]; then
+        sed '/# START DEV SETTINGS/,$d' ${COIN_DIR}/coin/settings_local.py
+        echo '# START DEV SETTINGS' >> ${COIN_DIR}/coin/settings_local.py
+        cat $(pwd)/dev_settings.py >> ${COIN_DIR}/coin/settings_local.py
+    fi
+}
+
+function exit_usage() {
+	echo -e "usage: coin-dev [-g GIT_COIN_DIR] [-r] [-h]"
+	echo -e "Run coin in development mode"
+	echo -e ""
+	echo -e "Options:"
+	echo -e " -r Restore a db located in /opt/coin/dump.sql"
+	echo -e " -g Replace coin with the git repository "
+	echo -e " -h Display this help"
+	exit 0
+}
+
+restore=false
+while getopts "g:rh" opt; do
+  case $opt in
+    g) use_git $OPTARG ;;
+    r) restore=true ;;
+    h) exit_usage ;;
+    \?) exit_usage ;;
+  esac
+done
+
+if $restore; then
+    restore
+fi
+
+if [ -f ${COIN_DIR}/manage.py ]; then
+	sed -i "s@http://unix:${COIN_DIR}/sock@http://127.0.0.1:8000@" ${NGINX_COIN_FILE}
+    service nginx reload
+	service coin stop
+	bash --init-file <(echo "cd ${COIN_DIR}; source venv/bin/activate; python manage.py migrate; python manage.py runserver 0.0.0.0:8000")
+fi

+ 60 - 0
dev_settings.py

@@ -0,0 +1,60 @@
+ALLOWED_HOSTS = ['adherents.arn-fai.net', 'adh.arn-fai.net', 'coin.local']
+
+URL_PREFIX = ''
+SITE_URL = "https://coin.local/"
+SECRET_KEY = 'OJ1kA7Q@TF=^U*uRKj&OCHaB3'
+ISP = {
+    'NAME': 'ARN',
+    'SITE': 'https://arn-fai.net',
+    'EMAIL': 'no@arn-fai.net',
+}
+SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
+
+PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
+EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
+
+FEEDS = (('isp', 'https://arn-fai.net/rss.xml', 3),
+         ('ffdn', 'http://www.ffdn.org/fr/rss.xml', 3))
+
+
+ACCOUNT_ACTIVATION_DAYS = 7
+
+REGISTRATION_OPEN = True
+
+MEMBER_DEFAULT_COTISATION = None
+
+MEMBER_CAN_EDIT_PROFILE = True
+
+EXTRA_INSTALLED_APPS = (
+    'vpn',
+    'vps',
+    'housing',
+    'hardware_provisioning',
+)
+
+# Allow user to edit their VPS Info
+MEMBER_CAN_EDIT_VPS_CONF = False
+
+# Allow user to edit their VPN Info
+MEMBER_CAN_EDIT_VPN_CONF = False
+
+LOGGING["formatters"]["verbose"] = {'format': "%(asctime)s - %(name)s - %(levelname)s - %(message)s"}
+LOGGING["handlers"]["coin_accounting"] = {
+    'level':'INFO',
+    'class':'logging.handlers.RotatingFileHandler',
+    'formatter': 'verbose',
+    'filename': '/var/log/coin/accounting.log',
+    'maxBytes': 1024*1024*15, # 15MB
+    'backupCount': 10,
+}
+LOGGING["handlers"]["coin_subnets"] = {
+    'level':'INFO',
+    'class':'logging.handlers.RotatingFileHandler',
+    'formatter': 'verbose',
+    'filename': '/var/log/coin/subnet.log',
+    'maxBytes': 1024*1024*15, # 15MB
+    'backupCount': 10,
+}
+LOGGING["loggers"]["coin.billing"]["handlers"] = [ 'coin_accounting' ]
+LOGGING["loggers"]["coin.subnets"]["handlers"] = [ 'coin_subnets' ]
+