Skip to content

Self-improving AI Employees for everyone

fix(deploy): make the AWS module boot cleanly and keep install.sh in step with the release

trohitg6830e70aa646
diff --git a/.gitignore b/.gitignore
index 44e03969..78b897f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -173,3 +173,8 @@ server/experiments/
# Terraform provider cache (cli/terraform/*)
**/.terraform/
+# Terraform state and variable files carry secrets (owner password, JWT keys)
+cli/terraform/**/*.tfstate
+cli/terraform/**/*.tfstate.*
+cli/terraform/**/*.tfvars
+cli/terraform/**/*.tfvars.json
diff --git a/cli/terraform/aws/README.md b/cli/terraform/aws/README.md
index f9163f22..36dac4fc 100644
--- a/cli/terraform/aws/README.md
+++ b/cli/terraform/aws/README.md
@@ -12,9 +12,10 @@ Settings are the ones validated on a live t3.micro in September 2026:
| Instance | `t3.micro`, 2 vCPU, 1 GiB | Smallest size the app runs on (backend ~200 MB + Temporal ~150 MB). 512 MB OOM-loops. |
| Credit mode | `standard` | Caps compute at the hourly rate under continuous CPU load. |
| Root disk | 10 GiB gp3, deleted with the instance | A fresh install uses ~4.5 GiB. |
-| Image | Ubuntu 24.04 LTS (Canonical) | Python 3.12 inside the server's `<3.13` pin; apt Node 18 is enough. |
+| Image | Ubuntu 24.04 LTS (Canonical) | Python 3.12 inside the server's `<3.13` pin. |
+| Node | current LTS from NodeSource when none is present; an existing 18+ is kept | The published package may still require 22. |
| Install | `install.sh` as `ubuntu`, no sudo | Root installs leave the venvs unusable by the login user (errors.md #16). |
-| Runtime | `company serve` under systemd as `ubuntu` | `AmbientCapabilities=CAP_NET_BIND_SERVICE` for port 80. |
+| Runtime | `company serve` under systemd as `ubuntu` on port 5678 | The server rejects ports below 1024; 80/443 stay free for a TLS front door. |
| Security group | 22, 80, 443 and the app port from `allow_cidr` | Same shape as the gcp module. |
```bash
@@ -27,11 +28,18 @@ terraform apply -var key_name=<your-key-pair> -var opencompany_version=0.1.1 \
terraform output url
```
-`app_env` carries the owner login, fresh JWT/encryption keys, `PORT=80`,
+`app_env` carries the owner login, fresh JWT/encryption keys, `PORT=5678`,
`DATA_DIR=/var/lib/opencompany` and `TEMPORAL_ENABLED=false`. Generate it with
`cli/commands/deploy/_secrets.py build_app_env(owner_email=..., owner_password=...,
-port=80)` and write it as `{"app_env": {...}}` to `app_env.auto.tfvars.json`
-(gitignored) rather than typing it by hand. First boot takes 3 to 5 minutes.
+port=5678)` and write it as `{"app_env": {...}}` to `app_env.auto.tfvars.json`
+(gitignored) rather than typing it by hand. First boot takes about 10 minutes
+on a t3.micro. Changing `app_env` or the boot script later does not recreate
+the instance; the new user data only runs on a fresh one.
+
+First boot fetches `https://opencompany.sh/install.sh` (override with
+`install_sh_url`), and that script asks `https://opencompany.sh/version` for
+the release unless `opencompany_version` is set. Both endpoints must be served
+from the opencompany.sh site.
Uses the AWS CLI's default credential chain. `company deploy` cannot drive this
module yet; it needs an AWS entry in `cli/commands/deploy/providers`.
diff --git a/cli/terraform/aws/main.tf b/cli/terraform/aws/main.tf
index c2fd2468..9ffb9827 100644
--- a/cli/terraform/aws/main.tf
+++ b/cli/terraform/aws/main.tf
@@ -61,11 +61,11 @@ resource "aws_instance" "app_server" {
}
user_data = templatefile("${path.module}/startup.sh.tftpl", {
- instance_name = var.instance_name
- version = var.opencompany_version
- app_env = var.app_env
+ instance_name = var.instance_name
+ version = var.opencompany_version
+ install_sh_url = var.install_sh_url
+ app_env = var.app_env
})
- user_data_replace_on_change = true
tags = {
Name = var.instance_name
diff --git a/cli/terraform/aws/startup.sh.tftpl b/cli/terraform/aws/startup.sh.tftpl
index 8c81a39e..3222e096 100644
--- a/cli/terraform/aws/startup.sh.tftpl
+++ b/cli/terraform/aws/startup.sh.tftpl
@@ -16,7 +16,7 @@ export DEBIAN_FRONTEND=noninteractive
APP_USER=ubuntu
APP_HOME=/home/$APP_USER
-INSTALL_SH=https://raw.githubusercontent.com/zeenie-ai/OpenCompany/main/install.sh
+INSTALL_SH='${install_sh_url}'
echo "[${instance_name}] installing OpenCompany as $APP_USER..."
sudo -u $APP_USER -H env OPENCOMPANY_VERSION="${version}" \
@@ -37,9 +37,10 @@ mkdir -p /var/lib/${instance_name}
chown $APP_USER:$APP_USER /var/lib/${instance_name}
echo "[${instance_name}] installing systemd service..."
-# install.sh uses ~/.npm-global when the global prefix is not writable (the
-# apt Node case); otherwise the shim lands on the system path.
-OPENCOMPANY_BIN=$(ls $APP_HOME/.npm-global/bin/company /usr/local/bin/company /usr/bin/company 2>/dev/null | head -1)
+# The shim lives under the user's npm global prefix (install.sh points it at
+# ~/.npm-global when the system prefix is not writable).
+OPENCOMPANY_BIN="$(sudo -u $APP_USER -H npm prefix -g)/bin/company"
+test -x "$OPENCOMPANY_BIN"
cat > /etc/systemd/system/${instance_name}.service <<SERVICE_EOF
[Unit]
Description=OpenCompany (single login-gated instance)
@@ -52,8 +53,6 @@ User=$APP_USER
WorkingDirectory=$APP_HOME
EnvironmentFile=/etc/${instance_name}/opencompany.env
ExecStart=$OPENCOMPANY_BIN serve
-# Lets the unprivileged service bind port 80 (inherited by the uvicorn child).
-AmbientCapabilities=CAP_NET_BIND_SERVICE
Restart=on-failure
RestartSec=5
TimeoutStopSec=20
diff --git a/cli/terraform/aws/variables.tf b/cli/terraform/aws/variables.tf
index 4ffb9c11..30dfb6b9 100644
--- a/cli/terraform/aws/variables.tf
+++ b/cli/terraform/aws/variables.tf
@@ -29,9 +29,9 @@ variable "key_name" {
}
variable "port" {
- description = "Public port the app binds and the security group opens."
+ description = "Public port the app binds and the security group opens. The server rejects ports below 1024; 80/443 are left for a TLS front door."
type = number
- default = 80
+ default = 5678
}
variable "allow_cidr" {
@@ -46,6 +46,12 @@ variable "opencompany_version" {
default = ""
}
+variable "install_sh_url" {
+ description = "URL of the OpenCompany install script the first boot runs. Override to test an unreleased installer."
+ type = string
+ default = "https://opencompany.sh/install.sh"
+}
+
variable "app_env" {
description = "KEY=VALUE map rendered into the VM's systemd EnvironmentFile. Generate with cli/commands/deploy/_secrets.py build_app_env(port=<port>)."
type = map(string)
diff --git a/cli/tests/test_cli_branding.py b/cli/tests/test_cli_branding.py
index 4e7a4900..791e5409 100644
--- a/cli/tests/test_cli_branding.py
+++ b/cli/tests/test_cli_branding.py
@@ -55,7 +55,10 @@ def test_installers_target_scoped_package_without_touching_unscoped_package():
).read_text(encoding="utf-8"),
}
- assert "npm install -g '@zeenie-ai/opencompany'" in installers["install.sh"]
+ # install.sh builds the spec (optionally pinned by OPENCOMPANY_VERSION)
+ # into $PKG before the single `npm install -g "$PKG"` call.
+ assert 'PKG="@zeenie-ai/opencompany${VERSION:+@$VERSION}"' in installers["install.sh"]
+ assert 'npm install -g "$PKG"' in installers["install.sh"]
assert 'npm install -g "@zeenie-ai/opencompany"' in installers["install.ps1"]
assert "npm install -g @zeenie-ai/opencompany@${version}" in installers["gcp startup"]
diff --git a/install.sh b/install.sh
index f6e5c63d..64f4ab78 100755
--- a/install.sh
+++ b/install.sh
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
# OpenCompany Installer
-# Usage: curl -fsSL https://raw.githubusercontent.com/zeenie-ai/OpenCompany/main/install.sh | bash
+# Usage: curl -fsSL https://opencompany.sh/install.sh | bash
+#
+# Served from opencompany.sh (not the GitHub raw URL) so installs are
+# trackable. The release to install comes from https://opencompany.sh/version
+# unless OPENCOMPANY_VERSION is set.
#
# This script installs OpenCompany and its dependencies:
# - Node.js 18+ (distro package via brew/apt/dnf/pacman)
@@ -155,10 +159,11 @@ install_node() {
fi
;;
debian)
- # The distro package is enough: Ubuntu 24.04 / Debian 12 ship Node 18,
- # Ubuntu 26.04 ships 22. No third-party apt repo needed.
- sudo apt-get update
- sudo apt-get install -y nodejs npm
+ # An existing Node >= 18 is kept (checked above). When none is
+ # present, install the current LTS: the published package may still
+ # require it, and Ubuntu 24.04's apt package is 18.
+ curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
+ sudo apt-get install -y nodejs
# Force rehash PATH to find newly installed node
hash -r 2>/dev/null || true
# Source profile to update PATH if needed
@@ -314,8 +319,11 @@ main() {
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> "$HOME/.bashrc"
fi
fi
- # OPENCOMPANY_VERSION pins a release (used by cli/terraform startup scripts).
- PKG="@zeenie-ai/opencompany${OPENCOMPANY_VERSION:+@$OPENCOMPANY_VERSION}"
+ # OPENCOMPANY_VERSION pins a release (the cli/terraform startup scripts set
+ # it). Otherwise ask opencompany.sh which release is current; if that is
+ # unreachable, fall back to npm's latest tag.
+ VERSION="${OPENCOMPANY_VERSION:-$(curl -fsSL --max-time 10 https://opencompany.sh/version 2>/dev/null | tr -d '[:space:]' || true)}"
+ PKG="@zeenie-ai/opencompany${VERSION:+@$VERSION}"
npm install -g "$PKG" || error_exit "npm install -g $PKG failed."
echo ""