Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0042156

Browse files
thraudfangl
authored andcommitted
remove code for LEGACY_DIRECTORIES (#7865)
1 parent 923107a commit 0042156

File tree

7 files changed

+8
-142
lines changed

7 files changed

+8
-142
lines changed

‎bin/docker-entrypoint.sh

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@ elif [[ -f /usr/lib/localstack/.light-version ]] || [[ -f /usr/lib/localstack/.f
3535
echo ""
3636
fi
3737

38-
# FIXME: remove with 2.0
39-
# the Dockerfile creates .marker file that will be overwritten if a volume is mounted into /tmp/localstack
40-
if [ ! -f /tmp/localstack/.marker ]; then
41-
# unless LEGACY_DIRECTORIES is explicitly set to 1, print an error message and exit with a non-zero exit code
42-
if [[ -z ${LEGACY_DIRECTORIES} ]] || [[ ${LEGACY_DIRECTORIES} == "0" ]]; then
43-
echo "ERROR"
44-
echo "============================================================================"
45-
echo " It seems you are mounting the LocalStack volume into /tmp/localstack."
46-
echo " This will break the LocalStack container! Please update your volume mount"
47-
echo " destination to /var/lib/localstack."
48-
echo " You can suppress this error by setting LEGACY_DIRECTORIES=1."
49-
echo ""
50-
echo " See: https://github.com/localstack/localstack/issues/6398"
51-
echo "============================================================================"
52-
echo ""
53-
exit 1
54-
fi
55-
fi
56-
5738
# This stores the PID of supervisord for us after forking
5839
suppid=0
5940

@@ -92,10 +73,6 @@ test -d ${LOG_DIR} || mkdir -p ${LOG_DIR}
9273
cat /dev/null > ${LOG_DIR}/localstack_infra.log
9374
cat /dev/null > ${LOG_DIR}/localstack_infra.err
9475

95-
# FIXME for backwards compatibility with LEGACY_DIRECTORIES=1
96-
test -f /tmp/localstack_infra.log || ln -s ${LOG_DIR}/localstack_infra.log /tmp/localstack_infra.log
97-
test -f /tmp/localstack_infra.err || ln -s ${LOG_DIR}/localstack_infra.err /tmp/localstack_infra.err
98-
9976
# run modern runtime init scripts before starting localstack
10077
test -d /etc/localstack/init/boot.d && /opt/code/localstack/.venv/bin/python -m localstack.runtime.init BOOT
10178

‎localstack/cli/localstack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def localstack(debug, profile):
5353
from localstack.utils.files import cache_dir
5454

5555
# overwrite the config variable here to defer import of cache_dir
56-
if not config.LEGACY_DIRECTORIES and not os.environ.get("LOCALSTACK_VOLUME_DIR", "").strip():
56+
if not os.environ.get("LOCALSTACK_VOLUME_DIR", "").strip():
5757
config.VOLUME_DIR = str(cache_dir() / "volume")
5858

5959

‎localstack/config.py

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,6 @@ def in_docker():
383383
# temporary folder of the host (required when running in Docker). Fall back to local tmp folder if not set
384384
HOST_TMP_FOLDER = os.environ.get("HOST_TMP_FOLDER", TMP_FOLDER)
385385

386-
# whether to use the old directory structure and mounting config
387-
LEGACY_DIRECTORIES = is_env_true("LEGACY_DIRECTORIES")
388-
389386
# whether to enable verbose debug logging
390387
LS_LOG = eval_log_type("LS_LOG")
391388
DEBUG = is_env_true("DEBUG") or LS_LOG in TRACE_LOG_LEVELS
@@ -1130,56 +1127,15 @@ def __iter__(self):
11301127
SERVICE_PROVIDER_CONFIG.load_from_environment()
11311128

11321129

1133-
def init_legacy_directories() -> Directories:
1134-
global PERSISTENCE
1135-
from localstack import constants
1136-
1137-
constants.DEFAULT_VOLUME_DIR = "/tmp/localstack"
1138-
1139-
if DATA_DIR:
1140-
PERSISTENCE = True
1141-
1142-
if is_in_docker:
1143-
dirs = Directories.legacy_for_container()
1144-
else:
1145-
dirs = Directories.legacy_from_config()
1146-
1147-
dirs.mkdirs()
1148-
return dirs
1149-
1150-
11511130
def init_directories() -> Directories:
1152-
global DATA_DIR, PERSISTENCE
1153-
1154-
if DATA_DIR:
1155-
# deprecation path: DATA_DIR being set means persistence is activated, but we're ignoring the path set in
1156-
# DATA_DIR
1157-
os.environ["PERSISTENCE"] = "1"
1158-
PERSISTENCE = True
1159-
1131+
# FIXME: should also consider when the config.py is loaded from the CLI which does not necessarily imply
1132+
# host mode. this may prove quite tricky to do.
11601133
if is_in_docker:
1161-
dirs = Directories.for_container()
1134+
return Directories.for_container()
11621135
else:
1163-
dirs = Directories.for_host()
1164-
1165-
if PERSISTENCE:
1166-
if DATA_DIR:
1167-
LOG.warning(
1168-
"Persistence mode was activated using the DATA_DIR variable. DATA_DIR is deprecated and "
1169-
"its value is ignored. The data is instead stored into %s in the LocalStack volume.",
1170-
dirs.data,
1171-
)
1172-
1173-
# deprecation path
1174-
DATA_DIR = dirs.data
1175-
1176-
return dirs
1136+
return Directories.for_host()
11771137

11781138

11791139
# initialize directories
11801140
dirs: Directories
1181-
if LEGACY_DIRECTORIES:
1182-
CLEAR_TMP_FOLDER = False
1183-
dirs = init_legacy_directories()
1184-
else:
1185-
dirs = init_directories()
1141+
dirs = init_directories()

‎localstack/services/awslambda/lambda_starter.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,6 @@ def start_lambda(port=None, asynchronous=False):
5757
lambda_utils.get_executor_mode(),
5858
)
5959

60-
if (
61-
config.is_in_docker
62-
and not config.LAMBDA_REMOTE_DOCKER
63-
and not config.dirs.functions
64-
and config.LEGACY_DIRECTORIES
65-
):
66-
LOG.warning(
67-
"!WARNING! - Looks like you have configured $LAMBDA_REMOTE_DOCKER=0 - "
68-
"please make sure to configure $HOST_TMP_FOLDER to point to your host's $TMPDIR"
69-
)
70-
7160
port = port or config.service_port("lambda")
7261
return start_local_api(
7362
"Lambda", port, api="lambda", method=lambda_api.serve, asynchronous=asynchronous

‎localstack/utils/bootstrap.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import Dict, Iterable, List, Optional, Set
1111

1212
from localstack import config, constants
13-
from localstack.config import Directories
1413
from localstack.constants import DEFAULT_VOLUME_DIR
1514
from localstack.runtime import hooks
1615
from localstack.utils.container_networking import get_main_container_name
@@ -580,30 +579,7 @@ def configure_container(container: LocalstackContainer):
580579

581580

582581
def configure_volume_mounts(container: LocalstackContainer):
583-
if not config.LEGACY_DIRECTORIES:
584-
container.volumes.add(VolumeBind(config.VOLUME_DIR, DEFAULT_VOLUME_DIR))
585-
return
586-
587-
source_dirs = config.dirs
588-
target_dirs = Directories.legacy_for_container()
589-
590-
# default shared directories
591-
for name in Directories.default_bind_mounts:
592-
src = getattr(source_dirs, name, None)
593-
target = getattr(target_dirs, name, None)
594-
if src and target:
595-
container.volumes.add(VolumeBind(src, target))
596-
597-
# shared tmp folder
598-
container.volumes.add(VolumeBind(source_dirs.tmp, target_dirs.tmp))
599-
600-
# set the HOST_TMP_FOLDER for the legacy dirs / legacy lambda function mounting
601-
container.env_vars["HOST_TMP_FOLDER"] = source_dirs.functions
602-
603-
# data_dir mounting and environment variables
604-
if source_dirs.data:
605-
container.volumes.add(VolumeBind(source_dirs.data, target_dirs.data))
606-
container.env_vars["DATA_DIR"] = target_dirs.data
582+
container.volumes.add(VolumeBind(config.VOLUME_DIR, DEFAULT_VOLUME_DIR))
607583

608584

609585
@log_duration()

‎localstack/utils/docker_utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33
import platform
44
import random
5-
import re
65
from typing import List, Optional
76

87
from localstack import config
@@ -102,9 +101,6 @@ def get_host_path_for_path_in_docker(path):
102101
:param path: Path to be replaced (subpath of DEFAULT_VOLUME_DIR)
103102
:return: Path on the host
104103
"""
105-
if config.LEGACY_DIRECTORIES:
106-
return re.sub(r"^%s/(.*)$" % config.dirs.tmp, r"%s/\1" % config.dirs.functions, path)
107-
108104
if config.is_in_docker:
109105
volume = get_default_volume_dir_mount()
110106

‎tests/bootstrap/test_cli.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import localstack.utils.container_utils.docker_cmd_client
99
from localstack import config, constants
1010
from localstack.cli.localstack import localstack as cli
11-
from localstack.config import DOCKER_SOCK, get_edge_url, in_docker
11+
from localstack.config import get_edge_url, in_docker
1212
from localstack.constants import MODULE_MAIN_PATH
1313
from localstack.utils.bootstrap import in_ci
1414
from localstack.utils.common import poll_condition
@@ -117,34 +117,6 @@ def test_custom_docker_flags(self, runner, tmp_path, monkeypatch, container_clie
117117
assert "42069/tcp" in inspect["HostConfig"]["PortBindings"]
118118
assert f"{volume}:{volume}" in inspect["HostConfig"]["Binds"]
119119

120-
@pytest.mark.skipif(
121-
condition=not config.LEGACY_DIRECTORIES, reason="this test targets LEGACY_DIRECTORIES=1"
122-
)
123-
def test_directories_mounted_correctly(self, runner, tmp_path, monkeypatch, container_client):
124-
data_dir = tmp_path / "data_dir"
125-
tmp_folder = tmp_path / "tmp"
126-
127-
# set different directories and make sure they are mounted correctly
128-
monkeypatch.setenv("DATA_DIR", str(data_dir))
129-
monkeypatch.setattr(config, "DATA_DIR", str(data_dir))
130-
monkeypatch.setattr(config, "TMP_FOLDER", str(tmp_folder))
131-
# reload directories from manipulated config
132-
monkeypatch.setattr(config, "dirs", config.Directories.legacy_from_config())
133-
134-
runner.invoke(cli, ["start", "-d"])
135-
runner.invoke(cli, ["wait", "-t", "60"])
136-
137-
# check that mounts were created correctly
138-
inspect = container_client.inspect_container(config.MAIN_CONTAINER_NAME)
139-
container_dirs = config.Directories.for_container()
140-
binds = inspect["HostConfig"]["Binds"]
141-
assert f"{tmp_folder}:{container_dirs.tmp}" in binds
142-
assert f"{data_dir}:{container_dirs.data}" in binds
143-
assert f"{DOCKER_SOCK}:{DOCKER_SOCK}" in binds
144-
145-
@pytest.mark.skipif(
146-
condition=config.LEGACY_DIRECTORIES, reason="this test targets LEGACY_DIRECTORIES=0"
147-
)
148120
def test_volume_dir_mounted_correctly(self, runner, tmp_path, monkeypatch, container_client):
149121
volume_dir = tmp_path / "volume"
150122

0 commit comments

Comments
 (0)