Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04

# 1. Define the arguments to accept them from devcontainer.json
ARG HTTP_PROXY
ARG HTTPS_PROXY
ARG NO_PROXY
ARG http_proxy
ARG https_proxy
ARG no_proxy

# 2. Export them as environment variables
ENV HTTP_PROXY=$HTTP_PROXY
ENV HTTPS_PROXY=$HTTPS_PROXY
ENV NO_PROXY=$NO_PROXY
ENV http_proxy=$http_proxy
ENV https_proxy=$https_proxy
ENV no_proxy=$no_proxy

# 3. Ensure sudo keeps these variables (crucial for features that use sudo)
RUN echo 'Defaults env_keep += "HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy"' >> /etc/sudoers

# 4. Prime the apt cache with proxy settings active
RUN apt-get update
64 changes: 64 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "Cloud Deployment Dev Container",
"build": {
"dockerfile": "Dockerfile",
"args": {
"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:}"
}
},
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"version": "latest",
"enableNonRootDocker": "true",
"moby": "true"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "lts"
},
"ghcr.io/devcontainers/features/go:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"upgradePackages": true
}
},
"containerEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
"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:}"
},
"forwardPorts": [
4200,
3000,
8081,
8003
],
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-docker",
"dbaeumer.vscode-eslint",
"golang.go",
"ms-vscode.cpptools",
"ryu1kn.text-marker",
"shardulm94.trailing-spaces",
"waderyan.gitblame",
"esbenp.prettier-vscode"
]
}
},
"initializeCommand": "sed -i 's/\\r$//' .devcontainer/post-create.sh && /bin/bash .devcontainer/pre-create.sh",
"postCreateCommand": "sed -i 's/\\r$//' .devcontainer/post-create.sh && /bin/bash .devcontainer/post-create.sh"
}
35 changes: 35 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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

# 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 <<EOF
Acquire::http::Proxy "$apt_http_proxy";
Acquire::https::Proxy "$apt_https_proxy";
EOF
fi

sudo apt-get update && sudo apt-get install -y build-essential cmake

go install github.com/air-verse/air@latest
go install github.com/go-delve/delve/cmd/dlv@latest
go install github.com/google/go-licenses@latest
111 changes: 111 additions & 0 deletions .devcontainer/pre-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash

# This script runs on the host machine BEFORE the container is created.

TEMPLATE_FILE=".env.template"
OUTPUT_FILE=".env"
KONG_FILE="kong.yaml"
CYPRESS_CONFIG="sample-web-ui/cypress.config.ts"
README_FILE="Readme.md"
REPO_TYPE=""

# Function to validate repository
validate_repository() {
if [ -f "$README_FILE" ] && grep -q "Device Management Toolkit (formerly known as Open AMT Cloud Toolkit)" "$README_FILE"; then
REPO_TYPE="DMT"
echo "✓ Detected: Device Management Toolkit repository"
return 0
fi

echo "✗ Error: Unrecognized repository. This script must be run from the Device Management Toolkit repository."
exit 1
}

# Function to handle DMT-specific operations
dmt_operations() {
echo "=========================================="
echo "Environment Configuration Setup"
echo "=========================================="

dmt_generate_defaults
dmt_populate_env_file
dmt_update_kong_config
dmt_update_cypress_config

echo "=========================================="
echo "Configuration complete!"
echo "=========================================="
}

# Function to generate default values for DMT
dmt_generate_defaults() {
DEFAULT_MPS_COMMON_NAME=$(hostname -I | awk '{print $1}') # Automatically detected system IP address
DEFAULT_MPS_WEB_ADMIN_USER="hspeoob" # Default admin username for MPS web interface
DEFAULT_MPS_WEB_ADMIN_PASSWORD="Apple-1234" # Default admin password for MPS web interface
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
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
DEFAULT_POSTGRES_PASSWORD="Apple-1234" # Default PostgreSQL database password
DEFAULT_VAULT_TOKEN=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) # Randomly generated 32-char Vault token
}

# Function to populate .env file for DMT
dmt_populate_env_file() {
if [ -f "$OUTPUT_FILE" ] && grep -qE "^MPS_JWT_SECRET=.+$" "$OUTPUT_FILE"; then
echo "✓ Existing .env with MPS_JWT_SECRET found; skipping .env generation."
return 0
fi

echo "Creating and populating .env file..."
cp "$TEMPLATE_FILE" "$OUTPUT_FILE"

sed -i "s|^MPS_COMMON_NAME=.*|MPS_COMMON_NAME=$DEFAULT_MPS_COMMON_NAME|" "$OUTPUT_FILE"
sed -i "s|^MPS_WEB_ADMIN_USER=.*|MPS_WEB_ADMIN_USER=$DEFAULT_MPS_WEB_ADMIN_USER|" "$OUTPUT_FILE"
sed -i "s|^MPS_WEB_ADMIN_PASSWORD=.*|MPS_WEB_ADMIN_PASSWORD=$DEFAULT_MPS_WEB_ADMIN_PASSWORD|" "$OUTPUT_FILE"
sed -i "s|^MPS_JWT_SECRET=.*|MPS_JWT_SECRET=$DEFAULT_MPS_JWT_SECRET|" "$OUTPUT_FILE"
sed -i "s|^MPS_JWT_ISSUER=.*|MPS_JWT_ISSUER=$DEFAULT_MPS_JWT_ISSUER|" "$OUTPUT_FILE"
sed -i "s|^POSTGRES_PASSWORD=.*|POSTGRES_PASSWORD=$DEFAULT_POSTGRES_PASSWORD|" "$OUTPUT_FILE"
sed -i "s|^VAULT_TOKEN=.*|VAULT_TOKEN=$DEFAULT_VAULT_TOKEN|" "$OUTPUT_FILE"

echo "✓ .env file has been created and populated with default values."
}

