Skip to content

Commit e541d6b

Browse files
committed
added yaml configuration
1 parent 5b291e7 commit e541d6b

File tree

5 files changed

+81
-57
lines changed

5 files changed

+81
-57
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
adloa/
2+
notes.txt
3+
.idea/

app_deploy.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,31 @@
88
import deploylib
99
import datetime
1010
import optparse
11+
import yaml
12+
13+
with open('config.yaml') as file:
14+
config = yaml.safe_load(file)
1115

1216
# settings
13-
TEST = False
14-
repo = 'git@bitbucket.org:yourgituseraccount/reponame.git'
15-
project_name = 'reponame'
16-
keep_releases = 5
17-
shared_dirs = ['storage']
18-
shared_files = ['.env']
19-
link_storage_public = True
20-
writable_dirs = []
21-
writable_use_sudo = False
22-
deploy_path = '/var/www'
17+
TEST = True
18+
repo = config['repo']['source']
19+
project_name = config['repo']['name']
20+
keep_releases = config['keep-releases']
21+
shared_dirs = config['shared-directories']
22+
shared_files = config['shared-files']
23+
link_storage_public = config['link_storage_public']
24+
writable_dirs = config['writable_dirs']
25+
writable_use_sudo = config['writable_use_sudo']
26+
deploy_path = config['deploy_directory_path']
2327
cwd = os.getcwd()
2428

25-
2629
# deploylib.cleanup_releases(cwd, keep_releases)
2730
parser = optparse.OptionParser("App Deploy")
2831

2932
parser.add_option('-b', '--rollback', action="store", dest="rollback", help="rollback release", default=False)
3033
parser.add_option('-v', '--releases', action="store_true", dest="releases", help="show releases", default=False)
3134
parser.add_option('-d', '--deploy', action="store_true", dest="deploy", help="deploy release", default=False)
32-
#parser.add_option('-h', '--help', action="store_true", dest="help", help="help", default=False)
35+
# parser.add_option('-h', '--help', action="store_true", dest="help", help="help", default=False)
3336

3437
options, args = parser.parse_args()
3538

@@ -103,7 +106,6 @@
103106

104107
print('New releases file created')
105108

106-
107109
if run_first_time:
108110
deploylib.create_directory(cwd, cwd + '/releases', '0')
109111
deploylib.create_directory(cwd, cwd + '/releases', '1')
@@ -118,16 +120,14 @@
118120
last_release = latest_release - 1
119121
latest_release = new_release
120122

121-
122123
deploylib.create_directory(cwd, cwd + '/releases', str(new_release))
123124
# copy to shared. shared_dirs, shared_files
124125
shared_copy_logs = deploylib.copy_to_shared(cwd, str(last_release), shared_dirs, shared_files)
125126
print(shared_copy_logs)
126127

127128
# git download code, run deploy script.
128-
deploylib.run_scripts_deploy(cwd, str(latest_release), repo, project_name, shared_dirs, shared_files, str(last_release), link_storage_public)
129+
deploylib.run_scripts_deploy(config['runtime'], cwd, str(latest_release), repo, project_name, shared_dirs, shared_files, str(last_release), link_storage_public)
129130
deploylib.cleanup_releases(cwd, keep_releases)
130131

131132
deploylib.run_command("rm -f " + cwd + "/.dep/deploy.lock")
132133
print("Deploy lock file released.")
133-

config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repo:
2+
source: "git@bitbucket.org:your-git-user-account/repo-name.git"
3+
name: "repo-name"
4+
keep-releases: 5
5+
shared-directories: ['storage']
6+
shared-files: ['.env']
7+
link_storage_public: True
8+
writable_dirs: []
9+
writable_use_sudo: False
10+
deploy_directory_path: '/var/www'
11+
runtime:
12+
install-composer-packages: True
13+
install-npm-packages: True
14+
laravel-clear-caches: True
15+
laravel-queue-restart: True
16+
laravel-config-clear: True

deploylib.py

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,22 @@ def copy_to_shared(cwd, release, shared_dirs, shared_files):
7878

7979

