Skip to content

Commit c06a0ea

Browse files
authored
Use composefile rather than docker-compose (#30)
1 parent 314c2c6 commit c06a0ea

9 files changed

Lines changed: 32 additions & 12 deletions

File tree

src/stack/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
# You should have received a copy of the GNU Affero General Public License
1515
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
1616

17+
import os
18+
1719
annotations_key = "annotations"
1820
cluster_id_key = "cluster-id"
1921
cluster_name_prefix = "bpi-"
2022
compose_deploy_type = "compose"
2123
compose_dir_name = "compose"
24+
compose_file_prefix = os.environ.get("BPI_COMPOSE_FILE_PREFIX", "composefile")
2225
config_file_name = "config.env"
2326
config_key = "config"
2427
configmaps_key = "configmaps"

src/stack/data/compose/docker-compose-test-database.yml renamed to src/stack/data/compose/composefile-test-database.yml

File renamed without changes.
File renamed without changes.

src/stack/data/compose/docker-compose-webapp-template.yml renamed to src/stack/data/compose/composefile-webapp-template.yml

File renamed without changes.

src/stack/deploy/deploy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from dataclasses import dataclass
2626
from importlib import resources
2727
from pathlib import Path
28-
from stack import constants
28+
from stack.constants import compose_file_prefix, cluster_name_prefix
2929
from stack.opts import opts
3030
from stack.util import (
3131
include_exclude_check,
@@ -220,7 +220,7 @@ def _make_default_cluster_name(deployment, compose_dir, stack, include, exclude)
220220
if opts.o.debug:
221221
print(f"pre-hash descriptor: {unique_cluster_descriptor}")
222222
hash = hashlib.md5(unique_cluster_descriptor.encode()).hexdigest()[:16]
223-
cluster = f"{constants.cluster_name_prefix}{hash}"
223+
cluster = f"{cluster_name_prefix}{hash}"
224224
if opts.o.debug:
225225
print(f"Using cluster name: {cluster}")
226226
return cluster
@@ -276,12 +276,12 @@ def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file):
276276
if include_exclude_check(pod_name, include, exclude):
277277
if pod_repository is None or pod_repository == "internal":
278278
if deployment:
279-
compose_file_name = os.path.join(compose_dir, f"docker-compose-{pod_path}.yml")
279+
compose_file_name = os.path.join(compose_dir, f"{compose_file_prefix}-{pod_path}.yml")
280280
else:
281281
compose_file_name = resolve_compose_file(stack, pod_name)
282282
else:
283283
if deployment:
284-
compose_file_name = os.path.join(compose_dir, f"docker-compose-{pod_name}.yml")
284+
compose_file_name = os.path.join(compose_dir, f"{compose_file_prefix}-{pod_name}.yml")
285285
pod_pre_start_command = pod.get("pre_start_command")
286286
pod_post_start_command = pod.get("post_start_command")
287287
script_dir = compose_dir.parent.joinpath("pods", pod_name, "scripts")
@@ -292,7 +292,7 @@ def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file):
292292
else:
293293
# TODO: fix this code for external stack with scripts
294294
pod_root_dir = os.path.join(dev_root_path, pod_repository.split("/")[-1], pod["path"])
295-
compose_file_name = os.path.join(pod_root_dir, f"docker-compose-{pod_name}.yml")
295+
compose_file_name = os.path.join(pod_root_dir, f"{compose_file_prefix}-{pod_name}.yml")
296296
pod_pre_start_command = pod.get("pre_start_command")
297297
pod_post_start_command = pod.get("post_start_command")
298298
if pod_pre_start_command is not None:

src/stack/deploy/deployment_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_compose_dir(self):
4242
return self.deployment_dir.joinpath(constants.compose_dir_name)
4343

4444
def get_compose_files(self):
45-
return glob.glob(f"{self.get_compose_dir()}/docker-compose-*.yml")
45+
return glob.glob(f"{self.get_compose_dir()}/{constants.compose_file_prefix}-*.yml")
4646

4747
def get_cluster_id(self):
4848
return self.id

src/stack/deploy/deployment_create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def create_operation(deployment_command_context, parsed_spec: Spec | MergedSpec,
574574
else:
575575
service_info["env_file"] = [shared_cfg_file]
576576

577-
with open(destination_compose_dir.joinpath("docker-compose-%s.yml" % pod), "w") as output_file:
577+
with open(destination_compose_dir.joinpath(f"{constants.compose_file_prefix}-%s.yml" % pod), "w") as output_file:
578578
yaml.dump(parsed_pod_file, output_file)
579579

580580
parsed_stack = parsed_spec.stack_for_pod(pod) if isinstance(parsed_spec, MergedSpec) else parsed_spec.load_stack()

src/stack/deploy/webapp/deploy_webapp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from urllib.parse import urlparse
2121
from tempfile import NamedTemporaryFile
2222

23+
from stack import constants
2324
from stack.util import error_exit, global_options2
2425
from stack.deploy.deployment_create import init_operation, create_operation
2526
from stack.deploy.deploy import create_deploy_context
@@ -29,7 +30,7 @@
2930

3031
def _fixup_container_tag(deployment_dir: str, image: str):
3132
deployment_dir_path = Path(deployment_dir)
32-
compose_file = deployment_dir_path.joinpath("compose", "docker-compose-webapp-template.yml")
33+
compose_file = deployment_dir_path.joinpath("compose", f"{constants.compose_file_prefix}-webapp-template.yml")
3334
# replace "bpi/webapp-container:stack" in the file with our image tag
3435
with open(compose_file) as rfile:
3536
contents = rfile.read()

src/stack/util.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
from pathlib import Path
2424
from dotenv import dotenv_values
2525
from typing import Mapping
26-
27-
from stack.constants import deployment_file_name
26+
from stack.constants import deployment_file_name, compose_file_prefix
2827

2928
STACK_USE_BUILTIN_STACK = "true" == os.environ.get("STACK_USE_BUILTIN_STACK", "false")
3029

@@ -87,12 +86,29 @@ def resolve_compose_file(stack, pod_name: str):
8786
if stack_is_external(stack):
8887
# First try looking in the external stack for the compose file
8988
compose_base = Path(stack).parent.parent.joinpath("compose")
90-
proposed_file = compose_base.joinpath(f"docker-compose-{pod_name}.yml")
89+
proposed_file = compose_base.joinpath(f"{compose_file_prefix}-{pod_name}.yml")
9190
if proposed_file.exists():
9291
return proposed_file
9392
# If we don't find it fall through to the internal case
9493
compose_base = get_internal_compose_file_dir()
95-
return compose_base.joinpath(f"docker-compose-{pod_name}.yml")
94+
return compose_base.joinpath(f"{compose_file_prefix}-{pod_name}.yml")
95+
96+
97+
def get_pod_file_path(stack, parsed_stack, pod_name: str):
98+
result = None
99+
pods = parsed_stack["pods"]
100+
if type(pods[0]) is str:
101+
result = resolve_compose_file(stack, pod_name)
102+
else:
103+
for pod in pods:
104+
if pod["name"] == pod_name:
105+
pod_root_dir = os.path.join(
106+
get_dev_root_path(None),
107+
pod["repository"].split("@")[0].split("/")[-1],
108+
pod["path"],
109+
)
110+
result = os.path.join(pod_root_dir, "{compose_file_prefix}.yml")
111+
return result
96112

97113

98114
def get_pod_script_paths(parsed_stack, pod_name: str):

0 commit comments

Comments
 (0)