Skip to content

Commit 8ad6bb9

Browse files
committed
build: proxy settings for build and devcontainer
-> devcontainer go version updated to 1.25 -> devcontainer updated to include proxy settings -> build script support proxy build Signed-off-by: Nabendu Maiti <nabendu.bikash.maiti@intel.com>
1 parent 0930500 commit 8ad6bb9

File tree

3 files changed

+68
-20
lines changed

3 files changed

+68
-20
lines changed

.devcontainer/devcontainer.json

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
22
// README at: https://github.com/devcontainers/templates/tree/main/src/go
33
{
4-
"name": "Go",
5-
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/go:dev-1-bullseye",
7-
// Features to add to the dev container. More info: https://containers.dev/features.
8-
// "features": {},
9-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
10-
"forwardPorts": [
11-
8181
12-
],
13-
// Use 'postCreateCommand' to run commands after the container is created.
14-
"postCreateCommand": "go install github.com/air-verse/air@v1.62.0"
15-
// Configure tool-specific properties.
16-
// "customizations": {},
17-
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
18-
// "remoteUser": "root"
4+
"name": "Go",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/go:1.25-trixie",
7+
// Features to add to the dev container. More info: https://containers.dev/features.
8+
// "features": {},
9+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
10+
"forwardPorts": [
11+
8181
12+
],
13+
"containerEnv": {
14+
"HTTP_PROXY": "${localEnv:HTTP_PROXY:}",
15+
"HTTPS_PROXY": "${localEnv:HTTPS_PROXY:}",
16+
"NO_PROXY": "${localEnv:NO_PROXY:}",
17+
"http_proxy": "${localEnv:http_proxy:}",
18+
"https_proxy": "${localEnv:https_proxy:}",
19+
"no_proxy": "${localEnv:no_proxy:}"
20+
},
21+
// Use 'postCreateCommand' to run commands after the container is created.
22+
"postCreateCommand": "/bin/bash .devcontainer/post-create.sh"
23+
24+
// Configure tool-specific properties.
25+
// "customizations": {},
26+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
27+
// "remoteUser": "root"
1928
}

.devcontainer/post-create.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Unset empty proxy variables
5+
for var in HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy; do
6+
eval v="\${$var}"
7+
if [ -z "$v" ]; then unset $var; fi
8+
done
9+
10+
# Strip all trailing '/' or '\\' from proxy URLs for apt config
11+
strip_trailing_slash() {
12+
local url="$1"
13+
# Remove all trailing / or \
14+
url="${url%%*(/|\\)}"
15+
# Fallback for Bash < 4.0 (no extglob): use sed
16+
echo "$url" | sed 's%[\\/]*$%%'
17+
}
18+
19+
if [ -n "$HTTP_PROXY" ] || [ -n "$http_proxy" ] || [ -n "$HTTPS_PROXY" ] || [ -n "$https_proxy" ]; then
20+
echo "Configuring apt to use proxy..."
21+
sudo mkdir -p /etc/apt/apt.conf.d
22+
# Remove all trailing / or \\ from proxy URLs
23+
apt_http_proxy="$(strip_trailing_slash "${HTTP_PROXY:-${http_proxy:-}}")"
24+
apt_https_proxy="$(strip_trailing_slash "${HTTPS_PROXY:-${https_proxy:-}}")"
25+
sudo tee /etc/apt/apt.conf.d/99proxy > /dev/null <<EOF
26+
Acquire::http::Proxy "$apt_http_proxy";
27+
Acquire::https::Proxy "$apt_https_proxy";
28+
EOF
29+
fi
30+
31+
go install github.com/air-verse/air@latest

build.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
# Get version from the first argument
44
version=$1
5+
# Set proxy environment variables only if they have values
6+
[ -n "${HTTP_PROXY:-${http_proxy:-}}" ] && export HTTP_PROXY="${HTTP_PROXY:-${http_proxy:-}}"
7+
[ -n "${HTTPS_PROXY:-${https_proxy:-}}" ] && export HTTPS_PROXY="${HTTPS_PROXY:-${https_proxy:-}}"
8+
[ -n "${NO_PROXY:-${no_proxy:-}}" ] && export NO_PROXY="${NO_PROXY:-${no_proxy:-localhost,127.0.0.1}}"
59

610
# Build Docker images for each variant
711
# Full build (with UI)
8-
docker build -t vprodemo.azurecr.io/console:v$version \
9-
-t vprodemo.azurecr.io/console:latest .
12+
docker build --build-arg HTTP_PROXY="$HTTP_PROXY" --build-arg HTTPS_PROXY="$HTTPS_PROXY" \
13+
--build-arg NO_PROXY="$NO_PROXY" \
14+
-t vprodemo.azurecr.io/console:v$version \
15+
-t vprodemo.azurecr.io/console:latest .
1016

1117
# Headless build (No UI)
12-
docker build --build-arg BUILD_TAGS="noui" \
13-
-t vprodemo.azurecr.io/console:v$version-headless \
14-
-t vprodemo.azurecr.io/console:latest-headless .
18+
docker build --build-arg --build-arg HTTP_PROXY="$HTTP_PROXY" \
19+
--build-arg HTTPS_PROXY="$HTTPS_PROXY" --build-arg NO_PROXY="$NO_PROXY" \
20+
--build-arg BUILD_TAGS="noui" \
21+
-t vprodemo.azurecr.io/console:v$version-headless \
22+
-t vprodemo.azurecr.io/console:latest-headless .
1523

1624
# Mark the Unix system outputs as executable
1725
chmod +x dist/linux/console_linux_x64

0 commit comments

Comments
 (0)