From be556c76d9f7c215c2bb088169b615475d47949b Mon Sep 17 00:00:00 2001 From: Iain Sproat <68657+iainsproat@users.noreply.github.com> Date: Mon, 3 Mar 2025 09:19:43 +0000 Subject: [PATCH] chore(devcontainers): Move post create command to a script (#4090) - it can be linted and has IDE code-completion - we can add a lot more things to the script without sacrificing readability --- .devcontainer/devcontainer.json | 2 +- .devcontainer/postCreateCommand.sh | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100755 .devcontainer/postCreateCommand.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5f65b7580..418edea78 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -31,7 +31,7 @@ ], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "yarn && yarn build:public && cp -n /workspaces/${localWorkspaceFolderBasename}/packages/server/.env-example /workspaces/${localWorkspaceFolderBasename}/packages/server/.env && cp -n /workspaces/${localWorkspaceFolderBasename}/packages/frontend-2/.env.example /workspaces/${localWorkspaceFolderBasename}/packages/frontend-2/.env", + "postCreateCommand": "/workspaces/${localWorkspaceFolderBasename}/.devcontainer/postCreateCommand.sh", // Configure tool-specific properties. // "customizations": {}, diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100755 index 000000000..7b8817014 --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -eox pipefail + +echo "Running postCreateCommand.sh" + +# determine where the script is located, navigate into that directory, then find the root of the git repo in which it is located +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "${SCRIPT_DIR}" +GIT_ROOT="$(git rev-parse --show-toplevel)" + +echo "Setting up environment variables by copying .env files" +cp -n "${GIT_ROOT}/packages/server/.env-example" "${GIT_ROOT}/packages/server/.env" || true +cp -n "${GIT_ROOT}/packages/frontend-2/.env.example" "${GIT_ROOT}/packages/frontend-2/.env" || true + +echo "Installing nodejs dependencies and building shared packages" +yarn +yarn build:public