From 6939a0bdf1b7b9d3c1d199d170140f88cdaffd5a Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Tue, 6 Mar 2018 14:53:09 +0100 Subject: [PATCH] Reorder all scripts and refactor some --- .gitmodules | 2 +- README.md | 1 + backup_db.sh | 3 -- build_doc.sh => build/doc.sh | 0 build/front.sh | 3 ++ build_graph.sh => build/graph.sh | 0 {translations => build/local}/messages.sh | 0 build/messages.sh | 3 ++ build_readme.sh => build/readme.sh | 0 setup_lib.sh => build/setup_lib.sh | 0 build_front.sh | 4 --- build_messages.sh | 3 -- db/restore.sh => dev/local/restore_db.sh | 0 makemigrations.sh => dev/makemigrations.sh | 0 migrate.sh => dev/migrate.sh | 0 pull.sh => dev/pull.sh | 6 ++-- restore_db.sh => dev/restore_db.sh | 0 docker-dev.sh => dev/up.sh | 0 .../update_submodules.sh | 11 ++----- docker-build.sh => docker/build_image.sh | 0 pf_osx.sh => docker/pf_osx.sh | 0 docker-composition-installer => install | 0 {fix => misc/fix}/fs_migrate.sh | 0 poll_twitter.sh => misc/poll_twitter.sh | 0 prod/backup_db.sh | 3 ++ collectstatic.sh => prod/collectstatic.sh | 0 db/backup.sh => prod/local/backup_db.sh | 0 prod/migrate.sh | 3 ++ push.sh => prod/push.sh | 2 +- docker-prod.sh => prod/up.sh | 0 prod/update_submodules.sh | 33 +++++++++++++++++++ upgrade.sh => prod/upgrade.sh | 4 ++- mezzo-push.sh => tmp/mezzo-push.sh | 0 .../update_translation_fields.sh | 0 34 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 README.md delete mode 100755 backup_db.sh rename build_doc.sh => build/doc.sh (100%) create mode 100755 build/front.sh rename build_graph.sh => build/graph.sh (100%) rename {translations => build/local}/messages.sh (100%) create mode 100755 build/messages.sh rename build_readme.sh => build/readme.sh (100%) rename setup_lib.sh => build/setup_lib.sh (100%) delete mode 100755 build_front.sh delete mode 100755 build_messages.sh rename db/restore.sh => dev/local/restore_db.sh (100%) rename makemigrations.sh => dev/makemigrations.sh (100%) rename migrate.sh => dev/migrate.sh (100%) rename pull.sh => dev/pull.sh (76%) rename restore_db.sh => dev/restore_db.sh (100%) rename docker-dev.sh => dev/up.sh (100%) rename update_submodules.sh => dev/update_submodules.sh (87%) rename docker-build.sh => docker/build_image.sh (100%) rename pf_osx.sh => docker/pf_osx.sh (100%) rename docker-composition-installer => install (100%) rename {fix => misc/fix}/fs_migrate.sh (100%) rename poll_twitter.sh => misc/poll_twitter.sh (100%) create mode 100755 prod/backup_db.sh rename collectstatic.sh => prod/collectstatic.sh (100%) rename db/backup.sh => prod/local/backup_db.sh (100%) create mode 100755 prod/migrate.sh rename push.sh => prod/push.sh (76%) rename docker-prod.sh => prod/up.sh (100%) create mode 100755 prod/update_submodules.sh rename upgrade.sh => prod/upgrade.sh (87%) rename mezzo-push.sh => tmp/mezzo-push.sh (100%) rename update_translation_fields.sh => tmp/update_translation_fields.sh (100%) 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 similarity index 100% rename from build_doc.sh rename to build/doc.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 similarity index 100% rename from build_graph.sh rename to build/graph.sh diff --git a/translations/messages.sh b/build/local/messages.sh similarity index 100% rename from translations/messages.sh rename to build/local/messages.sh 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 similarity index 100% rename from build_readme.sh rename to build/readme.sh diff --git a/setup_lib.sh b/build/setup_lib.sh similarity index 100% rename from setup_lib.sh rename to build/setup_lib.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_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/db/restore.sh b/dev/local/restore_db.sh similarity index 100% rename from db/restore.sh rename to dev/local/restore_db.sh diff --git a/makemigrations.sh b/dev/makemigrations.sh similarity index 100% rename from makemigrations.sh rename to dev/makemigrations.sh diff --git a/migrate.sh b/dev/migrate.sh similarity index 100% rename from migrate.sh rename to dev/migrate.sh diff --git a/pull.sh b/dev/pull.sh similarity index 76% rename from pull.sh rename to dev/pull.sh index 7e66168..de0b001 100755 --- a/pull.sh +++ b/dev/pull.sh @@ -1,6 +1,6 @@ #!/bin/bash -cd "$(dirname "$0")"/../ +cd "$(dirname "$0")"/../../ # We need to chown folders as they are docker's volumes sudo chown -R $USER var/media @@ -10,11 +10,11 @@ sudo chown -R $USER var/backup git pull # Update submodules -./bin/update_submodules.sh +./bin/dev/update_submodules.sh # Restore database if [ "$1" = "--restore-db" ]; then - docker-compose run db /srv/bin/db/restore.sh + docker-compose run db /srv/bin/dev/restore_db.sh fi # We need to chown folders as they are docker's volumes diff --git a/restore_db.sh b/dev/restore_db.sh similarity index 100% rename from restore_db.sh rename to dev/restore_db.sh diff --git a/docker-dev.sh b/dev/up.sh similarity index 100% rename from docker-dev.sh rename to dev/up.sh diff --git a/update_submodules.sh b/dev/update_submodules.sh similarity index 87% rename from update_submodules.sh rename to dev/update_submodules.sh index 4a403d9..fbd4bd4 100755 --- a/update_submodules.sh +++ b/dev/update_submodules.sh @@ -20,15 +20,8 @@ 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 +REGEX='s/https:\/\/github.com\//git@github.com:/g' +update_git_urls # checkout new submodule git submodule update --init diff --git a/docker-build.sh b/docker/build_image.sh similarity index 100% rename from docker-build.sh rename to docker/build_image.sh diff --git a/pf_osx.sh b/docker/pf_osx.sh similarity index 100% rename from pf_osx.sh rename to docker/pf_osx.sh diff --git a/docker-composition-installer b/install similarity index 100% rename from docker-composition-installer rename to install diff --git a/fix/fs_migrate.sh b/misc/fix/fs_migrate.sh similarity index 100% rename from fix/fs_migrate.sh rename to misc/fix/fs_migrate.sh diff --git a/poll_twitter.sh b/misc/poll_twitter.sh similarity index 100% rename from poll_twitter.sh rename to misc/poll_twitter.sh 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/collectstatic.sh b/prod/collectstatic.sh similarity index 100% rename from collectstatic.sh rename to prod/collectstatic.sh diff --git a/db/backup.sh b/prod/local/backup_db.sh similarity index 100% rename from db/backup.sh rename to prod/local/backup_db.sh 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/push.sh b/prod/push.sh similarity index 76% rename from push.sh rename to prod/push.sh index 198e2d5..fc7a2eb 100755 --- a/push.sh +++ b/prod/push.sh @@ -2,7 +2,7 @@ echo "----------------------------" echo `date +\%Y\%m\%d-\%H-\%M-\%S` -docker-compose run db /srv/bin/db/backup.sh +docker-compose run db /srv/bin/prod/backup_db.sh cd var git add . git commit -a -m "update DB and media" diff --git a/docker-prod.sh b/prod/up.sh similarity index 100% rename from docker-prod.sh rename to prod/up.sh 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/upgrade.sh b/prod/upgrade.sh similarity index 87% rename from upgrade.sh rename to prod/upgrade.sh index 1f1a1b2..43f8591 100755 --- a/upgrade.sh +++ b/prod/upgrade.sh @@ -1,5 +1,7 @@ #!/bin/bash +cd "$(dirname "$0")"/../../ + # Update main project git pull @@ -13,7 +15,7 @@ fi # Build front-end if [ "$1" = "--front" ]; then - ./bin/build_front.sh + docker-compose run app python /srv/app/manage.py build-front fi # Build documentation diff --git a/mezzo-push.sh b/tmp/mezzo-push.sh similarity index 100% rename from mezzo-push.sh rename to tmp/mezzo-push.sh diff --git a/update_translation_fields.sh b/tmp/update_translation_fields.sh similarity index 100% rename from update_translation_fields.sh rename to tmp/update_translation_fields.sh -- 2.39.5