Skip to content

Commit 903aaf1

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 76161c2 commit 903aaf1

File tree

4 files changed

+148
-18
lines changed

4 files changed

+148
-18
lines changed

.devcontainer/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM mcr.microsoft.com/devcontainers/go:1.25-bookworm
2+
3+
# 1. Define the arguments to accept them from devcontainer.json
4+
ARG HTTP_PROXY
5+
ARG HTTPS_PROXY
6+
ARG NO_PROXY
7+
ARG http_proxy
8+
ARG https_proxy
9+
ARG no_proxy
10+
11+
# 2. Export them as environment variables
12+
ENV HTTP_PROXY=$HTTP_PROXY
13+
ENV HTTPS_PROXY=$HTTPS_PROXY
14+
ENV NO_PROXY=$NO_PROXY
15+
ENV http_proxy=$http_proxy
16+
ENV https_proxy=$https_proxy
17+
ENV no_proxy=$no_proxy
18+
19+
# 3. Ensure sudo keeps these variables (crucial for features that use sudo)
20+
RUN echo 'Defaults env_keep += "HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy"' >> /etc/sudoers
21+
22+
# 4. Prime the apt cache with proxy settings active
23+
RUN apt-get update

.devcontainer/devcontainer.json

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,55 @@
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": "Console Go",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"build": {
7+
"dockerfile": "Dockerfile",
8+
"context": "..",
9+
"args": {
10+
"HTTP_PROXY": "${localEnv:HTTP_PROXY:}",
11+
"HTTPS_PROXY": "${localEnv:HTTPS_PROXY:}",
12+
"NO_PROXY": "${localEnv:NO_PROXY:}",
13+
"http_proxy": "${localEnv:http_proxy:}",
14+
"https_proxy": "${localEnv:https_proxy:}",
15+
"no_proxy": "${localEnv:no_proxy:}"
16+
}
17+
},
18+
// Features to add to the dev container. More info: https://containers.dev/features.
19+
// "features": {},
20+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
21+
"forwardPorts": [
22+
8181
23+
],
24+
"features": {
25+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
26+
"version": "latest",
27+
"moby": true
28+
},
29+
"ghcr.io/devcontainers/features/node:1": {
30+
"version": "lts"
31+
},
32+
"ghcr.io/devcontainers/features/common-utils:2": {
33+
"installZsh": true,
34+
"configureZshAsDefaultShell": true,
35+
"installOhMyZsh": true,
36+
"upgradePackages": true
37+
}
38+
},
39+
"containerEnv": {
40+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
41+
"HTTP_PROXY": "${localEnv:HTTP_PROXY:}",
42+
"HTTPS_PROXY": "${localEnv:HTTPS_PROXY:}",
43+
"NO_PROXY": "${localEnv:NO_PROXY:}",
44+
"http_proxy": "${localEnv:http_proxy:}",
45+
"https_proxy": "${localEnv:https_proxy:}",
46+
"no_proxy": "${localEnv:no_proxy:}"
47+
},
48+
// Use 'postCreateCommand' to run commands after the container is created.
49+
"postCreateCommand": "sed -i 's/\\r$//' .devcontainer/post-create.sh && /bin/bash .devcontainer/post-create.sh"
50+
51+
// Configure tool-specific properties.
52+
// "customizations": {},
53+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
54+
// "remoteUser": "root"
1955
}

.devcontainer/post-create.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
if [ -n "$HTTP_PROXY" ] || [ -n "$http_proxy" ] || [ -n "$HTTPS_PROXY" ] || [ -n "$https_proxy" ]; then
32+
echo "Configuring Docker daemon proxy..."
33+
docker_http_proxy="${HTTP_PROXY:-${http_proxy:-}}"
34+
docker_https_proxy="${HTTPS_PROXY:-${https_proxy:-}}"
35+
docker_no_proxy="${NO_PROXY:-${no_proxy:-}}"
36+
sudo mkdir -p /etc/docker
37+
sudo tee /etc/docker/daemon.json > /dev/null <<EOF
38+
{
39+
"proxies": {
40+
"httpProxy": "${docker_http_proxy}",
41+
"httpsProxy": "${docker_https_proxy}",
42+
"noProxy": "${docker_no_proxy}"
43+
}
44+
}
45+
EOF
46+
47+
if command -v systemctl >/dev/null 2>&1 && systemctl is-active --quiet docker; then
48+
sudo systemctl restart docker
49+
elif command -v service >/dev/null 2>&1 && service docker status >/dev/null 2>&1; then
50+
sudo service docker restart
51+
elif [ -x /usr/local/share/docker-init.sh ]; then
52+
sudo pkill dockerd || true
53+
sudo /usr/local/share/docker-init.sh >/tmp/docker-init.log 2>&1 || sudo /usr/local/share/docker-init.sh
54+
fi
55+
fi
56+
57+
echo "Installing runtime dependencies..."
58+
sudo apt-get update
59+
sudo apt-get install -y dbus dbus-x11 xdg-utils libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb
60+
61+
go install github.com/air-verse/air@latest
62+
go install github.com/go-delve/delve/cmd/dlv@latest

build.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@
66

77
# Get version from the first argument
88
version=$1
9+
# Set proxy environment variables only if they have values
10+
[ -n "${HTTP_PROXY:-${http_proxy:-}}" ] && export HTTP_PROXY="${HTTP_PROXY:-${http_proxy:-}}"
11+
[ -n "${HTTPS_PROXY:-${https_proxy:-}}" ] && export HTTPS_PROXY="${HTTPS_PROXY:-${https_proxy:-}}"
12+
[ -n "${NO_PROXY:-${no_proxy:-}}" ] && export NO_PROXY="${NO_PROXY:-${no_proxy:-localhost,127.0.0.1}}"
913

1014
# Build Docker images for each variant
1115
# Full build (with UI)
12-
docker build -t vprodemo.azurecr.io/console:v$version \
13-
-t vprodemo.azurecr.io/console:latest .
16+
docker build --build-arg HTTP_PROXY="$HTTP_PROXY" \
17+
--build-arg HTTPS_PROXY="$HTTPS_PROXY" \
18+
--build-arg NO_PROXY="$NO_PROXY" \
19+
-t vprodemo.azurecr.io/console:v$version \
20+
-t vprodemo.azurecr.io/console:latest .
1421

1522
# Headless build (No UI)
16-
docker build --build-arg BUILD_TAGS="noui" \
23+
docker build --build-arg HTTP_PROXY="$HTTP_PROXY" \
24+
--build-arg HTTPS_PROXY="$HTTPS_PROXY" \
25+
--build-arg NO_PROXY="$NO_PROXY" --build-arg BUILD_TAGS="noui" \
1726
-t vprodemo.azurecr.io/console:v$version-headless \
1827
-t vprodemo.azurecr.io/console:latest-headless .
1928

0 commit comments

Comments
 (0)