Skip to content

Commit 7784851

Browse files
committed
Move --stack
1 parent 48b5b2e commit 7784851

17 files changed

Lines changed: 47 additions & 289 deletions

File tree

src/stack/build/build_webapp.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import os
2626
import sys
2727

28-
from decouple import config
2928
from pathlib import Path
3029

3130
from stack.build import prepare_containers
@@ -50,7 +49,6 @@ def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, t
5049
quiet = ctx.obj.quiet
5150
debug = ctx.obj.debug
5251
verbose = ctx.obj.verbose
53-
stack = ctx.obj.stack
5452

5553
# See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
5654
container_build_dir = Path(__file__).absolute().parent.parent.joinpath("data", "container-build")
@@ -71,7 +69,7 @@ def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, t
7169
logger.log(f"Building base container: {base_container}")
7270

7371
build_context_1 = BuildContext(
74-
stack,
72+
None,
7573
ContainerSpec(base_container),
7674
container_build_dir,
7775
container_build_env,
@@ -101,7 +99,7 @@ def command(ctx, base_container, source_repo, force_rebuild, extra_build_args, t
10199
logger.log(f"Building app container: {tag}")
102100

103101
build_context_2 = BuildContext(
104-
stack,
102+
None,
105103
ContainerSpec(base_container),
106104
container_build_dir,
107105
container_build_env,

src/stack/build/prepare_containers.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
from stack.constants import container_file_name, container_lock_file_name
3737
from stack.opts import opts
3838
from stack.repos.setup_repositories import fs_path_for_repo, process_repo
39-
from stack.util import get_dev_root_path, include_exclude_check, stack_is_external, error_exit, get_yaml
40-
39+
from stack.util import get_dev_root_path, include_exclude_check, stack_is_external, error_exit, get_yaml, check_if_stack_exists
4140

4241
docker = DockerClient()
4342

@@ -143,27 +142,8 @@ def process_container(build_context: BuildContext) -> bool:
143142
return True
144143

145144

146-
@click.command(hidden=True)
147-
@click.option("--include", help="only build these containers")
148-
@click.option("--exclude", help="don't build these containers")
149-
@click.option("--force-rebuild", is_flag=True, default=False, help="Override dependency checking -- always rebuild")
150-
@click.option("--extra-build-args", help="Supply extra arguments to build")
151-
@click.option("--publish-images", is_flag=True, default=False, help="Publish the built images in the specified image registry")
152-
@click.option("--image-registry", help="Specify the image registry for --publish-images")
153-
@click.pass_context
154-
def legacy_command(ctx, include, exclude, force_rebuild, extra_build_args, publish_images, image_registry):
155-
"""build the set of containers required for a complete stack"""
156-
157-
# Legacy support for build-containers command.
158-
159-
build_policy = "build"
160-
if force_rebuild:
161-
build_policy = "build-force"
162-
163-
_prepare_containers(ctx, include, exclude, False, build_policy, extra_build_args, True, publish_images, image_registry, None)
164-
165-
166145
@click.command()
146+
@click.option("--stack", help="path to the stack", required=True)
167147
@click.option("--include", help="only build these containers")
168148
@click.option("--exclude", help="don't build these containers")
169149
@click.option("--git-ssh", is_flag=True, default=False)
@@ -174,14 +154,9 @@ def legacy_command(ctx, include, exclude, force_rebuild, extra_build_args, publi
174154
@click.option("--image-registry", help="Specify the remote image registry (default: auto-detect per-container)")
175155
@click.option("--target-arch", help="Specify a target architecture (only for use with --no-pull)")
176156
@click.pass_context
177-
def command(ctx, include, exclude, git_ssh, build_policy, extra_build_args, no_pull, publish_images, image_registry, target_arch):
157+
def command(ctx, stack, include, exclude, git_ssh, build_policy, extra_build_args, no_pull, publish_images, image_registry, target_arch):
178158
"""build (or fetch pre-built) stack containers"""
179-
180-
_prepare_containers(ctx, include, exclude, git_ssh, build_policy, extra_build_args, no_pull, publish_images, image_registry, target_arch)
181-
182-
183-
def _prepare_containers(ctx, include, exclude, git_ssh, build_policy, extra_build_args, no_pull, publish_images, image_registry, target_arch):
184-
stack = ctx.obj.stack
159+
check_if_stack_exists(stack)
185160

186161
if build_policy not in BUILD_POLICIES:
187162
error_exit(f"{build_policy} is not one of {BUILD_POLICIES}")

src/stack/command_types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
@dataclass
2020
class CommandOptions:
21-
stack: str
2221
quiet: bool = False
2322
verbose: bool = False
2423
dry_run: bool = False

src/stack/deploy/deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,5 +456,5 @@ class ConfigDirective:
456456
print(f"destination output: {destination_output}")
457457

458458

459-
command.add_command(deployment_init, "config")
459+
command.add_command(deployment_init, "init")
460460
command.add_command(deployment_create, "create")

src/stack/deploy/deployment.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
def command(ctx, dir):
4343
"""manage an existing stack deployment"""
4444

45-
# Check that --stack wasn't supplied
46-
if ctx.parent.obj.stack:
47-
print("Error: --stack can't be supplied with the deployment command")
48-
sys.exit(1)
4945
# Check dir is valid
5046
dir_path = Path(dir)
5147
if not dir_path.exists():

src/stack/deploy/deployment_create.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from stack import constants
2828
from stack.opts import opts
2929
from stack.util import (
30-
global_options,
3130
get_stack_path,
3231
get_yaml,
3332
pod_has_scripts,
@@ -41,6 +40,7 @@
4140
from stack.deploy.stack import Stack
4241
from stack.deploy.deployer_factory import getDeployerConfigGenerator
4342
from stack.deploy.deployment_context import DeploymentContext
43+
from stack.util import check_if_stack_exists
4444

4545

4646
def _make_default_deployment_dir():
@@ -266,6 +266,7 @@ def _parse_config_variables(variable_values: str):
266266

267267

268268
@click.command()
269+
@click.option("--stack", help="path to the stack", required=True)
269270
@click.option("--config", help="Provide config variables for the deployment")
270271
@click.option("--config-file", help="Provide config variables in a file for the deployment")
271272
@click.option("--kube-config", help="Provide a config file for a k8s deployment")
@@ -289,6 +290,7 @@ def _parse_config_variables(variable_values: str):
289290
@click.pass_context
290291
def init(
291292
ctx,
293+
stack,
292294
config,
293295
config_file,
294296
kube_config,
@@ -298,9 +300,8 @@ def init(
298300
map_ports_to_host,
299301
):
300302
"""output a stack specification file"""
301-
stack = global_options(ctx).stack
302-
if not stack:
303-
error_exit("Error: --stack option is required")
303+
check_if_stack_exists(stack)
304+
304305
deployer_type = ctx.obj.deployer.type
305306
deploy_command_context = ctx.obj
306307
return init_operation(

src/stack/deploy/webapp/deploy_webapp.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ def create_deployment(ctx, deployment_dir, image, url, kube_config, image_regist
102102
def command(ctx):
103103
"""manage a webapp setupment"""
104104

105-
# Check that --stack wasn't supplied
106-
if ctx.parent.obj.stack:
107-
error_exit("--stack can't be supplied with the webapp setup command")
105+
pass
108106

109107

110108
@command.command()

src/stack/main.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,46 @@
1515
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
1616

1717
import click
18-
import os
1918
import sys
2019

2120
from stack.cli_util import StackCLI, load_subcommands_from_stack
2221
from stack.command_types import CommandOptions
2322
from stack.repos import fetch
24-
from stack.repos import setup_repositories
2523
from stack.build import build
26-
from stack.build import prepare_containers
2724
from stack.deploy import deploy
2825
from stack import version
2926
from stack.deploy import deployment
3027
from stack import opts
3128
from stack import update
3229
from stack.webapp import webapp
33-
from stack.util import stack_is_external, error_exit
30+
from stack.util import STACK_USE_BUILTIN_STACK
3431

3532
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
3633

37-
STACK_USE_BUILTIN_STACK = "true" == os.environ.get("STACK_USE_BUILTIN_STACK", "false")
38-
3934

4035
@click.group(context_settings=CONTEXT_SETTINGS, cls=StackCLI)
41-
@click.option("--stack", help="path to the stack to build/deploy")
4236
@click.option("--verbose", help="more detailed output", is_flag=True, default=False)
4337
@click.option("--debug", help="enable debug logging", is_flag=True, default=False)
4438
# TEL: Hide these for now, until we make sure they are consistently implemented.
4539
@click.option("--quiet", is_flag=True, default=False, hidden=True)
4640
@click.option("--dry-run", is_flag=True, default=False, hidden=True)
4741
@click.option("--continue-on-error", is_flag=True, default=False, hidden=True)
4842
@click.pass_context
49-
def cli(ctx, stack, quiet, verbose, dry_run, debug, continue_on_error):
43+
def cli(ctx, quiet, verbose, dry_run, debug, continue_on_error):
5044
"""BPI stack"""
51-
if stack and not stack_is_external(stack) and not STACK_USE_BUILTIN_STACK:
52-
error_exit(f"Stack {stack} does not exist")
53-
54-
command_options = CommandOptions(stack, quiet, verbose, dry_run, debug, continue_on_error)
45+
command_options = CommandOptions(quiet, verbose, dry_run, debug, continue_on_error)
5546
opts.opts.o = command_options
5647
ctx.obj = command_options
5748

5849

5950
cli.add_command(build.command, "build")
51+
cli.add_command(deploy.command, "deploy")
6052
cli.add_command(deployment.command, "deployment")
6153
cli.add_command(fetch.command, "fetch")
62-
cli.add_command(deploy.command, "init")
6354
cli.add_command(update.command, "update")
6455
cli.add_command(version.command, "version")
6556
cli.add_command(webapp.command, "webapp")
6657

67-
# Hidden commands
68-
cli.add_command(prepare_containers.legacy_command, "build-containers")
69-
cli.add_command(setup_repositories.legacy_command, "fetch repositories")
70-
7158
# We only try to load external commands from an external stack.
7259
if not STACK_USE_BUILTIN_STACK:
7360
stack_path = None

src/stack/repos/setup_repositories.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
warn_exit,
3434
)
3535

36-
from stack.util import get_dev_root_path
36+
from stack.util import get_dev_root_path, check_if_stack_exists
3737

3838
from stack.build.build_util import get_containers_in_scope, host_and_path_for_repo, branch_strip
3939

@@ -182,39 +182,21 @@ def parse_branches(branches_string):
182182
return None
183183

184184

185-
@click.command(hidden=True)
186-
@click.option("--include", help="only clone these repositories")
187-
@click.option("--exclude", help="don't clone these repositories")
188-
@click.option("--git-ssh", is_flag=True, default=False)
189-
@click.option("--check-only", is_flag=True, default=False)
190-
@click.option("--pull", is_flag=True, default=False)
191-
@click.option("--branches", help="override branches for repositories")
192-
@click.pass_context
193-
def legacy_command(ctx, include, exclude, git_ssh, check_only, pull, branches):
194-
"""clone the repositories needed by the stack"""
195-
196-
return _command(ctx, include, exclude, git_ssh, check_only, pull, branches)
197-
198-
199185
@click.command()
186+
@click.option("--stack", help="path to the stack", required=True)
200187
@click.option("--include", help="only clone these repositories")
201188
@click.option("--exclude", help="don't clone these repositories")
202189
@click.option("--git-ssh", is_flag=True, default=False)
203190
@click.option("--check-only", is_flag=True, default=False)
204191
@click.option("--pull", is_flag=True, default=False)
205192
@click.option("--branches", help="override branches for repositories")
206193
@click.pass_context
207-
def command(ctx, include, exclude, git_ssh, check_only, pull, branches):
194+
def command(ctx, stack, include, exclude, git_ssh, check_only, pull, branches):
208195
"""clone the repositories needed by the stack"""
196+
check_if_stack_exists(stack)
209197

210-
return _command(ctx, include, exclude, git_ssh, check_only, pull, branches)
211-
212-
213-
def _command(ctx, include, exclude, git_ssh, check_only, pull, branches):
214-
"""clone the repositories needed by the stack"""
215198
quiet = opts.o.quiet
216199
verbose = opts.o.verbose
217-
stack = opts.o.stack
218200

219201
branches_array = []
220202

src/stack/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from typing import Mapping, Set, List
2424
from stack.constants import stack_file_name, deployment_file_name
2525

26+
STACK_USE_BUILTIN_STACK = "true" == os.environ.get("STACK_USE_BUILTIN_STACK", "false")
27+
2628

2729
def include_exclude_check(s, include, exclude):
2830
if include is None and exclude is None:
@@ -239,3 +241,8 @@ def warn_exit(s):
239241

240242
def env_var_map_from_file(file: Path, expand=True) -> Mapping[str, str]:
241243
return dotenv_values(file, interpolate=expand)
244+
245+
246+
def check_if_stack_exists(stack):
247+
if stack and not stack_is_external(stack) and not STACK_USE_BUILTIN_STACK:
248+
error_exit(f"Stack {stack} does not exist")

0 commit comments

Comments
 (0)