Build + Deploy Issue Bugfixes

- Changed .NET projects to target net472 so there's no need for runtime installs.
- Updated the build.sh script to handle deploying to targeted AWS regions by specifying the --region flag
- Removed hardcoded AMIs from the terrafrom deploy process
- Fixed some issues that come up when running the script from ARM architecture machines.
This commit is contained in:
Michael Weber
2025-08-13 19:55:08 -04:00
parent 782639293b
commit 6ce1e947b2
9 changed files with 72 additions and 28 deletions
+4 -3
View File
@@ -3,7 +3,7 @@ set -e
# Parse command line arguments # Parse command line arguments
DOMAIN_NAME="" DOMAIN_NAME=""
AWS_REGION="us-east-2" # Default region AWS_REGION="us-east-2" # Default region (matches build.sh default)
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
--domain) --domain)
@@ -51,9 +51,10 @@ cd "$DEPLOY_DIR"
# Create SSH key pair if it doesn't exist # Create SSH key pair if it doesn't exist
KEY_NAME="relay-proxy-key" KEY_NAME="relay-proxy-key"
if ! aws ec2 describe-key-pairs --key-names "$KEY_NAME" &> /dev/null; then if ! aws ec2 describe-key-pairs --region "$AWS_REGION" --key-names "$KEY_NAME" &> /dev/null; then
echo "Creating new SSH key pair..." echo "Creating new SSH key pair in region $AWS_REGION..."
aws ec2 create-key-pair \ aws ec2 create-key-pair \
--region "$AWS_REGION" \
--key-name "$KEY_NAME" \ --key-name "$KEY_NAME" \
--query 'KeyMaterial' \ --query 'KeyMaterial' \
--output text > "${KEY_NAME}.pem" --output text > "${KEY_NAME}.pem"
+40 -8
View File
@@ -4,6 +4,10 @@ terraform {
source = "hashicorp/aws" source = "hashicorp/aws"
version = "~> 5.0" version = "~> 5.0"
} }
random = {
source = "hashicorp/random"
version = "~> 3.1"
}
} }
required_version = ">= 1.2.0" required_version = ">= 1.2.0"
} }
@@ -12,9 +16,30 @@ provider "aws" {
region = var.aws_region region = var.aws_region
} }
# Random ID for unique resource names
resource "random_id" "deployment" {
byte_length = 4
}
# Data source to find the latest Amazon Linux 2023 AMI
data "aws_ami" "amazon_linux" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["al2023-ami-*-x86_64"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
# Security Group # Security Group
resource "aws_security_group" "relay_sg" { resource "aws_security_group" "relay_sg" {
name = "relay-security-group" name = "relay-security-group-${random_id.deployment.hex}"
description = "Security group for relay server" description = "Security group for relay server"
ingress { ingress {
@@ -72,7 +97,7 @@ resource "aws_security_group" "relay_sg" {
# EC2 Instance # EC2 Instance
resource "aws_instance" "relay_server" { resource "aws_instance" "relay_server" {
ami = var.ami_id ami = var.ami_id != "" ? var.ami_id : data.aws_ami.amazon_linux.id
instance_type = var.instance_type instance_type = var.instance_type
vpc_security_group_ids = [aws_security_group.relay_sg.id] vpc_security_group_ids = [aws_security_group.relay_sg.id]
@@ -80,7 +105,7 @@ resource "aws_instance" "relay_server" {
associate_public_ip_address = true associate_public_ip_address = true
root_block_device { root_block_device {
volume_size = 20 volume_size = 30
volume_type = "gp3" volume_type = "gp3"
encrypted = true encrypted = true
} }
@@ -106,22 +131,29 @@ resource "aws_instance" "relay_server" {
} }
} }
# Elastic IP # Elastic IP (only create if not using existing one)
resource "aws_eip" "relay_ip" { resource "aws_eip" "relay_ip" {
count = var.existing_eip_allocation_id == "" ? 1 : 0
tags = { tags = {
Name = "relay-eip" Name = "relay-eip"
} }
} }
# Data source for existing EIP (if provided)
data "aws_eip" "existing" {
count = var.existing_eip_allocation_id != "" ? 1 : 0
id = var.existing_eip_allocation_id
}
resource "aws_eip_association" "relay_eip_assoc" { resource "aws_eip_association" "relay_eip_assoc" {
instance_id = aws_instance.relay_server.id instance_id = aws_instance.relay_server.id
allocation_id = aws_eip.relay_ip.id allocation_id = var.existing_eip_allocation_id != "" ? data.aws_eip.existing[0].id : aws_eip.relay_ip[0].id
} }
# Get the hosted zone ID if domain is provided # Get the hosted zone ID if domain is provided
data "aws_route53_zone" "selected" { data "aws_route53_zone" "selected" {
count = var.domain_name != "" ? 1 : 0 count = var.domain_name != "" ? 1 : 0
name = regex(".[^.]+.[^.]+$", var.domain_name) # Get parent domain name = regex(".[^.]+.[^.]+$", var.domain_name) # Get parent domain
private_zone = false private_zone = false
} }
@@ -132,5 +164,5 @@ resource "aws_route53_record" "relay" {
name = var.domain_name name = var.domain_name
type = "A" type = "A"
ttl = "300" ttl = "300"
records = [aws_eip.relay_ip.public_ip] records = [var.existing_eip_allocation_id != "" ? data.aws_eip.existing[0].public_ip : aws_eip.relay_ip[0].public_ip]
} }
+3 -3
View File
@@ -1,17 +1,17 @@
output "relay_public_ip" { output "relay_public_ip" {
description = "Public IP of the relay server" description = "Public IP of the relay server"
value = aws_eip.relay_ip.public_ip value = var.existing_eip_allocation_id != "" ? data.aws_eip.existing[0].public_ip : aws_eip.relay_ip[0].public_ip
} }
output "relay_websocket_url" { output "relay_websocket_url" {
description = "WebSocket URL for agent connections" description = "WebSocket URL for agent connections"
value = var.domain_name != "" ? "wss://${var.domain_name}:443" : "ws://${aws_eip.relay_ip.public_ip}:8080" value = var.domain_name != "" ? "wss://${var.domain_name}:443" : "ws://${var.existing_eip_allocation_id != "" ? data.aws_eip.existing[0].public_ip : aws_eip.relay_ip[0].public_ip}:8080"
sensitive = true sensitive = true
} }
output "socks_proxy_address" { output "socks_proxy_address" {
description = "SOCKS proxy address" description = "SOCKS proxy address"
value = "${aws_eip.relay_ip.public_ip}:1080" value = "${var.existing_eip_allocation_id != "" ? data.aws_eip.existing[0].public_ip : aws_eip.relay_ip[0].public_ip}:1080"
} }
output "relay_instance_id" { output "relay_instance_id" {
+10 -4
View File
@@ -1,7 +1,7 @@
variable "aws_region" { variable "aws_region" {
description = "AWS region to deploy resources" description = "AWS region to deploy resources"
type = string type = string
default = "us-west-2" default = "us-east-2"
} }
variable "office_ip_range" { variable "office_ip_range" {
@@ -14,9 +14,9 @@ variable "office_ip_range" {
} }
variable "ami_id" { variable "ami_id" {
description = "AMI ID for relay server" description = "AMI ID for relay server (leave empty to use latest Amazon Linux 2023)"
type = string type = string
default = "ami-0e0bf53f6def86294" # Amazon Linux 2023 for us-east-2 default = "" # Will be auto-detected using data source
} }
variable "instance_type" { variable "instance_type" {
@@ -51,6 +51,12 @@ variable "proxy_pass" {
variable "domain_name" { variable "domain_name" {
description = "Domain name to use for the relay server (e.g., relay.example.com)" description = "Domain name to use for the relay server (e.g., relay.example.com)"
type = string type = string
default = "" # Optional, deployment will work without a domain default = "" # Optional, deployment will work without a domain
}
variable "existing_eip_allocation_id" {
description = "Existing Elastic IP allocation ID to use instead of creating a new one"
type = string
default = "" # If empty, a new EIP will be created
} }
@@ -2,11 +2,9 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net472</TargetFramework>
<RootNamespace>NativeAppHost</RootNamespace> <RootNamespace>NativeAppHost</RootNamespace>
<AssemblyName>NativeAppHost</AssemblyName> <AssemblyName>NativeAppHost</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>net472</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems> <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<!-- Explicitly set the assembly name --> <!-- Explicitly set the assembly name -->
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>net472</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems> <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<!-- Explicitly set the assembly name --> <!-- Explicitly set the assembly name -->
+1 -1
View File
@@ -19,7 +19,7 @@ First build the docker container: `docker build -t chromealone .`
## Deployment Instructions ## Deployment Instructions
There are currently two supported deployment modes: There are currently two supported deployment modes. Note that in either case, you should be running `docker` from the base directory of the ChromeAlone git repository.
### Deployment from scratch via AWS ### Deployment from scratch via AWS
+11 -4
View File
@@ -6,16 +6,18 @@ DOMAIN_NAME=""
APP_NAME="com.chrome.alone" APP_NAME="com.chrome.alone"
OUTPUT_NAME="sideloader.ps1" OUTPUT_NAME="sideloader.ps1"
TFVARS_FILE="" TFVARS_FILE=""
AWS_REGION="us-east-2" # Default region
# Function to display usage information # Function to display usage information
show_usage() { show_usage() {
echo "Usage: $0 [--domain=example.com] [--appname=com.chrome.alone] [--output=sideloader.ps1] [--tfvars=path/to/terraform.tfvars]" echo "Usage: $0 [--domain=example.com] [--appname=com.chrome.alone] [--output=sideloader.ps1] [--tfvars=path/to/terraform.tfvars] [--region=us-east-2]"
echo "" echo ""
echo "Arguments:" echo "Arguments:"
echo " --domain=DOMAIN Domain name for the relay server (required unless --tfvars is provided)" echo " --domain=DOMAIN Domain name for the relay server (required unless --tfvars is provided)"
echo " --appname=NAME Custom app name (optional, default: com.chrome.alone)" echo " --appname=NAME Custom app name (optional, default: com.chrome.alone)"
echo " --output=NAME Output file name (optional, default: sideloader.ps1)" echo " --output=NAME Output file name (optional, default: sideloader.ps1)"
echo " --tfvars=PATH Path to existing terraform.tfvars file (skips terraform deployment)" echo " --tfvars=PATH Path to existing terraform.tfvars file (skips terraform deployment)"
echo " --region=REGION AWS region for deployment (optional, default: us-east-2)"
echo "" echo ""
} }
@@ -38,6 +40,10 @@ while [[ $# -gt 0 ]]; do
TFVARS_FILE="${1#*=}" TFVARS_FILE="${1#*=}"
shift shift
;; ;;
--region=*)
AWS_REGION="${1#*=}"
shift
;;
--help|-h) --help|-h)
show_usage show_usage
exit 0 exit 0
@@ -69,6 +75,7 @@ if [ -n "$TFVARS_FILE" ]; then
else else
echo "Domain Name: $DOMAIN_NAME" echo "Domain Name: $DOMAIN_NAME"
fi fi
echo "AWS Region: $AWS_REGION"
echo "App Name: ${APP_NAME:-Using default com.chrome.alone}" echo "App Name: ${APP_NAME:-Using default com.chrome.alone}"
echo "Output Name: ${OUTPUT_NAME:-Using default sideloader.ps1}" echo "Output Name: ${OUTPUT_NAME:-Using default sideloader.ps1}"
@@ -124,7 +131,7 @@ if [ -n "$TFVARS_FILE" ]; then
else else
echo "Step 1: Running .deploy-relay.sh from BATTLEPLAN/ directory" echo "Step 1: Running .deploy-relay.sh from BATTLEPLAN/ directory"
cd "$PROJECT_ROOT/BATTLEPLAN" cd "$PROJECT_ROOT/BATTLEPLAN"
bash ./deploy-relay.sh --domain "$DOMAIN_NAME" bash ./deploy-relay.sh --domain "$DOMAIN_NAME" --region "$AWS_REGION"
fi fi
# Extract domain_name and relay_token from terraform.tfvars # Extract domain_name and relay_token from terraform.tfvars
@@ -186,8 +193,8 @@ cp -r ./HOTWHEELS/extension/ ./output/extension/
cp ./PAINTBUCKET/ContentScriptInject/*.js ./output/extension/ cp ./PAINTBUCKET/ContentScriptInject/*.js ./output/extension/
# Step 4b: Build the WASM files # Step 4b: Build the WASM files
GOOS=js GOARCH=wasm go build -trimpath -ldflags "-s -w" -o ./output/extension/wasm/main.wasm ./HOTWHEELS/wasm/content-script/ GOOS=js GOARCH=wasm go build -buildvcs=false -trimpath -ldflags "-s -w" -o ./output/extension/wasm/main.wasm ./HOTWHEELS/wasm/content-script/
GOOS=js GOARCH=wasm go build -trimpath -ldflags "-s -w -X main.EXTENSION_NAME=$APP_NAME" -o output/extension/wasm/background.wasm ./HOTWHEELS/wasm/background-script/ GOOS=js GOARCH=wasm go build -buildvcs=false -trimpath -ldflags "-s -w -X main.EXTENSION_NAME=$APP_NAME" -o output/extension/wasm/background.wasm ./HOTWHEELS/wasm/background-script/
# Step 4c: build the native messaging host # Step 4c: build the native messaging host
dotnet build -c Release -r win-x64 -o output/extension/ ./DOORKNOB/ExtensionSideloader/dotnet/NativeAppHost/NativeAppHost.csproj dotnet build -c Release -r win-x64 -o output/extension/ ./DOORKNOB/ExtensionSideloader/dotnet/NativeAppHost/NativeAppHost.csproj