Skip to content
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
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/https.env
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
30 changes: 22 additions & 8 deletions init-odkx-sync-endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

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 be None here. Please add a check.

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))
Expand All @@ -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":
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be guarded behind enforce_https anymore.

return enforce_https


Expand All @@ -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.
Expand All @@ -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():
Expand All @@ -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)