Skip to content

Commit

Permalink
Merge pull request #149 from seomoz/vinit-fix-commit-rebased
Browse files Browse the repository at this point in the history
Add option to skip swaparoo, fix broken swaparoo for older apps
  • Loading branch information
vmahedia authored Jun 20, 2018
2 parents 503a53d + 9b1b00a commit 992a05d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.19
0.4.20
29 changes: 17 additions & 12 deletions cli/docker_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ def packagejson_swaparoo():

# Do the swaparoo
for name, version in data['dependencies'].items():
if('git' in version or 'https' in version) and 'seomoz' in version:
print("popped {} as a private dependency".format(version))
os.system('npm install {}'.format(version))
if('git' in version or 'https' in version or 'ssh' in version) and 'seomoz' in version:
data['dependencies'].pop(name, None)
print("Installing {} as a private dependency".format(name))
os.system('npm install {}'.format(name))

# Write modified
with open('package.json', 'w+') as packagejson:
Expand All @@ -183,7 +184,7 @@ def null_swaparoo():

class Docker(object):

def docker_build(self, dockerUtilsObj, appObj, directory, repo, projects, path, image_tag, build_args, verbose_mode, docker_file='Dockerfile'):
def docker_build(self, dockerUtilsObj, appObj, directory, repo, projects, path, image_tag, build_args, verbose_mode, docker_file='Dockerfile', disable_swaparoo = False):
'''run a `docker_build -t image_tag .` in the current directory, handling any private repos'''
repo_name = appObj.getRepoName(repo)
sourcePath = "{0}/{1}/".format(directory, repo_name)
Expand All @@ -197,15 +198,19 @@ def docker_build(self, dockerUtilsObj, appObj, directory, repo, projects, path,
if path != 'none':
docker_path = sourcePath + "/{0}".format(path)
os.chdir(docker_path)

if os.path.isfile('package.json'):
swaparoo = packagejson_swaparoo
elif os.path.isfile('Gemfile'):
swaparoo = gemfile_swaparoo
# skip doing swaparoo, if explicitly asked for
if not disable_swaparoo:
if verbose_mode: print("Using swaparoo functionality")
if os.path.isfile('package.json'):
swaparoo = packagejson_swaparoo
elif os.path.isfile('Gemfile'):
swaparoo = gemfile_swaparoo
else:
swaparoo = null_swaparoo
with swaparoo():
dockerUtilsObj.docker_build(image_tag, docker_file, verbose_mode, build_args)
else:
swaparoo = null_swaparoo

with swaparoo():
if verbose_mode: print("Skipping swaparoo functionality")
dockerUtilsObj.docker_build(image_tag, docker_file, verbose_mode, build_args)

if __name__ == "__main__":
Expand Down
5 changes: 3 additions & 2 deletions cli/roger_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def parse_args(self):
self.parser.add_argument('--push', '-p', help="Also push to registry. Defaults to false.", action="store_true")
self.parser.add_argument('--build-arg', action='append',
help='docker build-arg; Use flags multiple times to pass more than one arg')
self.parser.add_argument('-ns', '--disable-swaparoo', help="Disables swaparoo functionality", action="store_true")
return self.parser

def main(self, settingObj, appObj, hooksObj, dockerUtilsObj, dockerObj, args):
Expand Down Expand Up @@ -168,14 +169,14 @@ def main(self, settingObj, appObj, hooksObj, dockerUtilsObj, dockerObj, args):
if checkout_dir == args.directory:
try:
dockerObj.docker_build(
dockerUtilsObj, appObj, args.directory, repo, projects, dockerfile_rel_repo_path, image, docker_build_args, args.verbose, build_filename)
dockerUtilsObj, appObj, args.directory, repo, projects, dockerfile_rel_repo_path, image, docker_build_args, args.verbose, build_filename, args.disable_swaparoo)
except ValueError:
raise ValueError("Docker build failed")
else:
directory = os.path.join(cur_dir, args.directory)
try:
dockerObj.docker_build(
dockerUtilsObj, appObj, directory, repo, projects, dockerfile_rel_repo_path, image, docker_build_args, args.verbose, build_filename)
dockerUtilsObj, appObj, directory, repo, projects, dockerfile_rel_repo_path, image, docker_build_args, args.verbose, build_filename, args.disable_swaparoo)
except ValueError:
print('Docker build failed.')
raise
Expand Down
1 change: 1 addition & 0 deletions cli/roger_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def parseArgs(self):
self.parser.add_argument('-sp', '--skip-push', action="store_true",
help="skip the push step. Defaults to false.'")
self.parser.add_argument('-v', '--verbose', help="verbose mode for debugging. Defaults to false.", action="store_true")
self.parser.add_argument('-ns', '--disable-swaparoo', help="Disables swaparoo functionality", action="store_true")
self.parser.add_argument('-f', '--force-push', action="store_true",
help="force push. Not recommended. Forces push even if validation checks failed. Applies only if skip_push is false. Defaults to false.")
self.parser.add_argument('-p', '--incr-patch', action="store_true",
Expand Down

0 comments on commit 992a05d

Please sign in to comment.