From 80bad96194e54b3d80bbab8cf1e49c3d00f48c3b Mon Sep 17 00:00:00 2001 From: Nabendu Maiti Date: Fri, 12 Dec 2025 17:51:52 +0530 Subject: [PATCH 1/2] build: proxy use for devcontainer -> devcontainer can use proxies -> add cypress dependencies in devcontainer Signed-off-by: Nabendu Maiti --- .devcontainer/devcontainer.json | 27 ++++++++++++++++++++++++++- .devcontainer/post-create.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 .devcontainer/post-create.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 52cf686b8..93bcc730e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,14 +10,39 @@ "forwardPorts": [ 4200 ], + "containerEnv": { + "HTTP_PROXY": "${localEnv:http_proxy}", + "HTTPS_PROXY": "${localEnv:https_proxy}", + "NO_PROXY": "${localEnv:no_proxy}", + "http_proxy": "${localEnv:http_proxy}", + "https_proxy": "${localEnv:https_proxy}", + "no_proxy": "${localEnv:no_proxy}" + }, + "runArgs": [ + "--env", + "HTTP_PROXY=${env:http_proxy:-}", + "--env", + "HTTPS_PROXY=${env:https_proxy:-}", + "--env", + "NO_PROXY=${env:no_proxy:-}", + "--env", + "http_proxy=${env:http_proxy:-}", + "--env", + "https_proxy=${env:https_proxy:-}", + "--env", + "no_proxy=${env:no_proxy:-}" + ], + "portsAttributes": { "4200": { "label": "Angular Dev Server", "onAutoForward": "notify" } }, + // Use 'onCreateCommand' to run commands once when the container is created. + "onCreateCommand": "if [ -n \"$HTTP_PROXY\" ] || [ -n \"$HTTPS_PROXY\" ]; then sudo bash -c \"echo 'Acquire::http::Proxy \\\"'$HTTP_PROXY'\\\";' > /etc/apt/apt.conf.d/proxy.conf && echo 'Acquire::https::Proxy \\\"'$HTTPS_PROXY'\\\";' >> /etc/apt/apt.conf.d/proxy.conf\"; fi", // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "npm install" + "postCreateCommand": "/bin/bash .devcontainer/post-create.sh" // Configure tool-specific properties. // "customizations": {}, // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh new file mode 100755 index 000000000..5716c4de7 --- /dev/null +++ b/.devcontainer/post-create.sh @@ -0,0 +1,27 @@ + +#!/bin/bash +set -e + +# Unset empty proxy variables +for var in HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy; do + eval v="\${$var}" + if [ -z "$v" ]; then unset $var; fi +done + +# Configure apt proxy if proxies are present +if [ -n "$HTTP_PROXY" ] || [ -n "$http_proxy" ] || [ -n "$HTTPS_PROXY" ] || [ -n "$https_proxy" ]; then + echo "Configuring apt to use proxy..." + sudo mkdir -p /etc/apt/apt.conf.d + sudo tee /etc/apt/apt.conf.d/99proxy > /dev/null < Date: Sun, 14 Dec 2025 06:40:02 +0530 Subject: [PATCH 2/2] build: Add robust proxy handling - Add proxy handling for apt in different enviroments - fix non proxy env invalid error Signed-off-by: Nabendu Maiti --- .devcontainer/devcontainer.json | 31 +++++++------------------------ .devcontainer/post-create.sh | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 93bcc730e..6b4a900a0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,38 +11,21 @@ 4200 ], "containerEnv": { - "HTTP_PROXY": "${localEnv:http_proxy}", - "HTTPS_PROXY": "${localEnv:https_proxy}", - "NO_PROXY": "${localEnv:no_proxy}", - "http_proxy": "${localEnv:http_proxy}", - "https_proxy": "${localEnv:https_proxy}", - "no_proxy": "${localEnv:no_proxy}" + "HTTP_PROXY": "${localEnv:HTTP_PROXY:}", + "HTTPS_PROXY": "${localEnv:HTTPS_PROXY:}", + "NO_PROXY": "${localEnv:NO_PROXY:}", + "http_proxy": "${localEnv:http_proxy:}", + "https_proxy": "${localEnv:https_proxy:}", + "no_proxy": "${localEnv:no_proxy:}" }, - "runArgs": [ - "--env", - "HTTP_PROXY=${env:http_proxy:-}", - "--env", - "HTTPS_PROXY=${env:https_proxy:-}", - "--env", - "NO_PROXY=${env:no_proxy:-}", - "--env", - "http_proxy=${env:http_proxy:-}", - "--env", - "https_proxy=${env:https_proxy:-}", - "--env", - "no_proxy=${env:no_proxy:-}" - ], - "portsAttributes": { "4200": { "label": "Angular Dev Server", "onAutoForward": "notify" } }, - // Use 'onCreateCommand' to run commands once when the container is created. - "onCreateCommand": "if [ -n \"$HTTP_PROXY\" ] || [ -n \"$HTTPS_PROXY\" ]; then sudo bash -c \"echo 'Acquire::http::Proxy \\\"'$HTTP_PROXY'\\\";' > /etc/apt/apt.conf.d/proxy.conf && echo 'Acquire::https::Proxy \\\"'$HTTPS_PROXY'\\\";' >> /etc/apt/apt.conf.d/proxy.conf\"; fi", // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "/bin/bash .devcontainer/post-create.sh" + "postCreateCommand": "sed -i 's/\\r$//' .devcontainer/post-create.sh && /bin/bash .devcontainer/post-create.sh" // Configure tool-specific properties. // "customizations": {}, // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 5716c4de7..c5bea86c6 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -1,4 +1,3 @@ - #!/bin/bash set -e @@ -8,19 +7,27 @@ for var in HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy; do if [ -z "$v" ]; then unset $var; fi done -# Configure apt proxy if proxies are present +# Strip all trailing '/' or '\\' from proxy URLs for apt config +strip_trailing_slash() { + local url="$1" + # Remove all trailing / or \ + url="${url%%*(/|\\)}" + # Fallback for Bash < 4.0 (no extglob): use sed + echo "$url" | sed 's%[\\/]*$%%' +} + if [ -n "$HTTP_PROXY" ] || [ -n "$http_proxy" ] || [ -n "$HTTPS_PROXY" ] || [ -n "$https_proxy" ]; then echo "Configuring apt to use proxy..." sudo mkdir -p /etc/apt/apt.conf.d + # Remove all trailing / or \\ from proxy URLs + apt_http_proxy="$(strip_trailing_slash "${HTTP_PROXY:-${http_proxy:-}}")" + apt_https_proxy="$(strip_trailing_slash "${HTTPS_PROXY:-${https_proxy:-}}")" sudo tee /etc/apt/apt.conf.d/99proxy > /dev/null <