# Function to update kong.yaml for DMT
dmt_update_kong_config() {
if [ -f "$KONG_FILE" ]; then
echo "Updating kong.yaml with JWT secrets..."
if grep -qE "^\s*secret:\s*[^[:space:]]+" "$KONG_FILE"; then
echo "✓ Existing Kong JWT secret found; leaving unchanged."
else
sed -i "s|key: [a-zA-Z0-9]* #sample key|key: $DEFAULT_MPS_JWT_ISSUER #sample key|" "$KONG_FILE"
sed -i -E "s|^(\s*secret:)\s*.*$|\1 \"$DEFAULT_MPS_JWT_SECRET\"|" "$KONG_FILE"
echo "✓ kong.yaml has been updated with JWT secrets."
fi
else
echo "⚠ Warning: kong.yaml not found, skipping Kong configuration."
fi
}

# Function to update cypress.config.ts for DMT
dmt_update_cypress_config() {
if [ -f "$CYPRESS_CONFIG" ]; then
echo "Updating cypress.config.ts with credentials..."
sed -i "s|MPS_USERNAME: '.*'|MPS_USERNAME: '$DEFAULT_MPS_WEB_ADMIN_USER'|" "$CYPRESS_CONFIG"
sed -i "s|MPS_PASSWORD: '.*'|MPS_PASSWORD: '$DEFAULT_MPS_WEB_ADMIN_PASSWORD'|" "$CYPRESS_CONFIG"
sed -i "s|VAULT_TOKEN: '.*'|VAULT_TOKEN: '$DEFAULT_VAULT_TOKEN'|" "$CYPRESS_CONFIG"
echo "✓ cypress.config.ts has been updated with credentials."
else
echo "⚠ Warning: cypress.config.ts not found, skipping Cypress configuration."
fi
}

# Main execution
main() {
validate_repository

if [ "$REPO_TYPE" = "DMT" ]; then
dmt_operations
fi
}

# Run main function
main REPO_TYPE="DMT"
57 changes: 57 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Debug MPS (Node.js)",
"program": "${workspaceFolder}/mps/dist/index.js",
"cwd": "${workspaceFolder}/mps",
"envFile": "${workspaceFolder}/.env",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/mps/dist/**/*.js"
],
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "pwa-node",
"request": "launch",
"name": "Debug RPS (Node.js)",
"program": "${workspaceFolder}/rps/dist/Index.js",
"cwd": "${workspaceFolder}/rps",
"envFile": "${workspaceFolder}/.env",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/rps/dist/**/*.js"
],
"skipFiles": [
"<node_internals>/**"
]
},
{
"name": "Debug MPS Router (Go)",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/mps-router/cmd/main.go",
"cwd": "${workspaceFolder}/mps-router",
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Debug Web UI (Chrome)",
"type": "pwa-chrome",
"request": "launch",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}/sample-web-ui"
}
],
"compounds": [
{
"name": "Debug All Services",
"configurations": ["Debug MPS (Node.js)", "Debug RPS (Node.js)", "Debug MPS Router (Go)", "Debug Web UI (Chrome)"]
}
]
}
73 changes: 73 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Start Infrastructure",
"type": "shell",
"command": "docker-compose up -d db vault kong mosquitto consul",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"group": "build",
"problemMatcher": []
},
{
"label": "Stop Infrastructure",
"type": "shell",
"command": "docker-compose stop db vault kong mosquitto consul",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "Restart Infrastructure",
"type": "shell",
"command": "docker-compose restart db vault kong mosquitto consul",
"problemMatcher": []
},
{
"label": "Connect DevContainer to Network",
"type": "shell",
"command": "docker network connect $(docker network ls --filter name=openamtnetwork --format '{{.Name}}') $HOSTNAME || echo 'Already connected or network not found'",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
},
{
"label": "Build MPS",
"type": "typescript",
"tsconfig": "mps/tsconfig.build.json",
"group": "build"
},
{
"label": "Build RPS",
"type": "typescript",
"tsconfig": "rps/tsconfig.build.json",
"group": "build"
},
{
"label": "Serve WebUI (Angular)",
"type": "shell",
"command": "cd sample-web-ui && npm install && npm start -- --host 0.0.0.0",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "Compiling..."
},
"endsPattern": {
"regexp": "Compiled successfully"
}
}
}
}
]
}
Loading
Loading