8080
# DONT USE!! - todo remove
81-
def remove_resources_from_release(cwd, release, shared_dirs, shared_files):
82-
# for directory in shared_dirs:
83-
# dir_src = cwd + '/releases/' + release + '/' + directory
84-
# if os.path.isdir(dir_src):
85-
# # clear_folder(dir_src)
86-
# run_command("rm -f " + dir_src)
87-
# else:
88-
# print("Directory does not exist to remove: {}".format(dir_src))
89-
90-
for shared_file in shared_files:
91-
file_src = cwd + '/releases/' + release + '/' + shared_file
92-
if os.path.isfile(file_src):
93-
run_command("rm -f " + file_src)
94-
# os.remove(file_src)
95-
else:
96-
print("File does not exist to remove: {}".format(file_src))
81+
# def remove_resources_from_release(cwd, release, shared_dirs, shared_files):
82+
# # for directory in shared_dirs:
83+
# # dir_src = cwd + '/releases/' + release + '/' + directory
84+
# # if os.path.isdir(dir_src):
85+
# # # clear_folder(dir_src)
86+
# # run_command("rm -f " + dir_src)
87+
# # else:
88+
# # print("Directory does not exist to remove: {}".format(dir_src))
89+
#
90+
# for shared_file in shared_files:
91+
# file_src = cwd + '/releases/' + release + '/' + shared_file
92+
# if os.path.isfile(file_src):
93+
# run_command("rm -f " + file_src)
94+
# # os.remove(file_src)
95+
# else:
96+
# print("File does not exist to remove: {}".format(file_src))
9797

9898

9999
def run_command(my_commands):
@@ -111,27 +111,36 @@ def run_deploy_check(cwd, new_release):
111111
pass
112112

113113

114-
def run_vendors(cwd, new_release):
114+
def run_vendors(config, cwd, new_release):
115115
# Can edit this section for Laravel specific cmds
116116
os.chdir(cwd + '/releases/' + new_release)
117117
which_composer = subprocess.run("which composer", shell=True, stdout=subprocess.PIPE)
118118
composer = which_composer.stdout.decode('utf-8').rstrip()
119119
which_php = subprocess.run("which php", shell=True, stdout=subprocess.PIPE)
120120
php = which_php.stdout.decode('utf-8').rstrip()
121-
# Install Composer libs
122-
print("Install Composer Libs")
123-
run_command(composer + " install --optimize-autoloader")
124-
# Install NPM
125-
print("Install NPM Libs")
126-
run_command("npm install")
127-
run_command("npm run production")
128-
# Update Laravel
129-
print("Update Laravel")
130-
run_command(php + " artisan cache:clear")
131-
run_command(php + " artisan route:cache")
132-
run_command(php + " artisan config:cache")
133-
run_command(php + " artisan view:clear")
134-
run_command(php + " artisan queue:restart")
121+
122+
if config['install-composer-packages']:
123+
# Install Composer libs
124+
print("Install Composer Libs")
125+
run_command(composer + " install --optimize-autoloader")
126+
127+
if config['install-npm-packages']:
128+
# Install NPM
129+
print("Install NPM Libs")
130+
run_command("npm install")
131+
run_command("npm run production")
132+
133+
if config['laravel-clear-caches']:
134+
# Laravel cache, view, route, cache reset
135+
print("Laravel cache, view, route, cache reset")
136+
run_command(php + " artisan cache:clear")
137+
run_command(php + " artisan view:clear")
138+
run_command(php + " artisan route:cache")
139+
run_command(php + " artisan config:cache")
140+
141+
if config['laravel-clear-caches']:
142+
run_command(php + " artisan queue:restart")
143+
135144
os.chdir(cwd)
136145

137146

@@ -170,16 +179,11 @@ def run_symlinks(cwd, new_release):
170179
print("Deploy is live!")
171180

172181

173-
def run_post_deploy(cwd, new_release):
174-
current_release_dir = cwd + "/releases/" + new_release
175-
os.chdir(cwd + "/current")
176-
run_command("php artisan config:clear")
177-
os.chdir(cwd)
178-
# run_command("sudo chown -R $USER:www-data shared")
179-
# run_command("chmod -R 775 shared/storage")
182+
# def run_post_deploy(cwd, new_release):
183+
# run post deploy scripts here
180184

181185

182-
def run_scripts_deploy(cwd, new_release, repo, project_name, shared_dirs, shared_files, last_release,
186+
def run_scripts_deploy(config, cwd, new_release, repo, project_name, shared_dirs, shared_files, last_release,
183187
link_storage_public):
184188
which_git = subprocess.run("which git", shell=True, stdout=subprocess.PIPE)
185189
git = which_git.stdout.decode('utf-8').rstrip()
@@ -198,11 +202,11 @@ def run_scripts_deploy(cwd, new_release, repo, project_name, shared_dirs, shared
198202
#run_command("chown -R youruser:www-data " + cwd + '/releases/' + str(new_release))
199203
run_command("rm -rf " + storage_dir_src)
200204

201-
run_vendors(cwd, new_release)
205+
run_vendors(config, cwd, new_release)
202206
run_deploy_check(cwd, new_release)
203207
symlink_project_resources(cwd, shared_dirs, shared_files, new_release, link_storage_public)
204208
run_symlinks(cwd, new_release)
205-
run_post_deploy(cwd, new_release)
209+
# run_post_deploy(cwd, new_release)
206210

207211

208212
def get_all_versions(cwd):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyYAML==6.0.2

0 commit comments

Comments
 (0)