From: Guillaume Pellerin Date: Tue, 6 Mar 2018 13:53:09 +0000 (+0100) Subject: Reorder all scripts and refactor some X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=6939a0bdf1b7b9d3c1d199d170140f88cdaffd5a;p=docker-django-scripts.git Reorder all scripts and refactor some --- diff --git a/.gitmodules b/.gitmodules index 02f3962..4ee2e00 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "docker-composition-installer"] - path = docker-composition-installer + path = install url = git@github.com:yomguy/docker-composition-installer.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..1e0ca6a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# diff --git a/backup_db.sh b/backup_db.sh deleted file mode 100755 index 349c1a4..0000000 --- a/backup_db.sh +++ /dev/null @@ -1,3 +0,0 @@ - #!/bin/sh - - docker-compose run db /srv/bin/db/backup.sh diff --git a/build/doc.sh b/build/doc.sh new file mode 100755 index 0000000..abc248d --- /dev/null +++ b/build/doc.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app bash /srv/doc/build.sh diff --git a/build/front.sh b/build/front.sh new file mode 100755 index 0000000..8732c34 --- /dev/null +++ b/build/front.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app python /srv/app/manage.py build-front diff --git a/build/graph.sh b/build/graph.sh new file mode 100755 index 0000000..b5cda09 --- /dev/null +++ b/build/graph.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app python /srv/app/manage.py graph_models organization-core organization-media organization-pages organization.network organization.magazine organization.projects organization.agenda organization.shop organization.job > /srv/doc/graph/mezzanine-organization.dot diff --git a/build/local/messages.sh b/build/local/messages.sh new file mode 100755 index 0000000..0d0c263 --- /dev/null +++ b/build/local/messages.sh @@ -0,0 +1,9 @@ +# docker-compose run app python manage.py compilemessages +cd /srv + +find $(pwd) -type d -name 'locale' -print | while read f; do + cd "$f" && cd .. + echo $(pwd) + django-admin makemessages -l fr + django-admin compilemessages +done diff --git a/build/messages.sh b/build/messages.sh new file mode 100755 index 0000000..cea64ee --- /dev/null +++ b/build/messages.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app bash /srv/bin/build/local/messages.sh diff --git a/build/readme.sh b/build/readme.sh new file mode 100755 index 0000000..b73a032 --- /dev/null +++ b/build/readme.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cat doc/src/overview.rst doc/src/architecture.rst doc/src/install.rst doc/src/development.rst doc/src/maintenance.rst doc/src/copyright.rst doc/src/license.rst > README.rst +echo "Build finished. The README.rst file is up to date." diff --git a/build/setup_lib.sh b/build/setup_lib.sh new file mode 100755 index 0000000..87bd14e --- /dev/null +++ b/build/setup_lib.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +ls /srv/lib/ +for module in `ls /srv/lib/`; do + cd /srv/lib/$module + if [ -f 'requirements.txt' ]; then + pip install -r requirements.txt + else + python setup.py develop + fi +done diff --git a/build_doc.sh b/build_doc.sh deleted file mode 100755 index abc248d..0000000 --- a/build_doc.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose run app bash /srv/doc/build.sh diff --git a/build_front.sh b/build_front.sh deleted file mode 100755 index ecf7be0..0000000 --- a/build_front.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -docker-compose run app python /srv/app/manage.py build-front -docker-compose run app python /srv/app/manage.py collectstatic --no-input diff --git a/build_graph.sh b/build_graph.sh deleted file mode 100755 index b5cda09..0000000 --- a/build_graph.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose run app python /srv/app/manage.py graph_models organization-core organization-media organization-pages organization.network organization.magazine organization.projects organization.agenda organization.shop organization.job > /srv/doc/graph/mezzanine-organization.dot diff --git a/build_messages.sh b/build_messages.sh deleted file mode 100755 index c47133b..0000000 --- a/build_messages.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose run app bash /srv/bin/translations/messages.sh diff --git a/build_readme.sh b/build_readme.sh deleted file mode 100755 index b73a032..0000000 --- a/build_readme.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -cat doc/src/overview.rst doc/src/architecture.rst doc/src/install.rst doc/src/development.rst doc/src/maintenance.rst doc/src/copyright.rst doc/src/license.rst > README.rst -echo "Build finished. The README.rst file is up to date." diff --git a/collectstatic.sh b/collectstatic.sh deleted file mode 100755 index 611b171..0000000 --- a/collectstatic.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose run app python /srv/app/manage.py collectstatic --no-input diff --git a/db/backup.sh b/db/backup.sh deleted file mode 100755 index 4fa4811..0000000 --- a/db/backup.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# dump postgres or mysql functions of the database -# export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" -# export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" - -if [ ! -z "$MYSQL_PASSWORD" ]; then - export MYSQL_PWD=$MYSQL_PASSWORD - mysqldump $MYSQL_DATABASE -hdb -u$MYSQL_USER | gzip > /srv/backup/mariadb.dump.gz -elif [ ! -z "$POSTGRES_PASSWORD" ]; then - export PGPASSWORD=$POSTGRES_PASSWORD - pg_dump -Fc -hdb -Upostgres -dpostgres > /srv/backup/postgres.dump -fi - -echo "Backup done!" diff --git a/db/restore.sh b/db/restore.sh deleted file mode 100755 index 73fd180..0000000 --- a/db/restore.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# import dump functions of the database (postgres or mysql) -# export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" -# export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" - -if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then - export MYSQL_PWD=$MYSQL_ROOT_PASSWORD - gunzip < /srv/backup/mariadb.dump.gz | mysql -h db $MYSQL_DATABASE -uroot -elif [ ! -z "$POSTGRES_PASSWORD" ]; then - export PGPASSWORD=$POSTGRES_PASSWORD - pg_restore -c -hdb -Upostgres -dpostgres /srv/backup/postgres.dump -fi - -echo "Restore done!" diff --git a/dev/local/restore_db.sh b/dev/local/restore_db.sh new file mode 100755 index 0000000..73fd180 --- /dev/null +++ b/dev/local/restore_db.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# import dump functions of the database (postgres or mysql) +# export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" +# export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" + +if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then + export MYSQL_PWD=$MYSQL_ROOT_PASSWORD + gunzip < /srv/backup/mariadb.dump.gz | mysql -h db $MYSQL_DATABASE -uroot +elif [ ! -z "$POSTGRES_PASSWORD" ]; then + export PGPASSWORD=$POSTGRES_PASSWORD + pg_restore -c -hdb -Upostgres -dpostgres /srv/backup/postgres.dump +fi + +echo "Restore done!" diff --git a/dev/makemigrations.sh b/dev/makemigrations.sh new file mode 100755 index 0000000..d359a6f --- /dev/null +++ b/dev/makemigrations.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app python /srv/app/manage.py makemigrations -v 3 $1 diff --git a/dev/migrate.sh b/dev/migrate.sh new file mode 100755 index 0000000..98ad441 --- /dev/null +++ b/dev/migrate.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app python /srv/app/manage.py migrate -v 3 diff --git a/dev/pull.sh b/dev/pull.sh new file mode 100755 index 0000000..de0b001 --- /dev/null +++ b/dev/pull.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../../ + +# We need to chown folders as they are docker's volumes +sudo chown -R $USER var/media +sudo chown -R $USER var/backup + +# Update main project +git pull + +# Update submodules +./bin/dev/update_submodules.sh + +# Restore database +if [ "$1" = "--restore-db" ]; then + docker-compose run db /srv/bin/dev/restore_db.sh +fi + +# We need to chown folders as they are docker's volumes +sudo chown -R www-data var/media +sudo chown -R root var/backup diff --git a/dev/restore_db.sh b/dev/restore_db.sh new file mode 100755 index 0000000..8b9e895 --- /dev/null +++ b/dev/restore_db.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run db /srv/bin/db/restore.sh diff --git a/dev/up.sh b/dev/up.sh new file mode 100755 index 0000000..6263e27 --- /dev/null +++ b/dev/up.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose -f docker-compose.yml -f env/dev.yml up diff --git a/dev/update_submodules.sh b/dev/update_submodules.sh new file mode 100755 index 0000000..fbd4bd4 --- /dev/null +++ b/dev/update_submodules.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# The script detect the right main project branch, then update the submodule function of branch-[mainProjectBranch] +# For example, if you define these variables in .gitmodules : +# - branch-dev +# - branch-master +# If you are on dev branch in main project, the script will update submodule functions of branch-dev you've defined +# In main project, if you are in another branch than master or dev, it will take by default dev branch +# If you don't define any branches for you submodule, the script will update from master + +curr_branch=$(git symbolic-ref --short HEAD) + +echo $curr_branch +if [ $curr_branch != "master" ] && [ $curr_branch != "dev" ]; +then + curr_branch="dev" +fi + +function update_git_urls { + find ./ -type f \( -name ".gitmodules" -o -name "config" \) -exec sed -i $REGEX {} + +} + +REGEX='s/https:\/\/github.com\//git@github.com:/g' +update_git_urls + +# checkout new submodule +git submodule update --init +# Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules +git submodule sync +# Checkout all submodules on right branches specified in .gitmodules, by default the branch is master +git submodule foreach --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch-'$curr_branch' || echo master)' +# Pull all submodules on right branches specified in .gitmodules, by default the branch is master +git submodule foreach --recursive 'git pull origin $(git config -f $toplevel/.gitmodules submodule.$name.branch-'$curr_branch' || echo master)' diff --git a/docker-build.sh b/docker-build.sh deleted file mode 100755 index 957956b..0000000 --- a/docker-build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -# Always remove intermediate containers and build app in dev mode -docker-compose -f docker-compose.yml -f env/dev.yml build --force-rm --no-cache -# Delete all stopped containers (including data-only containers) -docker rm $(docker ps -a -q) -# Delete all 'untagged/dangling' () images -docker rmi $(docker images -q -f dangling=true) -# restart app container -docker-compose restart app diff --git a/docker-composition-installer b/docker-composition-installer deleted file mode 160000 index 12cfb2a..0000000 --- a/docker-composition-installer +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 12cfb2a1887d3a927e7f50a37945d20c5a89d70b diff --git a/docker-dev.sh b/docker-dev.sh deleted file mode 100755 index 6263e27..0000000 --- a/docker-dev.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose -f docker-compose.yml -f env/dev.yml up diff --git a/docker-prod.sh b/docker-prod.sh deleted file mode 100755 index 644c207..0000000 --- a/docker-prod.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose -f docker-compose.yml -f env/prod.yml up diff --git a/docker/build_image.sh b/docker/build_image.sh new file mode 100755 index 0000000..957956b --- /dev/null +++ b/docker/build_image.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Always remove intermediate containers and build app in dev mode +docker-compose -f docker-compose.yml -f env/dev.yml build --force-rm --no-cache +# Delete all stopped containers (including data-only containers) +docker rm $(docker ps -a -q) +# Delete all 'untagged/dangling' () images +docker rmi $(docker images -q -f dangling=true) +# restart app container +docker-compose restart app diff --git a/docker/pf_osx.sh b/docker/pf_osx.sh new file mode 100755 index 0000000..0d81e91 --- /dev/null +++ b/docker/pf_osx.sh @@ -0,0 +1,133 @@ +#!/bin/bash + +readonly PROGNAME=$(basename $0) + +port="${1}" +foreground="false" +stop="false" +environment="default" +quite="false" +hostport="$1" + +usage="${PROGNAME} [-h] [-s] [-f] [-e] [-hp] -- Forwards a docker-machine port so that you can access it locally + +where: + -h, --help Show this help text + -s, --stop Stop the port forwarding process + -f, --foreground Run the docker-machine ssh client in foreground instead of background + -e, --environment The name of the docker-machine environment (default is default) + -q, --quite Don't print anything to the console, not even errors + +examples: + # Port forward port 8047 in docker-machine environment default + \$ ${PROGNAME} 8047 + + # Port forward docker port 8047 to host port 8087 in docker-machine environment default + \$ ${PROGNAME} 8087:8047 + + # Port forward port 8047 in docker-machine dev + \$ ${PROGNAME} 8047 -e dev + + # Runs in foreground (port forwarding is automatically stopped when process is terminated) + \$ ${PROGNAME} 8047 -f + + # Stop the port forwarding for this port + \$ ${PROGNAME} 8047 -s" + +if [ $# -eq 0 ]; then + echo "$usage" + exit 1 +fi + +if [ -z "$1" ]; then + echo "You need to specify the port to forward" >&2 + echo "$usage" + exit 1 +fi + +if [ "$#" -ne 0 ]; then + while [ "$#" -gt 0 ] + do + case "$1" in + -h|--help) + echo "$usage" + exit 0 + ;; + -f|--foreground) + foreground="true" + ;; + -s|--stop) + stop="true" + ;; + -e|--environment) + environment="$2" + ;; + -q|--quite) + quite="true" + ;; + --) + break + ;; + -*) + echo "Invalid option '$1'. Use --help to see the valid options" >&2 + exit 1 + ;; + # an option argument, continue + *) ;; + esac + shift + done +fi + +pidport() { + lsof -n -i4TCP:$1 | grep --exclude-dir={.bzr,CVS,.git,.hg,.svn} LISTEN +} + +# Check if port contains ":", if so we should split +if [[ $port == *":"* ]]; then + # Split by : + ports=(${port//:/ }) + if [[ ${#ports[@]} != 2 ]]; then + if [[ $quite == "false" ]]; then + echo "Port forwarding should be defined as hostport:targetport, for example: 8090:8080" + fi + exit 1 + fi + + + hostport=${ports[0]} + port=${ports[1]} +fi + + +if [[ ${stop} == "true" ]]; then + result=`pidport $hostport` + + if [ -z "${result}" ]; then + if [[ $quite == "false" ]]; then + echo "Port $hostport is not forwarded, cannot stop" + fi + exit 1 + fi + + process=`echo "${result}" | awk '{ print $1 }'` + if [[ $process != "ssh" ]]; then + if [[ $quite == "false" ]]; then + echo "Port $hostport is bound by process ${process} and not by docker-machine, won't stop" + fi + exit 1 + fi + + pid=`echo "${result}" | awk '{ print $2 }'` && + kill $pid && + echo "Stopped port forwarding for $hostport" +else + docker-machine ssh $environment `if [[ ${foreground} == "false" ]]; then echo "-f -N"; fi` -L $hostport:localhost:$port && + if [[ $quite == "false" ]] && [[ $foreground == "false" ]]; then + printf "Forwarding port $port" + if [[ $hostport -ne $port ]]; then + printf " to host port $hostport" + fi + echo " in docker-machine environment $environment." + fi +fi diff --git a/fix/fs_migrate.sh b/fix/fs_migrate.sh deleted file mode 100755 index 9ec9fcf..0000000 --- a/fix/fs_migrate.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -docker-compose stop -mv data var -mkdir var/lib -sudo mv var/postgresql var/lib -sudo mv var/external var/opt -sudo mv var/var/log var -sudo rm -rf var/var diff --git a/install b/install new file mode 160000 index 0000000..12cfb2a --- /dev/null +++ b/install @@ -0,0 +1 @@ +Subproject commit 12cfb2a1887d3a927e7f50a37945d20c5a89d70b diff --git a/makemigrations.sh b/makemigrations.sh deleted file mode 100755 index d359a6f..0000000 --- a/makemigrations.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose run app python /srv/app/manage.py makemigrations -v 3 $1 diff --git a/mezzo-push.sh b/mezzo-push.sh deleted file mode 100755 index 7a5d2a3..0000000 --- a/mezzo-push.sh +++ /dev/null @@ -1,7 +0,0 @@ -echo "----------------------------" -echo `date +\%Y\%m\%d-\%H-\%M-\%S` -docker-compose run db /srv/bin/db/backup.sh -git add var -git commit -a -m "update DB and media" -git pull -git push diff --git a/migrate.sh b/migrate.sh deleted file mode 100755 index 98ad441..0000000 --- a/migrate.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose run app python /srv/app/manage.py migrate -v 3 diff --git a/misc/fix/fs_migrate.sh b/misc/fix/fs_migrate.sh new file mode 100755 index 0000000..9ec9fcf --- /dev/null +++ b/misc/fix/fs_migrate.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +docker-compose stop +mv data var +mkdir var/lib +sudo mv var/postgresql var/lib +sudo mv var/external var/opt +sudo mv var/var/log var +sudo rm -rf var/var diff --git a/misc/poll_twitter.sh b/misc/poll_twitter.sh new file mode 100755 index 0000000..ab01c9f --- /dev/null +++ b/misc/poll_twitter.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose exec app python /srv/app/manage.py poll_twitter --force diff --git a/pf_osx.sh b/pf_osx.sh deleted file mode 100755 index 0d81e91..0000000 --- a/pf_osx.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/bin/bash - -readonly PROGNAME=$(basename $0) - -port="${1}" -foreground="false" -stop="false" -environment="default" -quite="false" -hostport="$1" - -usage="${PROGNAME} [-h] [-s] [-f] [-e] [-hp] -- Forwards a docker-machine port so that you can access it locally - -where: - -h, --help Show this help text - -s, --stop Stop the port forwarding process - -f, --foreground Run the docker-machine ssh client in foreground instead of background - -e, --environment The name of the docker-machine environment (default is default) - -q, --quite Don't print anything to the console, not even errors - -examples: - # Port forward port 8047 in docker-machine environment default - \$ ${PROGNAME} 8047 - - # Port forward docker port 8047 to host port 8087 in docker-machine environment default - \$ ${PROGNAME} 8087:8047 - - # Port forward port 8047 in docker-machine dev - \$ ${PROGNAME} 8047 -e dev - - # Runs in foreground (port forwarding is automatically stopped when process is terminated) - \$ ${PROGNAME} 8047 -f - - # Stop the port forwarding for this port - \$ ${PROGNAME} 8047 -s" - -if [ $# -eq 0 ]; then - echo "$usage" - exit 1 -fi - -if [ -z "$1" ]; then - echo "You need to specify the port to forward" >&2 - echo "$usage" - exit 1 -fi - -if [ "$#" -ne 0 ]; then - while [ "$#" -gt 0 ] - do - case "$1" in - -h|--help) - echo "$usage" - exit 0 - ;; - -f|--foreground) - foreground="true" - ;; - -s|--stop) - stop="true" - ;; - -e|--environment) - environment="$2" - ;; - -q|--quite) - quite="true" - ;; - --) - break - ;; - -*) - echo "Invalid option '$1'. Use --help to see the valid options" >&2 - exit 1 - ;; - # an option argument, continue - *) ;; - esac - shift - done -fi - -pidport() { - lsof -n -i4TCP:$1 | grep --exclude-dir={.bzr,CVS,.git,.hg,.svn} LISTEN -} - -# Check if port contains ":", if so we should split -if [[ $port == *":"* ]]; then - # Split by : - ports=(${port//:/ }) - if [[ ${#ports[@]} != 2 ]]; then - if [[ $quite == "false" ]]; then - echo "Port forwarding should be defined as hostport:targetport, for example: 8090:8080" - fi - exit 1 - fi - - - hostport=${ports[0]} - port=${ports[1]} -fi - - -if [[ ${stop} == "true" ]]; then - result=`pidport $hostport` - - if [ -z "${result}" ]; then - if [[ $quite == "false" ]]; then - echo "Port $hostport is not forwarded, cannot stop" - fi - exit 1 - fi - - process=`echo "${result}" | awk '{ print $1 }'` - if [[ $process != "ssh" ]]; then - if [[ $quite == "false" ]]; then - echo "Port $hostport is bound by process ${process} and not by docker-machine, won't stop" - fi - exit 1 - fi - - pid=`echo "${result}" | awk '{ print $2 }'` && - kill $pid && - echo "Stopped port forwarding for $hostport" -else - docker-machine ssh $environment `if [[ ${foreground} == "false" ]]; then echo "-f -N"; fi` -L $hostport:localhost:$port && - if [[ $quite == "false" ]] && [[ $foreground == "false" ]]; then - printf "Forwarding port $port" - if [[ $hostport -ne $port ]]; then - printf " to host port $hostport" - fi - echo " in docker-machine environment $environment." - fi -fi diff --git a/poll_twitter.sh b/poll_twitter.sh deleted file mode 100755 index ab01c9f..0000000 --- a/poll_twitter.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose exec app python /srv/app/manage.py poll_twitter --force diff --git a/prod/backup_db.sh b/prod/backup_db.sh new file mode 100755 index 0000000..c8d8904 --- /dev/null +++ b/prod/backup_db.sh @@ -0,0 +1,3 @@ + #!/bin/sh + + docker-compose run db /srv/bin/prod/local/backup_db.sh diff --git a/prod/collectstatic.sh b/prod/collectstatic.sh new file mode 100755 index 0000000..611b171 --- /dev/null +++ b/prod/collectstatic.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app python /srv/app/manage.py collectstatic --no-input diff --git a/prod/local/backup_db.sh b/prod/local/backup_db.sh new file mode 100755 index 0000000..4fa4811 --- /dev/null +++ b/prod/local/backup_db.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# dump postgres or mysql functions of the database +# export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" +# export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" + +if [ ! -z "$MYSQL_PASSWORD" ]; then + export MYSQL_PWD=$MYSQL_PASSWORD + mysqldump $MYSQL_DATABASE -hdb -u$MYSQL_USER | gzip > /srv/backup/mariadb.dump.gz +elif [ ! -z "$POSTGRES_PASSWORD" ]; then + export PGPASSWORD=$POSTGRES_PASSWORD + pg_dump -Fc -hdb -Upostgres -dpostgres > /srv/backup/postgres.dump +fi + +echo "Backup done!" diff --git a/prod/migrate.sh b/prod/migrate.sh new file mode 100755 index 0000000..b561bbf --- /dev/null +++ b/prod/migrate.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run app python /srv/app/manage.py migrate diff --git a/prod/push.sh b/prod/push.sh new file mode 100755 index 0000000..fc7a2eb --- /dev/null +++ b/prod/push.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "----------------------------" +echo `date +\%Y\%m\%d-\%H-\%M-\%S` +docker-compose run db /srv/bin/prod/backup_db.sh +cd var +git add . +git commit -a -m "update DB and media" +git pull +git push diff --git a/prod/up.sh b/prod/up.sh new file mode 100755 index 0000000..644c207 --- /dev/null +++ b/prod/up.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose -f docker-compose.yml -f env/prod.yml up diff --git a/prod/update_submodules.sh b/prod/update_submodules.sh new file mode 100755 index 0000000..fb27679 --- /dev/null +++ b/prod/update_submodules.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# The script detect the right main project branch, then update the submodule function of branch-[mainProjectBranch] +# For example, if you define these variables in .gitmodules : +# - branch-dev +# - branch-master +# If you are on dev branch in main project, the script will update submodule functions of branch-dev you've defined +# In main project, if you are in another branch than master or dev, it will take by default dev branch +# If you don't define any branches for you submodule, the script will update from master + +curr_branch=$(git symbolic-ref --short HEAD) + +echo $curr_branch +if [ $curr_branch != "master" ] && [ $curr_branch != "dev" ]; +then + curr_branch="dev" +fi + +function update_git_urls { + find ./ -type f \( -name ".gitmodules" -o -name "config" \) -exec sed -i $REGEX {} + +} + +REGEX='s/git@github.com:/https:\/\/github.com\//g' +update_git_urls + +# checkout new submodule +git submodule update --init +# Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules +git submodule sync +# Checkout all submodules on right branches specified in .gitmodules, by default the branch is master +git submodule foreach --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch-'$curr_branch' || echo master)' +# Pull all submodules on right branches specified in .gitmodules, by default the branch is master +git submodule foreach --recursive 'git pull origin $(git config -f $toplevel/.gitmodules submodule.$name.branch-'$curr_branch' || echo master)' diff --git a/prod/upgrade.sh b/prod/upgrade.sh new file mode 100755 index 0000000..43f8591 --- /dev/null +++ b/prod/upgrade.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +cd "$(dirname "$0")"/../../ + +# Update main project +git pull + +# Update submodules +./bin/update_submodules.sh + +# Apply migrations +if [ "$1" = "--migrate" ]; then + docker-compose run app python /srv/app/manage.py migrate +fi + +# Build front-end +if [ "$1" = "--front" ]; then + docker-compose run app python /srv/app/manage.py build-front +fi + +# Build documentation +if [ "$1" = "--doc" ]; then + docker-compose run app bash /srv/doc/build.sh +fi + +# Collect static files +if [ "$1" = "--collect" ]; then + docker-compose run app python manage.py collectstatic --noinput +fi + +# Reload Wsgi +if [ "$1" = "--reload" ]; then + touch app/wsgi.py +fi + +# Install local cron to +if [ "$1" = "--cron" ]; then + sudo cp ./etc/cron.d/* /etc/cron.d/ +fi diff --git a/pull.sh b/pull.sh deleted file mode 100755 index 7e66168..0000000 --- a/pull.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -cd "$(dirname "$0")"/../ - -# We need to chown folders as they are docker's volumes -sudo chown -R $USER var/media -sudo chown -R $USER var/backup - -# Update main project -git pull - -# Update submodules -./bin/update_submodules.sh - -# Restore database -if [ "$1" = "--restore-db" ]; then - docker-compose run db /srv/bin/db/restore.sh -fi - -# We need to chown folders as they are docker's volumes -sudo chown -R www-data var/media -sudo chown -R root var/backup diff --git a/push.sh b/push.sh deleted file mode 100755 index 198e2d5..0000000 --- a/push.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -echo "----------------------------" -echo `date +\%Y\%m\%d-\%H-\%M-\%S` -docker-compose run db /srv/bin/db/backup.sh -cd var -git add . -git commit -a -m "update DB and media" -git pull -git push diff --git a/restore_db.sh b/restore_db.sh deleted file mode 100755 index 8b9e895..0000000 --- a/restore_db.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -docker-compose run db /srv/bin/db/restore.sh diff --git a/setup_lib.sh b/setup_lib.sh deleted file mode 100755 index 87bd14e..0000000 --- a/setup_lib.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -ls /srv/lib/ -for module in `ls /srv/lib/`; do - cd /srv/lib/$module - if [ -f 'requirements.txt' ]; then - pip install -r requirements.txt - else - python setup.py develop - fi -done diff --git a/tmp/mezzo-push.sh b/tmp/mezzo-push.sh new file mode 100755 index 0000000..7a5d2a3 --- /dev/null +++ b/tmp/mezzo-push.sh @@ -0,0 +1,7 @@ +echo "----------------------------" +echo `date +\%Y\%m\%d-\%H-\%M-\%S` +docker-compose run db /srv/bin/db/backup.sh +git add var +git commit -a -m "update DB and media" +git pull +git push diff --git a/tmp/update_translation_fields.sh b/tmp/update_translation_fields.sh new file mode 100755 index 0000000..66f3479 --- /dev/null +++ b/tmp/update_translation_fields.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +git submodule update --recursive --remote diff --git a/translations/messages.sh b/translations/messages.sh deleted file mode 100755 index 0d0c263..0000000 --- a/translations/messages.sh +++ /dev/null @@ -1,9 +0,0 @@ -# docker-compose run app python manage.py compilemessages -cd /srv - -find $(pwd) -type d -name 'locale' -print | while read f; do - cd "$f" && cd .. - echo $(pwd) - django-admin makemessages -l fr - django-admin compilemessages -done diff --git a/update_submodules.sh b/update_submodules.sh deleted file mode 100755 index 4a403d9..0000000 --- a/update_submodules.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# The script detect the right main project branch, then update the submodule function of branch-[mainProjectBranch] -# For example, if you define these variables in .gitmodules : -# - branch-dev -# - branch-master -# If you are on dev branch in main project, the script will update submodule functions of branch-dev you've defined -# In main project, if you are in another branch than master or dev, it will take by default dev branch -# If you don't define any branches for you submodule, the script will update from master - -curr_branch=$(git symbolic-ref --short HEAD) - -echo $curr_branch -if [ $curr_branch != "master" ] && [ $curr_branch != "dev" ]; -then - curr_branch="dev" -fi - -function update_git_urls { - find ./ -type f \( -name ".gitmodules" -o -name "config" \) -exec sed -i $REGEX {} + -} - -if [ "$1" = "--ssh" ]; then - REGEX='s/https:\/\/github.com\//git@github.com:/g' - update_git_urls -fi - -if [ "$1" = "--https" ]; then - REGEX='s/git@github.com:/https:\/\/github.com\//g' - update_git_urls -fi - -# checkout new submodule -git submodule update --init -# Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules -git submodule sync -# Checkout all submodules on right branches specified in .gitmodules, by default the branch is master -git submodule foreach --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch-'$curr_branch' || echo master)' -# Pull all submodules on right branches specified in .gitmodules, by default the branch is master -git submodule foreach --recursive 'git pull origin $(git config -f $toplevel/.gitmodules submodule.$name.branch-'$curr_branch' || echo master)' diff --git a/update_translation_fields.sh b/update_translation_fields.sh deleted file mode 100755 index 66f3479..0000000 --- a/update_translation_fields.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -git submodule update --recursive --remote diff --git a/upgrade.sh b/upgrade.sh deleted file mode 100755 index 1f1a1b2..0000000 --- a/upgrade.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -# Update main project -git pull - -# Update submodules -./bin/update_submodules.sh - -# Apply migrations -if [ "$1" = "--migrate" ]; then - docker-compose run app python /srv/app/manage.py migrate -fi - -# Build front-end -if [ "$1" = "--front" ]; then - ./bin/build_front.sh -fi - -# Build documentation -if [ "$1" = "--doc" ]; then - docker-compose run app bash /srv/doc/build.sh -fi - -# Collect static files -if [ "$1" = "--collect" ]; then - docker-compose run app python manage.py collectstatic --noinput -fi - -# Reload Wsgi -if [ "$1" = "--reload" ]; then - touch app/wsgi.py -fi - -# Install local cron to -if [ "$1" = "--cron" ]; then - sudo cp ./etc/cron.d/* /etc/cron.d/ -fi