Skip to content

Commit d3d78a3

Browse files
committed
feat: allow devcontainer discovery more than one folder deep
1 parent 2efb7b6 commit d3d78a3

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

bin/init.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
66
source "$SCRIPT_DIR/lib/detect-devcontainer.sh"
77

88
## Find the devcontainer folder
9-
DEVCONTAINER_FOLDER=$(find_devcontainer_folder)
10-
11-
if [ -z "$DEVCONTAINER_FOLDER" ]; then
9+
if ! DEVCONTAINER_FOLDER=$(find_devcontainer_folder); then
1210
echo "Error: Could not find magento2-devcontainer folder in .devcontainer/"
1311
echo "Ensure you have cloned the magento2-devcontainer repo as a submodule."
1412
exit 1
1513
fi
1614

1715
FOLDER_NAME=$(basename "$DEVCONTAINER_FOLDER")
16+
TARGET_DIR=$(dirname "$DEVCONTAINER_FOLDER")
1817
echo "Using devcontainer folder: $DEVCONTAINER_FOLDER"
18+
echo "Target directory: $TARGET_DIR"
1919

2020
## Get available Magento versions from compose folder
2121
get_available_versions() {
@@ -87,17 +87,17 @@ read -p "Enter a name for your devcontainer (it should be unique per project) [$
8787
DEVCONTAINER_NAME="${DEVCONTAINER_NAME:-$FOLDER_NAME}"
8888

8989
## Copy over required docker-compose.yml.
90-
cp "$DEVCONTAINER_FOLDER/docker-compose.overrides.yml.sample" .devcontainer/docker-compose.overrides.yml
91-
echo "services: {}" > .devcontainer/docker-compose.yml
90+
cp "$DEVCONTAINER_FOLDER/docker-compose.overrides.yml.sample" "$TARGET_DIR/docker-compose.overrides.yml"
91+
echo "services: {}" > "$TARGET_DIR/docker-compose.yml"
9292

9393
## Copy over devcontainer and set the name and version
94-
cp "$DEVCONTAINER_FOLDER/devcontainer.json.sample" .devcontainer/devcontainer.json
95-
sed -i "s/\"name\": \"My Project Magento\"/\"name\": \"$DEVCONTAINER_NAME\"/" .devcontainer/devcontainer.json
96-
sed -i "s|$FOLDER_NAME/compose/[0-9]\+\.[0-9]\+\.[0-9]\+/|$FOLDER_NAME/compose/$SELECTED_VERSION/|g" .devcontainer/devcontainer.json
94+
cp "$DEVCONTAINER_FOLDER/devcontainer.json.sample" "$TARGET_DIR/devcontainer.json"
95+
sed -i "s/\"name\": \"My Project Magento\"/\"name\": \"$DEVCONTAINER_NAME\"/" "$TARGET_DIR/devcontainer.json"
96+
sed -i "s|$FOLDER_NAME/compose/[0-9]\+\.[0-9]\+\.[0-9]\+/|$FOLDER_NAME/compose/$SELECTED_VERSION/|g" "$TARGET_DIR/devcontainer.json"
9797

9898
## Copy .env.sample and set the project name
99-
cp "$DEVCONTAINER_FOLDER/.env.sample" .devcontainer/.env
100-
sed -i "s/COMPOSE_PROJECT_NAME=\"magento2-devcontainer\"/COMPOSE_PROJECT_NAME=\"$DEVCONTAINER_NAME\"/" .devcontainer/.env
99+
cp "$DEVCONTAINER_FOLDER/.env.sample" "$TARGET_DIR/.env"
100+
sed -i "s/COMPOSE_PROJECT_NAME=\"magento2-devcontainer\"/COMPOSE_PROJECT_NAME=\"$DEVCONTAINER_NAME\"/" "$TARGET_DIR/.env"
101101

102102
echo ""
103103
echo "Devcontainer '$DEVCONTAINER_NAME' initialized successfully."

bin/lib/detect-devcontainer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ find_devcontainer_folder() {
1919
if [ -d "$dir/compose" ]; then
2020
folders+=("$dir")
2121
fi
22-
done < <(find .devcontainer -mindepth 1 -maxdepth 1 -type d -print0 2>/dev/null)
22+
done < <(find .devcontainer -mindepth 1 -maxdepth 2 -type d -print0 2>/dev/null)
2323

2424
if [ ${#folders[@]} -eq 0 ]; then
2525
return 1

0 commit comments

Comments
 (0)