From 3b5d92307a4f6f17a81a18496d1194e66b0e7b3a Mon Sep 17 00:00:00 2001 From: Moreira Dos Santos Daniel Date: Fri, 22 Mar 2024 08:41:25 +0100 Subject: [PATCH] Add migrate to deployment --- api/arconnectmanager/settings.py | 1 + config/deploy.rb | 97 +++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 33 deletions(-) diff --git a/api/arconnectmanager/settings.py b/api/arconnectmanager/settings.py index f76e7bd..f0e8ebf 100644 --- a/api/arconnectmanager/settings.py +++ b/api/arconnectmanager/settings.py @@ -145,6 +145,7 @@ # https://docs.djangoproject.com/en/5.0/howto/static-files/ STATIC_URL = 'static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field diff --git a/config/deploy.rb b/config/deploy.rb index cc39e78..b331c91 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -42,52 +42,83 @@ # Uncomment the following to require manually verifying the host key before first deploy. # set :ssh_options, verify_host_key: :secure -# Créer un lien symbolique vers le fichier .env dans le répertoire current/backend -after 'deploy:symlink:release', 'deploy:create_env_symlink' namespace :deploy do - desc 'Create symlink for .env file' - task :create_env_symlink do - on roles(:app) do - execute "ln -sf #{shared_path}/.env #{release_path}/api/.env" + desc 'Create symlink for .env file' + task :create_env_symlink do + on roles(:app) do + execute "ln -sf #{shared_path}/.env #{release_path}/api/.env" + end + end + + desc 'Migrate database' + task :migrate_database do + on roles(:app) do + within release_path.join('api') do + execute :python, 'manage.py migrate' end end end - -# Installer les dépendances Python -after 'deploy:updating', 'pip:install' -namespace :pip do - desc 'Install' - task :install do - on roles([:app, :web]) do |h| - execute "pip install -r #{release_path}/api/requirements.txt" - end + desc 'Collect static files' + task :collect_static do + on roles(:app) do + within release_path.join('api') do + execute :python, 'manage.py collectstatic --noinput' + end end + end end +namespace :pip do + desc 'Install' + task :install do + on roles([:app, :web]) do |h| + execute "pip install -r #{release_path}/api/requirements.txt" + end + end +end - -# Construire et déployer l'application Vue.js -after 'deploy:updated', 'vue:deploy' namespace :vue do - desc 'Build and deploy Vue.js application' - task :deploy do - on roles(:app) do - within release_path.join('frontend') do - execute :npm, 'install' # Installer les dépendances npm - execute :npm, 'run build' # Construire l'application Vue.js - end +desc 'Build and deploy Vue.js application' +task :deploy do + on roles(:app) do + within release_path.join('frontend') do + execute :npm, 'install' # Installer les dépendances npm + execute :npm, 'run build' # Construire l'application Vue.js end end end +end -# Redémarrer le serveur Gunicorn -after 'deploy:publishing', 'gunicorn:restart' namespace :gunicorn do - desc 'Restart application' - task :restart do - on roles(:web) do |h| - execute :sudo, 'systemctl restart gunicorn' - end - end +desc 'Stop application' +task :stop do + on roles(:app) do + execute :sudo, 'systemctl stop gunicorn' + end end + +desc 'Restart application' +task :restart do + on roles(:app) do + execute :sudo, 'systemctl restart gunicorn' + end +end +end + +# Créer un lien symbolique vers le fichier .env dans le répertoire current/backend +after 'deploy:symlink:release', 'deploy:create_env_symlink' + +# Installer les dépendances Python +after 'deploy:updating', 'pip:install' + +# Construire et déployer l'application Vue.js +after 'deploy:updated', 'vue:deploy' + +# Redémarrer le serveur Gunicorn +after 'deploy:publishing', 'gunicorn:stop' +after 'gunicorn:stop', 'gunicorn:restart' + +# Après le redémarrage de Gunicorn, exécutez les migrations de la base de données et collectez les fichiers statiques +after 'gunicorn:restart', 'deploy:migrate_database' +after 'gunicorn:restart', 'deploy:collect_static' \ No newline at end of file