👷 Deploy from CI using SSH
This commit is contained in:
1 parent
a2cfd0ceaf
commit
87e2f2292c
3 files changed
+17
-50
No files matched your search
+3
-1
@@ -30,4 +30,6 @@ lint:
|
|||||||
deploy:
|
deploy:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
script:
|
script:
|
||||||
- echo "TODO run the fabric script"
|
- ssh gitdeploy@dreamcast.neuf.no "$(< bin/deploy)"
|
||||||
|
only:
|
||||||
|
- main
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
PROJECT_PATH=/var/www/neuf.no/bbs
|
||||||
|
PROCESS_NAME="$PROJECT.neuf.no"
|
||||||
|
|
||||||
|
cd "$PROJECT_PATH" || exit 1
|
||||||
|
git pull
|
||||||
|
poetry install
|
||||||
|
umask 022; poetry run python manage.py collectstatic --noinput # Collect static
|
||||||
|
poetry run python manage.py migrate # Run DB migrations
|
||||||
|
|
||||||
|
# Reload
|
||||||
|
sudo /usr/bin/supervisorctl pid "$PROCESS_NAME" | xargs kill -HUP
|
||||||
Vendored
-49
@@ -1,49 +0,0 @@
|
|||||||
import os
|
|
||||||
from contextlib import contextmanager as _contextmanager
|
|
||||||
from fabric.api import run, sudo, env, cd, prefix
|
|
||||||
|
|
||||||
env.use_ssh_config = True
|
|
||||||
env.hosts = ['dreamcast.neuf.no']
|
|
||||||
env.user = 'gitdeploy'
|
|
||||||
|
|
||||||
|
|
||||||
BASE_PATH = '/var/www/neuf.no/'
|
|
||||||
|
|
||||||
PROJECTS = {
|
|
||||||
'bbs': {
|
|
||||||
'path': os.path.join(BASE_PATH, 'bbs'),
|
|
||||||
'process_name': 'bbs.neuf.no'
|
|
||||||
},
|
|
||||||
'fantastene': {
|
|
||||||
'path': os.path.join(BASE_PATH, 'bbs_fantastene'),
|
|
||||||
'process_name': 'fantastene-bbs.neuf.no'
|
|
||||||
},
|
|
||||||
'arrut': {
|
|
||||||
'path': os.path.join(BASE_PATH, 'bbs_arrut'),
|
|
||||||
'process_name': 'arrut-bbs.neuf.no'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@_contextmanager
|
|
||||||
def virtualenv(project):
|
|
||||||
activate = 'source {}/venv/bin/activate'.format(project['path'])
|
|
||||||
with cd(project['path']), prefix(activate):
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
def deploy(project_name='bbs'):
|
|
||||||
if project_name not in PROJECTS:
|
|
||||||
print("'{}' not in valid projects({})".format(project_name, ', '.join(sorted(PROJECTS.keys()))))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
project = PROJECTS[project_name]
|
|
||||||
with virtualenv(project):
|
|
||||||
run('git pull') # Get source
|
|
||||||
run('pip install -r requirements.txt') # install deps in virtualenv
|
|
||||||
run('umask 022; python manage.py collectstatic --noinput') # Collect static
|
|
||||||
run('python manage.py migrate') # Run DB migrations
|
|
||||||
|
|
||||||
# Reload
|
|
||||||
sudo('/usr/bin/supervisorctl pid {process_name} | xargs kill -HUP'.format(process_name=project['process_name']),
|
|
||||||
shell=False)
|
|
||||||
Reference in new issue
Block a user