Skip to content

Commit 0b7c38a

Browse files
committed
feat: add devcontainer
-> Add devcontainer configuration for development environment setup. Signed-off-by: Nabendu Maiti <nabendu.bikash.maiti@intel.com>
1 parent 0b1129d commit 0b7c38a

4 files changed

Lines changed: 262 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "Go (MEI Device - Linux host)",
3+
"image": "mcr.microsoft.com/devcontainers/go:1.25-trixie",
4+
"features": {
5+
"ghcr.io/devcontainers/features/common-utils:2": {
6+
"installZsh": true,
7+
"installOhMyZsh": true,
8+
"installOhMyZshConfig": true,
9+
"configureZshAsDefaultShell": true
10+
}
11+
},
12+
"runArgs": [
13+
"--device",
14+
"/dev/mei0",
15+
"--privileged",
16+
"--net=host"
17+
],
18+
"remoteUser": "root",
19+
"forwardPorts": [
20+
8181
21+
],
22+
"containerEnv": {
23+
"HTTP_PROXY": "${localEnv:HTTP_PROXY:}",
24+
"HTTPS_PROXY": "${localEnv:HTTPS_PROXY:}",
25+
"NO_PROXY": "${localEnv:NO_PROXY:}",
26+
"http_proxy": "${localEnv:http_proxy:}",
27+
"https_proxy": "${localEnv:https_proxy:}",
28+
"no_proxy": "${localEnv:no_proxy:}"
29+
},
30+
"initializeCommand": "/bin/bash .devcontainer/pre-create.sh",
31+
"postCreateCommand": "/bin/bash .devcontainer/post-create.sh",
32+
"customizations": {
33+
"vscode": {
34+
"extensions": [
35+
"waderyan.gitblame",
36+
"shd101wyy.markdown-preview-enhanced",
37+
"artisanbytecrafter.poptheme",
38+
"ryu1kn.text-marker",
39+
"anoff.theme-monokai-light"
40+
],
41+
"settings": {
42+
"workbench.colorTheme": "Monokai Light",
43+
"workbench.preferredLightColorTheme": "Monokai Light"
44+
}
45+
}
46+
}
47+
}

.devcontainer/post-create.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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
32+
go install github.com/go-delve/delve/cmd/dlv@latest

