forked from jbeorse/sync-endpoint-default-setup
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Enhancement: Docker Swarm stack name added. #26
Open
adityaofficial10
wants to merge
1
commit into
odk-x:development
Choose a base branch
from
adityaofficial10:fix/stack-name-added
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Configure the fully qualified domain to be served via HTTPS | ||
HTTPS_DOMAIN=localhost | ||
[email protected] | ||
STACK_NAME=syncldap |
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ def run_interactive_config(): | |
env_file_location = os.path.join(os.path.dirname(__file__), "config", "https.env") | ||
|
||
try: | ||
domain, email = parse_env_file(env_file_location) | ||
domain, email, stack_name = parse_env_file(env_file_location) | ||
print("Found configuration at {}".format(env_file_location)) | ||
except OSError: | ||
print("No default https configuration file found at expected path {}. This prevents automatically renewing certs!".format(env_file_location)) | ||
|
@@ -37,6 +37,14 @@ def run_interactive_config(): | |
if input_domain != "": | ||
domain = input_domain | ||
|
||
print("") | ||
|
||
print("Enter the Docker Swarm stack name you'd like to use:") | ||
input_stack_name = input("Docker Swarm stack [({})]:".format(stack_name)) | ||
|
||
if input_stack_name != "": | ||
stack_name = input_stack_name | ||
|
||
print("") | ||
use_custom_password = input("Do you want to use a custom LDAP administration password (y/N)?") | ||
if use_custom_password == "y": | ||
|
@@ -97,8 +105,7 @@ def run_interactive_config(): | |
--non-interactive".format(email, domain)) | ||
|
||
print("Attempting to save updated https configuration") | ||
write_to_env_file(env_file_location, domain, email) | ||
|
||
write_to_env_file(env_file_location, domain, email, stack_name) | ||
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. This should not be guarded behind |
||
return enforce_https | ||
|
||
|
||
|
@@ -112,7 +119,7 @@ def replaceInFile(file_path, pattern, subst): | |
remove(file_path) | ||
move(abs_path, file_path) | ||
|
||
def write_to_env_file(filepath, domain_name, email): | ||
def write_to_env_file(filepath, domain_name, email, stack_name): | ||
"""A janky in-memory file write. | ||
|
||
This is not atomic and would use lots of ram for large files. | ||
|
@@ -128,19 +135,24 @@ def write_to_env_file(filepath, domain_name, email): | |
line = "HTTPS_DOMAIN={}\n".format(domain_name) | ||
if line.startswith("HTTPS_ADMIN_EMAIL="): | ||
line = "HTTPS_ADMIN_EMAIL={}\n".format(email) | ||
if line.startswith("STACK_NAME="): | ||
line = "STACK_NAME={}\n".format(stack_name) | ||
f.write(line) | ||
|
||
|
||
def parse_env_file(filepath): | ||
domain = None | ||
email = None | ||
stack_name = None | ||
with open(filepath) as f: | ||
for line in f: | ||
if line.startswith("HTTPS_DOMAIN="): | ||
domain=line[13:].strip() | ||
if line.startswith("HTTPS_ADMIN_EMAIL="): | ||
email=line[18:].strip() | ||
return (domain,email) | ||
if line.startswith("STACK_NAME="): | ||
stack_name=line[11:].strip() | ||
return (domain,email,stack_name) | ||
|
||
|
||
def run_docker_builds(): | ||
|
@@ -157,14 +169,16 @@ def run_sync_endpoint_build(): | |
|
||
|
||
def deploy_stack(use_https): | ||
env_file_location = os.path.join(os.path.dirname(__file__), "config", "https.env") | ||
domain, email, stack_name = parse_env_file(env_file_location) | ||
if use_https: | ||
os.system("docker stack deploy -c docker-compose.yml -c docker-compose-https.yml syncldap") | ||
os.system("docker stack deploy -c docker-compose.yml -c docker-compose-https.yml {}".format(stack_name)) | ||
else: | ||
os.system("docker stack deploy -c docker-compose.yml syncldap") | ||
os.system("docker stack deploy -c docker-compose.yml {}".format(stack_name)) | ||
|
||
|
||
if __name__ == "__main__": | ||
https = run_interactive_config() | ||
run_docker_builds() | ||
run_sync_endpoint_build() | ||
deploy_stack(https) | ||
deploy_stack(https) |
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.
For a user coming from a previous version,
stack_name
would beNone
here. Please add a check.