@australiawow/setup-dev-stack 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/setup-dev-stack.sh +53 -58
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@australiawow/setup-dev-stack",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Automated Nginx/SSL/Docker Stack Orchestrator",
5
5
  "main": "setup-dev-stack.sh",
6
6
  "bin": {
@@ -2,63 +2,82 @@
2
2
 
3
3
  # --- Technical Specification ---
4
4
  # Name: setup-dev-stack.sh
5
- # Version: 7.0 (NPM/GitHub Edition)
5
+ # Version: 2.0.0 (Self-Healing Edition)
6
6
  # ----------------------------------------------------------------
7
7
 
8
- # 1. Self-Elevate to sudo if not already
8
+ # MODULE 0: NATIVE DEPENDENCY CHECK (Runs as User)
9
+ echo "Step 1/6: Verifying Native Dependencies..."
10
+
11
+ # Check for Homebrew
12
+ if ! command -v brew >/dev/null 2>&1; then
13
+ echo "Fact: Homebrew not detected. Installing..."
14
+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
15
+ fi
16
+
17
+ # Check and Install Nginx/mkcert
18
+ for tool in nginx mkcert; do
19
+ if ! command -v $tool >/dev/null 2>&1; then
20
+ echo "Fact: $tool missing. Installing via Homebrew..."
21
+ brew install $tool
22
+ else
23
+ echo "Fact: $tool detected."
24
+ fi
25
+ done
26
+
27
+ # MODULE 1: PRIVILEGE ELEVATION (The Switch)
9
28
  if [[ $EUID -ne 0 ]]; then
29
+ echo "Fact: Dependencies synced. Elevating to sudo for Networking/Nginx..."
10
30
  exec sudo "$0" "$@"
11
31
  exit $?
12
32
  fi
13
33
 
34
+ # From here on, we are ROOT
14
35
  clear
15
36
  echo "------------------------------------------------"
16
- echo "🚀 SETUP-DEV-STACK: INTERACTIVE SETUP"
37
+ echo "🚀 NHAGUE DEV-STACK: INTERACTIVE SETUP"
17
38
  echo "------------------------------------------------"
18
39
 
19
- # 2. Prompts
40
+ # MODULE 2: PROMPTS
20
41
  read -p "Enter Client Slug (e.g., companyx): " CLIENT
21
42
  read -p "Enter Domain (e.g., companyx.com): " DOMAIN
22
43
 
23
44
  CURRENT_DIR=$(pwd)
24
- echo "Current folder: $CURRENT_DIR"
25
- read -p "Is this the project root? (y/n): " IS_CURRENT
26
-
45
+ read -p "Is this the project root? ($CURRENT_DIR) (y/n): " IS_CURRENT
27
46
  if [[ "$IS_CURRENT" == "y" || "$IS_CURRENT" == "Y" ]]; then
28
47
  PROJECT_DIR=$CURRENT_DIR
29
48
  else
30
49
  read -p "Enter full path to project: " PROJECT_DIR
31
50
  fi
32
51
 
33
- # 3. Variables (Constants for your specific stack)
34
- H_PORT=8081
35
- K_PORT=8080
36
- PG_PORT=5050
37
- KONG_PORT=8000
38
- MINIO_PORT=9000
39
-
40
- # 4. Dependency Sync
41
- echo "Step 1/5: Syncing Native Dependencies..."
42
- for tool in nginx mkcert; do
43
- command -v $tool >/dev/null 2>&1 || brew install $tool
44
- done
45
- mkcert -install >/dev/null 2>&1
52
+ # MODULE 3: SSL AUTOMATION
53
+ echo "Step 3/6: Automating SSL Trust..."
54
+ # Fact: We must use the REAL_USER path for certs so they are accessible
55
+ REAL_USER=${SUDO_USER:-$(whoami)}
56
+ USER_HOME=$(eval echo "~$REAL_USER")
57
+ CERT_DIR="$USER_HOME/certs/$CLIENT"
46
58
 
47
- # 5. SSL Automation
48
- echo "Step 2/5: Automating SSL Trust..."
49
- CERT_DIR="$HOME/certs/$CLIENT"
50
59
  mkdir -p "$CERT_DIR"
51
- mkcert -cert-file "$CERT_DIR/cert.pem" -key-file "$CERT_DIR/key.pem" \
60
+ # Run mkcert as the real user to ensure it touches their local keychain
61
+ sudo -u "$REAL_USER" mkcert -install >/dev/null 2>&1
62
+ sudo -u "$REAL_USER" mkcert -cert-file "$CERT_DIR/cert.pem" -key-file "$CERT_DIR/key.pem" \
52
63
  "$DOMAIN" "*.$DOMAIN" "localhost" "127.0.0.1" >/dev/null 2>&1
53
64
 
54
- # 6. DNS Spoofing
55
- echo "Step 3/5: Updating /etc/hosts..."
65
+ # MODULE 4: DNS SPOOFING
66
+ echo "Step 4/6: Updating /etc/hosts..."
56
67
  sed -i '' "/$DOMAIN/d" /etc/hosts
57
68
  echo "127.0.0.1 api.$DOMAIN auth.$DOMAIN console.$DOMAIN db-admin.$DOMAIN app.$DOMAIN $DOMAIN" >> /etc/hosts
58
69
 
59
- # 7. Nginx Logic
60
- echo "Step 4/5: Configuring Nginx Gateway..."
61
- NGINX_SERVERS="/opt/homebrew/etc/nginx/servers"
70
+ # MODULE 5: NGINX GATEWAY
71
+ echo "Step 5/6: Configuring Nginx Gateway..."
72
+ NGINX_ROOT="/opt/homebrew/etc/nginx"
73
+ NGINX_SERVERS="$NGINX_ROOT/servers"
74
+ mkdir -p "$NGINX_SERVERS"
75
+
76
+ # Fact: Mapping your Five Star stack ports
77
+ H_PORT=8081
78
+ K_PORT=8080
79
+ KONG_PORT=8000
80
+
62
81
  cat <<EOF > "$NGINX_SERVERS/$CLIENT.conf"
63
82
  server {
64
83
  listen 443 ssl;
@@ -78,12 +97,6 @@ server {
78
97
  proxy_pass http://localhost:$K_PORT/auth;
79
98
  proxy_set_header Host \$host;
80
99
  proxy_buffer_size 128k;
81
- proxy_buffers 4 256k;
82
- }
83
-
84
- location /files {
85
- proxy_pass http://localhost:$MINIO_PORT;
86
- proxy_set_header Host \$host;
87
100
  }
88
101
 
89
102
  location / {
@@ -93,23 +106,10 @@ server {
93
106
  proxy_set_header X-Forwarded-Proto \$scheme;
94
107
  }
95
108
  }
96
-
97
- server {
98
- listen 443 ssl;
99
- server_name auth.$DOMAIN;
100
- ssl_certificate $CERT_DIR/cert.pem;
101
- ssl_certificate_key $CERT_DIR/key.pem;
102
- location / {
103
- proxy_pass http://localhost:$K_PORT;
104
- proxy_set_header Host \$host;
105
- proxy_buffer_size 128k;
106
- proxy_buffers 4 256k;
107
- }
108
- }
109
109
  EOF
110
110
 
111
- # 8. Docker Bridge
112
- echo "Step 5/5: Generating Docker Override..."
111
+ # MODULE 6: DOCKER BRIDGE
112
+ echo "Step 6/6: Generating Docker Override..."
113
113
  cat <<EOF > "$PROJECT_DIR/docker-compose.override.yml"
114
114
  version: '3.8'
115
115
  services:
@@ -120,19 +120,14 @@ services:
120
120
  auth-webhook:
121
121
  extra_hosts:
122
122
  - "auth.$DOMAIN:host.docker.internal"
123
- kong:
124
- extra_hosts:
125
- - "api.$DOMAIN:host.docker.internal"
126
- - "auth.$DOMAIN:host.docker.internal"
127
123
  EOF
128
124
 
129
- # Reset Ownership
130
- REAL_USER=${SUDO_USER:-$(whoami)}
131
125
  chown "$REAL_USER" "$PROJECT_DIR/docker-compose.override.yml"
132
126
  chown -R "$REAL_USER" "$CERT_DIR"
133
127
 
134
- # 9. Reload
135
- /opt/homebrew/bin/nginx -t && sudo /opt/homebrew/bin/brew services restart nginx
128
+ # RELOAD
129
+ echo "Reloading Nginx Native..."
130
+ /opt/homebrew/bin/nginx -t && /opt/homebrew/bin/brew services restart nginx
136
131
 
137
132
  echo "------------------------------------------------"
138
133
  echo "✅ SETUP SUCCESSFUL: $DOMAIN"