-
Notifications
You must be signed in to change notification settings - Fork 3
Support multiple Docker deployments on the same host #586
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
Draft
ezio-melotti
wants to merge
5
commits into
master
Choose a base branch
from
docker-multiple-deployments
base: master
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.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4587e15
Avoid exposing redis and mysql ports
ezio-melotti fb3f297
Support different project names
ezio-melotti 07ca10f
Remove duplicated var
ezio-melotti 18f26fd
Fix typo in comment
ezio-melotti 9f3be7d
Refactor ENV_FILE and PROJECT_NAME handling
ezio-melotti 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 hidden or 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
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,10 +25,12 @@ | |||||
| CERTBOT_DIR = SCRIPT_DIR.parent.parent / 'certbot' | ||||||
| CERTBOT_SYMLINK_DIR = SCRIPT_DIR / 'certbot' | ||||||
|
|
||||||
| # some of these are overridden in the __main__ section | ||||||
| COMPOSE_FILE = 'docker-compose.mysql.yml' | ||||||
| DEV_BE_COMPOSE_FILE = 'docker-compose.dev-be.yml' | ||||||
| AGENT_DESC_COMPOSE_FILE = 'docker-compose.agent-desc.yml' | ||||||
| TESTING_COMPOSE_FILE = 'docker-compose.testing.yml' | ||||||
| PROJECT_NAME = 'simoc' # used to handle multiple deployments | ||||||
| DOCKER_COMPOSE_CMD = ['docker', 'compose', '-f', COMPOSE_FILE] | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -302,7 +304,7 @@ def init_db(): | |||||
| def remove_db(): | ||||||
| """Remove the volume for the MySQL DB.""" | ||||||
| docker_compose('rm', '--stop', '-v', '-f', 'simoc-db') | ||||||
| docker('volume', 'rm', 'simoc_db-data') | ||||||
| docker('volume', 'rm', f'{PROJECT_NAME}_db-data') | ||||||
| return True # the volume rm might return False if the volume is missing | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -404,7 +406,8 @@ def test(*args): | |||||
| # add the testing yml that replaces the db | ||||||
| DOCKER_COMPOSE_CMD.extend(['-f', TESTING_COMPOSE_FILE]) | ||||||
| # check if the volume already exists | ||||||
| cp = subprocess.run(['docker', 'volume', 'inspect', 'simoc_db-testing'], | ||||||
| test_volume = f'{PROJECT_NAME}_db-testing' | ||||||
| cp = subprocess.run(['docker', 'volume', 'inspect', test_volume], | ||||||
| capture_output=True) | ||||||
| vol_info = json.loads(cp.stdout) | ||||||
| if not vol_info: | ||||||
|
|
@@ -430,16 +433,18 @@ def adminer(db=None): | |||||
| # mount the 'simoc_db-testing' volume instead of the | ||||||
| # default 'simoc_db-data' if 'testing' is passed as arg | ||||||
| DOCKER_COMPOSE_CMD.extend(['-f', TESTING_COMPOSE_FILE]) | ||||||
| db_container = f'{PROJECT_NAME}-simoc-db-1' | ||||||
| network_name = f'{PROJECT_NAME}_simoc-net' | ||||||
| def show_info(): | ||||||
| # show the volume that is currently connected to the db container | ||||||
| cp = subprocess.run(['docker', 'inspect', '-f', | ||||||
| '{{range .Mounts}}{{.Name}}{{end}}', | ||||||
| 'simoc_simoc-db_1'], capture_output=True) | ||||||
| db_container], capture_output=True) | ||||||
| print('* Starting adminer at: http://localhost:8081/') | ||||||
| print('* Connecting to:', cp.stdout.decode('utf-8')) | ||||||
| return True | ||||||
| cmd = ['run', '--network', 'simoc_simoc-net', | ||||||
| '--link', 'simoc_simoc-db_1:db', '-p', '8081:8080', | ||||||
| cmd = ['run', '--network', network_name, | ||||||
| '--link', f'{db_container}:db', '-p', '8081:8080', | ||||||
| '-e', 'ADMINER_DESIGN=dracula', 'adminer'] | ||||||
| return up() and show_info() and docker(*cmd) | ||||||
|
|
||||||
|
|
@@ -505,8 +510,12 @@ def create_help(cmds): | |||||
| help='the docker compose yml file (default: %(default)r)' | ||||||
| ) | ||||||
| parser.add_argument( | ||||||
| '--env-file', metavar='FILE', type=pathlib.Path, default=ENV_FILE, | ||||||
| help='the env file (default: %(default)r)' | ||||||
| '--project-name', metavar='NAME', | ||||||
| help='the project name for docker compose' | ||||||
| ) | ||||||
| parser.add_argument( | ||||||
| '--env-file', metavar='FILE', type=pathlib.Path, | ||||||
| help='the env file with the deployment-specific variables' | ||||||
|
||||||
| help='the env file with the deployment-specific variables' | |
| help='the env file with the deployment-specific variables (default: env/local.env)' |
ezio-melotti marked this conversation as resolved.
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.
The comment references hardcoded volume names 'simoc_db-testing' and 'simoc_db-data', but the actual volume names are now dynamic based on PROJECT_NAME. Consider updating the comment to reflect this, e.g., "mount the '{PROJECT_NAME}_db-testing' volume instead of the default '{PROJECT_NAME}_db-data' if 'testing' is passed as arg"