-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maduong/bugfix/282569 the cli should look for a compose file anywhere in the folder (not just at the root) #1183
Merged
derekbekoe
merged 15 commits into
Azure:master
from
thegalah:maduong/bugfix/282569-The-CLI-should-look-for-a-compose-file-anywhere-in-the-folder-(not-just-at-the-root)
Oct 28, 2016
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9087499
wip commit
7a7107f
Fixed url
6897136
Added helper method to get file
c33ae1c
Moved constants, minor refactor
0404596
Fixed check
90174da
Fixedpylint
9c1a09c
Refactor
61f2534
Fixed syntax error
ed07c52
Updated variable name
3bebc9d
Minor refactor
d5c9b3c
Made more descriptive variable name
a45eeb2
Fixed exception handling
b14a4ab
Removed invalid syntax
f5a1835
Added CalledProcessError
f0be2a7
Merge remote-tracking branch 'Azure/master' into maduong/bugfix/28256…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,11 @@ | |
RP_URL = BASE_URL + CONTAINER_SERVICE_RESOURCE_URL + "/providers/Microsoft.Mindaro" | ||
API_VERSION = "2016-11-01-preview" | ||
|
||
DOCKERFILE_FILE = 'Dockerfile' | ||
DOCKER_COMPOSE_FILE = 'docker-compose.yml' | ||
DOCKER_COMPOSE_TEST_FILE = 'docker-compose.test.yml' | ||
DOCKER_COMPOSE_EXPECTED_VERSION = '2' | ||
|
||
def add_release( | ||
name, | ||
resource_group_name, | ||
|
@@ -192,49 +197,66 @@ def list_releases(name, resource_group_name): | |
json_request = req.json() | ||
return json_request | ||
|
||
def _gitroot(): | ||
""" | ||
Gets the absolute path of the repository root | ||
""" | ||
try: | ||
base = check_output(['git', 'rev-parse', '--show-toplevel']) | ||
except OSError: | ||
raise CLIError('Git is not currently installed.') | ||
except CalledProcessError: | ||
raise CLIError('Current working directory is not a git repository') | ||
return base.decode('utf-8').strip() | ||
|
||
def _get_filepath_in_current_git_repo(file_to_search): | ||
""" | ||
retrieves the full path of the first file in the git repo that matches filename | ||
""" | ||
for dirpath, _, filenames in os.walk(_gitroot()): | ||
for file_name in filenames: | ||
if file_name.lower() == file_to_search.lower(): | ||
return os.path.join(dirpath, file_name) | ||
return None | ||
|
||
def _ensure_docker_compose(): | ||
""" | ||
1. Raises an error if there is no docker_compose_file present. | ||
2. Raises an error if the version specified in the docker_compose_file is not | ||
docker_compose_version. | ||
3. Raises an error if docker_compose_test_file has a version other than docker_compose_version. | ||
""" | ||
docker_compose_file = 'docker-compose.yml' | ||
docker_compose_test_file = 'docker-compose.test.yml' | ||
docker_compose_expected_version = '2' | ||
if not os.path.isfile(docker_compose_file): | ||
raise CLIError('Docker compose file "{}" was not found.'.format(docker_compose_file)) | ||
with open(docker_compose_file, 'r') as f: | ||
docker_compose_file = _get_filepath_in_current_git_repo(DOCKER_COMPOSE_FILE) | ||
docker_compose_test_file = _get_filepath_in_current_git_repo(DOCKER_COMPOSE_TEST_FILE) | ||
|
||
if not docker_compose_file: | ||
raise CLIError('Docker compose file "{}" was not found.'.format(DOCKER_COMPOSE_FILE)) | ||
_ensure_version(docker_compose_file, DOCKER_COMPOSE_EXPECTED_VERSION) | ||
|
||
if docker_compose_test_file: | ||
_ensure_version(docker_compose_test_file, DOCKER_COMPOSE_EXPECTED_VERSION) | ||
|
||
def _ensure_version(filepath, expected_version): | ||
with open(filepath, 'r') as f: | ||
compose_data = yaml.load(f) | ||
if 'version' not in compose_data.keys(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checking for version and is exactly the same for both files - consider refactoring (e.g. |
||
raise CLIError('File : "{}"\nis missing version information.'.format( | ||
filepath)) | ||
if not expected_version in compose_data['version']: | ||
raise CLIError( | ||
'Docker compose file "{}" is missing version information.'.format( | ||
docker_compose_file)) | ||
if not docker_compose_expected_version in compose_data['version']: | ||
raise CLIError( | ||
'Docker compose file "{}" has incorrect version. \ | ||
Only version "{}" is supported.'.format( | ||
docker_compose_file, | ||
docker_compose_expected_version)) | ||
if os.path.isfile(docker_compose_test_file): | ||
with open(docker_compose_test_file, 'r') as f: | ||
compose_data = yaml.load(f) | ||
if 'version' not in compose_data.keys(): | ||
raise CLIError('Docker compose file "{}" is missing version information.'.format( | ||
docker_compose_test_file)) | ||
if not docker_compose_expected_version in compose_data['version']: | ||
raise CLIError( | ||
'Docker compose file "{}" has incorrect version. \ | ||
Only version "{}" is supported.'.format( | ||
docker_compose_test_file, | ||
docker_compose_expected_version)) | ||
'File : "{}"\nhas incorrect version. \ | ||
\n Only version "{}" is supported.'.format( | ||
filepath, | ||
expected_version)) | ||
|
||
|
||
def _ensure_dockerfile(): | ||
""" | ||
1. Raises an error if there is no dockerfile present. | ||
""" | ||
dockerfile_file = 'Dockerfile' | ||
if not os.path.isfile(dockerfile_file): | ||
dockerfile_file = _get_filepath_in_current_git_repo(DOCKERFILE_FILE) | ||
|
||
if not dockerfile_file: | ||
raise CLIError('Docker file "{}" was not found.'.format(dockerfile_file)) | ||
|
||
def _get_remote_url(): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add
CalledProcessError
to thefrom subprocess import ...
line at the very top.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved