-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use repository for aladdin config (#106)
- Added git fetching of aladdin config using a "config_repo" option - Replaced --dev flag with ALADDIN_DEV env variable
- Loading branch information
1 parent
8bdd11a
commit 59ae2b7
Showing
9 changed files
with
147 additions
and
46 deletions.
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 |
---|---|---|
|
@@ -53,7 +53,11 @@ You can add these two commands to your profile file if desired. | |
|
||
You will now need to [create your aladdin configuration](./docs/create_aladdin_configuration.md), and link that to aladdin. | ||
|
||
$ aladdin config set config_dir /path/to/aladdin/configuration | ||
$ aladdin config set config_repo [email protected]:{git_account}/{repo}.git | ||
|
||
NOTE: | ||
|
||
When doing bootstrapping, initial setup or when developing on the aladdin codebase itself it might be useful to be able to point aladdin to a config on the local development environment (ie not yet in source control). This can be done by setting the `ALADDIN_DEV=true` environment variable and by setting the `config_dir` setting (`aladdin config set config_dir /path/to/your/config`). | ||
|
||
### Manage configuration | ||
#### Software dependencies | ||
|
@@ -135,10 +139,11 @@ We have several aladdin commands used for development and deployment. Note that | |
- `-c/--cluster` which cluster to connect to, defaults to `LOCAL`. | ||
- `-n/--namespace` which namespace to connect to, defaults to `default`. | ||
- `--init` force initialization logic (i.e. pull latest aladdin image, test aws config, initialize helm, etc...). This is forced every hour for each cluster/namespace combo. | ||
- `--dev` mount host's aladdin directory onto aladdin container. Useful when developing aladdin. | ||
- `--skip-prompts` skip any confirmation messages during aladdin execution. Useful when automating commands. | ||
- `--non-terminal` run aladdin container without tty. | ||
|
||
Additionally aladdin checks for a `ALADDIN_DEV=true` environment variable, that when set aladdin will mount the host's aladdin directory onto the aladdin container. This means code changes should be reflected on the container without the need to re-build the image. Mostly useful when developing aladdin. | ||
|
||
## Running several aladdin commands in the same cluster/namespace combo | ||
Aladdin supports running several commands in the same cluster/namespace combo without having to "reinitialize" aladdin. To do this, go into `aladdin bash`. Then all the container commands will be aliased to be run without prefixing aladdin. | ||
Example: | ||
|
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
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
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
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,5 +1,15 @@ | ||
import json | ||
import os | ||
import pathlib | ||
import subprocess | ||
from distutils.util import strtobool | ||
|
||
from aladdin import __version__ | ||
from aladdin.lib import logging | ||
from aladdin.lib.utils import working_directory | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__)) | ||
|
||
|
@@ -39,3 +49,104 @@ def load_config_from_file(file): | |
|
||
def load_config(): | ||
return load_config_from_file(f'{os.environ["ALADDIN_CONFIG_DIR"]}/config.json') | ||
|
||
|
||
def load_user_config_file() -> dict: | ||
home = pathlib.Path.home() | ||
return load_config_from_file(home / ".aladdin/config/config.json") | ||
|
||
|
||
def set_user_config_file(config: dict): | ||
home = pathlib.Path.home() | ||
with open(home / ".aladdin/config/config.json", "w") as json_file: | ||
json.dump(config, json_file, indent=2) | ||
|
||
|
||
def set_config_path() -> bool: | ||
""" | ||
Function to set the "ALADDIN_CONFIG_DIR" env var | ||
Uses git to fetch the latest revision of the config repo | ||
NOTE: | ||
If this function returns False it will short-circuit execution of | ||
any aladdin command, so returning False should be preceded by some | ||
user-friendly error statement about why we're exiting | ||
""" | ||
if os.getenv("ALADDIN_CONFIG_DIR"): | ||
# Aladdin config is already set, nothing to do here | ||
return True | ||
|
||
err_message = ( | ||
"Unable to find config repo. " | ||
"Please use " | ||
"'aladdin config set config_repo <[email protected]:{git_account}/{repo}.git>' " | ||
"to set config repo" | ||
) | ||
try: | ||
config = load_user_config_file() | ||
except FileNotFoundError: | ||
logger.error(err_message) | ||
return False | ||
|
||
config_dir: str = config.get("config_dir") | ||
config_repo: str = config.get("config_repo") | ||
if not config_dir and not config_repo: | ||
logger.error(err_message) | ||
return False | ||
|
||
if not config_repo: | ||
# try to auto-set config_repo | ||
if not os.path.isdir(config_dir): | ||
logger.error(err_message) | ||
return False | ||
with working_directory(config_dir): | ||
try: | ||
remote = subprocess.run( | ||
"git remote get-url origin".split(), | ||
check=True, | ||
capture_output=True, | ||
encoding="utf-8" | ||
).stdout.strip() | ||
except subprocess.CalledProcessError: | ||
logger.error(err_message) | ||
return False | ||
*_, git_account, repo = remote.split("/") | ||
config_repo = f"[email protected]:{git_account}/{repo}" | ||
config["config_repo"] = config_repo | ||
set_user_config_file(config) | ||
|
||
remote_config_path = pathlib.Path.home() / ".aladdin/remote_config" | ||
commands = [f"git clone -b {__version__} {config_repo} remote_config"] | ||
cwd = pathlib.Path.home() / ".aladdin" | ||
if os.path.isdir(remote_config_path) and os.path.isdir(remote_config_path / ".git"): | ||
cwd = remote_config_path | ||
commands = [ | ||
"git fetch --tags --prune -f", | ||
f"git checkout {__version__}" | ||
] | ||
with working_directory(cwd): | ||
for command in commands: | ||
try: | ||
subprocess.run( | ||
command.split(), | ||
check=True, | ||
encoding="utf-8", | ||
capture_output=True | ||
) | ||
except subprocess.CalledProcessError as e: | ||
logger.error( | ||
"Failed to fetch aladdin config (%s) from remote: \n%s", | ||
config_repo, | ||
e.stderr.strip() or e.stdout.strip() | ||
) | ||
return False | ||
|
||
os.environ["ALADDIN_CONFIG_DIR"] = str(remote_config_path) | ||
|
||
if strtobool(os.getenv("ALADDIN_DEV", "false")) and config_dir and os.path.isdir(config_dir): | ||
""" | ||
Allow aladdin developers to use a custom config | ||
""" | ||
os.environ["ALADDIN_CONFIG_DIR"] = config_dir | ||
|
||
return True |
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
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
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
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,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "aladdin" | ||
version = "1.19.7.13" | ||
version = "1.19.7.14" | ||
description = "" | ||
authors = ["Fivestars <[email protected]>"] | ||
include = [ | ||
|