.devcontainer/pre-create.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
3+
# This script runs on the host machine BEFORE the container is created.
4+
# It ensures the Intel LMS service is running.
5+
6+
echo "Checking LMS service status..."
7+
8+
# Skip LMS checks on non-Linux hosts.
9+
if [[ "$(uname -s)" != "Linux" ]]; then
10+
echo "Non-Linux host detected; skipping LMS service check."
11+
exit 0
12+
fi
13+
14+
check_lms_active() {
15+
if sudo systemctl is-active --quiet lms; then
16+
echo "LMS service is active."
17+
return 0
18+
else
19+
return 1
20+
fi
21+
}
22+
23+
prompt_timeout() {
24+
local msg="$1"
25+
local sec=10
26+
USER_INPUT=""
27+
while [ $sec -gt 0 ]; do
28+
echo -ne "\r$msg (timeout: ${sec}s) "
29+
if read -t 1 USER_INPUT; then
30+
echo ""
31+
return 0
32+
fi
33+
((sec--))
34+
done
35+
echo ""
36+
USER_INPUT="n"
37+
}
38+
39+
if check_lms_active; then
40+
exit 0
41+
fi
42+
43+
echo "LMS service is not active."
44+
45+
# Check if the service unit exists
46+
if sudo systemctl list-unit-files | grep -q "^lms.service"; then
47+
echo "LMS service exists but is inactive."
48+
49+
prompt_timeout "Do you want to start it? (y/n) [n]"
50+
answer="$USER_INPUT"
51+
52+
if [[ "$answer" =~ ^[Yy]$ ]]; then
53+
echo "Attempting to start LMS..."
54+
sudo systemctl start lms
55+
56+
# Wait for up to 10 seconds for service to start
57+
for i in {1..10}; do
58+
sleep 1
59+
if check_lms_active; then
60+
echo "LMS started successfully."
61+
exit 0
62+
fi
63+
done
64+
65+
echo "ERROR: Failed to start LMS service."
66+
sudo systemctl status lms
67+
exit 1
68+
else
69+
echo "Skipping LMS start. Proceeding with devcontainer creation..."
70+
exit 0
71+
fi
72+
fi
73+
74+
echo "LMS service not found."
75+
76+
prompt_timeout "Do you want to install and start it? (y/n) [n]"
77+
answer="$USER_INPUT"
78+
79+
if [[ "$answer" =~ ^[Yy]$ ]]; then
80+
# Proceed with installation
81+
echo "Proceeding with installation..."
82+
else
83+
echo "Skipping LMS installation. Proceeding with devcontainer creation..."
84+
exit 0
85+
fi
86+
87+
# Install dependencies
88+
echo "Installing dependencies..."
89+
# Update apt cache first (optional but recommended before installing)
90+
# sudo apt-get update
91+
sudo apt-get install -y cmake libglib2.0-dev libcurl4-openssl-dev libxerces-c-dev \
92+
libnl-3-dev libnl-route-3-dev libxml2-dev libidn2-0-dev libace-dev build-essential git
93+
94+
# Prepare working directory
95+
WORK_DIR="$HOME/lms_setup"
96+
mkdir -p "$WORK_DIR"
97+
echo "Working directory: $WORK_DIR"
98+
99+
if [ -d "$WORK_DIR/lms" ]; then
100+
echo "Cleaning up previous LMS source..."
101+
sudo rm -rf "$WORK_DIR/lms"
102+
fi
103+
104+
# Clone LMS
105+
echo "Cloning LMS repository..."
106+
git clone https://github.com/intel/lms.git "$WORK_DIR/lms"
107+
108+
# Build LMS
109+
echo "Building LMS..."
110+
cd "$WORK_DIR/lms"
111+
mkdir -p build
112+
cd build
113+
114+
# Using dynamic paths based on where we verified the clone
115+
sudo cmake -S .. -B .
116+
sudo cmake --build .
117+
118+
echo "Installing LMS..."
119+
sudo make install
120+
121+
echo "Starting LMS service..."
122+
sudo systemctl daemon-reload
123+
sudo systemctl enable lms
124+
sudo systemctl start lms
125+
126+
# Verify installation
127+
for i in {1..10}; do
128+
sleep 1
129+
if check_lms_active; then
130+
echo "LMS installed and started successfully."
131+
exit 0
132+
fi
133+
done
134+
135+
echo "ERROR: Failed to start LMS after installation."
136+
sudo systemctl status lms
137+
exit 1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/go
3+
{
4+
"name": "Go (Standard - no MEI device, only Lms supported)",
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+
"ghcr.io/devcontainers/features/common-utils:2": {
10+
"installZsh": true,
11+
"installOhMyZsh": true,
12+
"installOhMyZshConfig": true,
13+
"configureZshAsDefaultShell": true
14+
}
15+
},
16+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
17+
"forwardPorts": [
18+
8181
19+
],
20+
"containerEnv": {
21+
"HTTP_PROXY": "${localEnv:HTTP_PROXY:}",
22+
"HTTPS_PROXY": "${localEnv:HTTPS_PROXY:}",
23+
"NO_PROXY": "${localEnv:NO_PROXY:}",
24+
"http_proxy": "${localEnv:http_proxy:}",
25+
"https_proxy": "${localEnv:https_proxy:}",
26+
"no_proxy": "${localEnv:no_proxy:}"
27+
},
28+
// Use 'initializeCommand' to run commands on the host before the container is created.
29+
// "initializeCommand": "echo 'This runs on the host before container creation'",
30+
"initializeCommand": "/bin/bash .devcontainer/pre-create.sh",
31+
// Use 'postCreateCommand' to run commands after the container is created.
32+
"postCreateCommand": "/bin/bash .devcontainer/post-create.sh",
33+
"customizations": {
34+
"vscode": {
35+
"extensions": [
36+
"waderyan.gitblame",
37+
"shd101wyy.markdown-preview-enhanced",
38+
"artisanbytecrafter.poptheme",
39+
"ryu1kn.text-marker"
40+
],
41+
"settings": {
42+
"workbench.colorTheme": "Pop Light"
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)