Skip to content

Commit c081b1b

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 f3c3926 commit c081b1b

File tree

5 files changed

+259
-18
lines changed

5 files changed

+259
-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

.devcontainer/pre-create.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
# This script runs on the host machine BEFORE the container is created.
4+
5+
TEMPLATE_FILE=".env.template"
6+
OUTPUT_FILE=".env"
7+
KONG_FILE="kong.yaml"
8+
CYPRESS_CONFIG="sample-web-ui/cypress.config.ts"
9+
README_FILE="Readme.md"
10+
REPO_TYPE=""
11+
12+
# Function to validate repository
13+
validate_repository() {
14+
if [ -f "$README_FILE" ] && grep -q "Device Management Toolkit (formerly known as Open AMT Cloud Toolkit)" "$README_FILE"; then
15+
REPO_TYPE="DMT"
16+
echo "✓ Detected: Device Management Toolkit repository"
17+
return 0
18+
fi
19+
20+
echo "✗ Error: Unrecognized repository. This script must be run from the Device Management Toolkit repository."
21+
exit 1
22+
}
23+
24+
# Function to handle DMT-specific operations
25+
dmt_operations() {
26+
echo "=========================================="
27+
echo "Environment Configuration Setup"
28+
echo "=========================================="
29+
30+
dmt_generate_defaults
31+
dmt_populate_env_file
32+
dmt_update_kong_config
33+
dmt_update_cypress_config
34+
35+
echo "=========================================="
36+
echo "Configuration complete!"
37+
echo "=========================================="
38+
}
39+
40+
# Function to generate default values for DMT
41+
dmt_generate_defaults() {
42+
DEFAULT_MPS_COMMON_NAME=$(hostname -I | awk '{print $1}') # Automatically detected system IP address
43+
DEFAULT_MPS_WEB_ADMIN_USER="hspeoob" # Default admin username for MPS web interface
44+
DEFAULT_MPS_WEB_ADMIN_PASSWORD="Apple-1234" # Default admin password for MPS web interface
45+
DEFAULT_MPS_JWT_SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) # Randomly generated 32-char JWT secret
46+
DEFAULT_MPS_JWT_ISSUER=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) # Randomly generated 32-char JWT issuer key
47+
DEFAULT_POSTGRES_PASSWORD="Apple-1234" # Default PostgreSQL database password
48+
DEFAULT_VAULT_TOKEN=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) # Randomly generated 32-char Vault token
49+
}
50+
51+
# Function to populate .env file for DMT
52+
dmt_populate_env_file() {
53+
if [ -f "$OUTPUT_FILE" ] && grep -qE "^MPS_JWT_SECRET=.+$" "$OUTPUT_FILE"; then
54+
echo "✓ Existing .env with MPS_JWT_SECRET found; skipping .env generation."
55+
return 0
56+
fi
57+
58+
echo "Creating and populating .env file..."
59+
cp "$TEMPLATE_FILE" "$OUTPUT_FILE"
60+
61+
sed -i "s|^MPS_COMMON_NAME=.*|MPS_COMMON_NAME=$DEFAULT_MPS_COMMON_NAME|" "$OUTPUT_FILE"
62+
sed -i "s|^MPS_WEB_ADMIN_USER=.*|MPS_WEB_ADMIN_USER=$DEFAULT_MPS_WEB_ADMIN_USER|" "$OUTPUT_FILE"
63+
sed -i "s|^MPS_WEB_ADMIN_PASSWORD=.*|MPS_WEB_ADMIN_PASSWORD=$DEFAULT_MPS_WEB_ADMIN_PASSWORD|" "$OUTPUT_FILE"
64+
sed -i "s|^MPS_JWT_SECRET=.*|MPS_JWT_SECRET=$DEFAULT_MPS_JWT_SECRET|" "$OUTPUT_FILE"
65+
sed -i "s|^MPS_JWT_ISSUER=.*|MPS_JWT_ISSUER=$DEFAULT_MPS_JWT_ISSUER|" "$OUTPUT_FILE"
66+
sed -i "s|^POSTGRES_PASSWORD=.*|POSTGRES_PASSWORD=$DEFAULT_POSTGRES_PASSWORD|" "$OUTPUT_FILE"
67+
sed -i "s|^VAULT_TOKEN=.*|VAULT_TOKEN=$DEFAULT_VAULT_TOKEN|" "$OUTPUT_FILE"
68+
69+
echo "✓ .env file has been created and populated with default values."
70+
}
71+
72+
# Function to update kong.yaml for DMT
73+
dmt_update_kong_config() {
74+
if [ -f "$KONG_FILE" ]; then
75+
echo "Updating kong.yaml with JWT secrets..."
76+
if grep -qE "^\s*secret:\s*[^[:space:]]+" "$KONG_FILE"; then
77+
echo "✓ Existing Kong JWT secret found; leaving unchanged."
78+
else
79+
sed -i "s|key: [a-zA-Z0-9]* #sample key|key: $DEFAULT_MPS_JWT_ISSUER #sample key|" "$KONG_FILE"
80+
sed -i -E "s|^(\s*secret:)\s*.*$|\1 \"$DEFAULT_MPS_JWT_SECRET\"|" "$KONG_FILE"
81+
echo "✓ kong.yaml has been updated with JWT secrets."
82+
fi
83+
else
84+
echo "⚠ Warning: kong.yaml not found, skipping Kong configuration."
85+
fi
86+
}
87+
88+
# Function to update cypress.config.ts for DMT
89+
dmt_update_cypress_config() {
90+
if [ -f "$CYPRESS_CONFIG" ]; then
91+
echo "Updating cypress.config.ts with credentials..."
92+
sed -i "s|MPS_USERNAME: '.*'|MPS_USERNAME: '$DEFAULT_MPS_WEB_ADMIN_USER'|" "$CYPRESS_CONFIG"
93+
sed -i "s|MPS_PASSWORD: '.*'|MPS_PASSWORD: '$DEFAULT_MPS_WEB_ADMIN_PASSWORD'|" "$CYPRESS_CONFIG"
94+
sed -i "s|VAULT_TOKEN: '.*'|VAULT_TOKEN: '$DEFAULT_VAULT_TOKEN'|" "$CYPRESS_CONFIG"
95+
echo "✓ cypress.config.ts has been updated with credentials."
96+
else
97+
echo "⚠ Warning: cypress.config.ts not found, skipping Cypress configuration."
98+
fi
99+
}
100+
101+
# Main execution
102+
main() {
103+
validate_repository
104+
105+
if [ "$REPO_TYPE" = "DMT" ]; then
106+
dmt_operations
107+
fi
108+
}
109+
110+
# Run main function
111+
main REPO_TYPE="DMT"

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)