Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/aitokenteam #17

Open
wants to merge 146 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
558aa60
start of new version
Dec 12, 2024
2138b04
now creating
Dec 12, 2024
2badf08
machine image
Dec 12, 2024
51a0906
update
Dec 12, 2024
fdac521
now running
Dec 13, 2024
5ed453c
using ami
Dec 13, 2024
f29b5df
bugfix egress
Dec 13, 2024
f381197
adding updates and proposed changes
Dec 13, 2024
5c7e3a2
work in progress
Dec 13, 2024
7f1fd3a
starting
Dec 13, 2024
b9a7e36
moving towards asg support
Dec 14, 2024
d8898a4
now trying again with medium
Dec 14, 2024
7e7f8f9
many sizes
Dec 14, 2024
7f40ba1
now creating more sizes
Dec 14, 2024
107ae6a
removing too small
Dec 14, 2024
68c39a9
alb
Dec 16, 2024
790bb6b
create tg
Dec 16, 2024
8c10213
create tg
Dec 16, 2024
bb62580
applied
Dec 16, 2024
f9d0d56
group coming online
Dec 16, 2024
a135fe8
plan
Dec 16, 2024
b561619
wip
Dec 16, 2024
7e4cf29
update
Dec 16, 2024
1cf2295
health check
Dec 16, 2024
c6fd42c
update
Dec 16, 2024
049c6ef
start of swarms deploy
Dec 16, 2024
05ed0bd
start of swarms
Dec 16, 2024
248221c
now applying
Dec 17, 2024
1063aed
now applying
Dec 17, 2024
06f9a86
adding readme
Dec 17, 2024
790758e
starting cognito
Dec 17, 2024
e671f30
apply
Dec 17, 2024
3cd307a
appplied
Dec 17, 2024
e64a39a
google
Dec 17, 2024
e43831e
Delete accounts/swarms/.terraform.lock.hcl
jmikedupont2 Dec 17, 2024
ea2a611
more scopes
Dec 17, 2024
0e86ce3
adding ses
Dec 17, 2024
a2bff67
starting on ses verification
Dec 17, 2024
464cc1c
insecure listener and updated instructions
Dec 18, 2024
334207b
building ami
Dec 18, 2024
79ec0b3
now larger drive
Dec 18, 2024
ada7442
new ami asg
Dec 18, 2024
2e59cc2
loading
Dec 18, 2024
c38d394
new installer
Dec 18, 2024
45f8b38
update
Dec 18, 2024
13621be
remove the slow asg
Dec 18, 2024
06a8b41
simple autoscale policy
Dec 19, 2024
eedf499
swarmdeploy
Dec 19, 2024
cac4c79
now just hacking this for now
Dec 19, 2024
554f901
bugfix: use the install in the root dir
Dec 19, 2024
f708fad
proof of godaddy working
Dec 19, 2024
b6f8961
secrets loading
Dec 19, 2024
e8aa000
version 1
Dec 19, 2024
aa37da0
fix the yaml
Dec 19, 2024
cc6d1e8
call swarms
Dec 19, 2024
57d111e
notes from todays meeting
Dec 19, 2024
3011848
Update README.md
jmikedupont2 Dec 19, 2024
b9cd606
Update README.md
jmikedupont2 Dec 19, 2024
112773e
test
Dec 19, 2024
c512375
first version of call swarms calling
Dec 19, 2024
69de293
update job version
Dec 19, 2024
3c4a68b
starting on a new autoscaling group
Dec 19, 2024
ea44b5f
customer test
Dec 19, 2024
eca5690
working it seems
Dec 19, 2024
db93c71
now adding a call swarms.sh
Dec 20, 2024
749092d
update
Dec 20, 2024
dcf219e
fixing bug
Dec 20, 2024
b6b8460
removing test code
Dec 20, 2024
d482d1c
deploy
Dec 20, 2024
832898b
start of the observability
Dec 21, 2024
76dea16
applied
Dec 21, 2024
08e85bd
allow decrypt
Dec 21, 2024
06b9a22
wip
Dec 21, 2024
3c23717
work in progress
Dec 21, 2024
dd2b6fd
call swarms
Dec 21, 2024
c849407
gitignore
Dec 21, 2024
45427cd
fixing more perms
Dec 21, 2024
fcbecca
wip
Dec 22, 2024
d0b08da
report
Dec 22, 2024
1cb80d1
adding branch name
Dec 22, 2024
151c3e8
now fixing the logging config
Dec 22, 2024
aee8856
swap
Dec 22, 2024
41a652d
update the code to fetch then checkout
Dec 22, 2024
f1da299
pdev
Dec 22, 2024
c930829
pdev
Dec 22, 2024
9dd1a41
pdev
Dec 22, 2024
cb9a924
adding main
Dec 22, 2024
f4326f3
starting with docker
Dec 23, 2024
3899d69
update readme
Dec 23, 2024
4342004
normalizing the names
Dec 23, 2024
42a947f
adding status
Dec 23, 2024
b2c2099
top level module
Dec 24, 2024
198627d
tofu apply -target module.call_swarms.aws_ssm_document.deploy-docker
Dec 24, 2024
4c8eba2
example logs
Dec 24, 2024
0761940
creating readme
Dec 24, 2024
b96bfdd
creating readme
Dec 24, 2024
9fa1b3a
fix fmt
Dec 24, 2024
8138b4a
now its pulling
Dec 24, 2024
02bbed9
resize
Dec 25, 2024
f71554b
max price 0.0275
Dec 25, 2024
81564cb
fmt
Dec 25, 2024
66dda6e
adding spot
Dec 25, 2024
ecb23ac
Delete environments/swarms-aws-agent-api/dev/us-east-1/Readme.md~
jmikedupont2 Dec 26, 2024
ddb49a5
moving traffic source attachments
Dec 26, 2024
0357e1b
fixing size
Dec 26, 2024
45768a5
increase size
Dec 26, 2024
cc23a5a
removing spot for now
Dec 26, 2024
00452be
fixing branch to be constant in user data
Dec 27, 2024
a045f4b
creating cname
Dec 27, 2024
aee30ad
creating new mcs subcomponent
Dec 27, 2024
3de651f
tofu fmt
Dec 27, 2024
41ef75c
fixing path name
Dec 27, 2024
a792f31
fixing branch
Dec 28, 2024
038b0b7
changing health check path https://github.com/The-Swarm-Corporation/M…
Dec 28, 2024
73bb419
parser now producing better results
Dec 28, 2024
6b959d0
report
Dec 28, 2024
679e81e
now generating new code
Dec 29, 2024
9784e4f
generated first version
Dec 29, 2024
4ab9ced
adding in documentation
Dec 31, 2024
1ff4b4e
getlogs
Dec 31, 2024
67998a8
creating mcs dev
Dec 31, 2024
bcc9ee1
adding mcs dev
Dec 31, 2024
e12be67
update
Dec 31, 2024
eb322e3
Merge branch 'feature/ses' into feature/mcs
Jan 9, 2025
d4b64fb
applied
Jan 9, 2025
edce93d
step one create ssm infra
Jan 9, 2025
faf3eb5
adding eliza
Jan 9, 2025
0982e88
applied
Jan 9, 2025
723bfad
fixing name of log file
Jan 9, 2025
d4a3eaa
work in progress starting to boot
Jan 10, 2025
27ee585
applied
Jan 10, 2025
97d36b0
new sizes
Jan 10, 2025
c9a23d4
renaming
Jan 12, 2025
8db2f0f
wip
Jan 12, 2025
50ed993
adding in bogus azs
Jan 12, 2025
03d3b0d
adding owners
Jan 13, 2025
cc47c09
removing my key
Jan 13, 2025
2fef929
update readme
Jan 13, 2025
f09fb87
comment out kms id
Jan 13, 2025
8b46a9a
keypairs
Jan 13, 2025
a0f7676
fixing
Jan 13, 2025
c5be841
move to branch
Jan 14, 2025
4eb3ee8
allow github to create repositories
Jan 14, 2025
ecd5950
adding more detailed instructions
Jan 14, 2025
316a26e
adding ai notes back in
Jan 14, 2025
88ef79a
tofu
Jan 14, 2025
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
27 changes: 27 additions & 0 deletions .github/workflows/call-swarms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
workflow_dispatch:
push:
branches:
- "feature/docker"
# pull_request:
# branches:
# - "main"
# paths:
# - ".github/workflows/call-swarms.yaml"

name: CallSwarms
jobs:
caller-identity:
name: Return the IAM user
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github
- uses: actions/checkout@v2
- run: bash -x -e ./actions/call_swarms.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ flycheck_*.el
# network security
/network-security.data

/logs/logs/
.aider*
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
find -name \*.tf -exec grep -r provider {} \; -print
136 changes: 135 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,151 @@
# terraform-template

```
git clone https://github.com/aitokenteam/ai-agent-terraform.git
cd ai-agent-terraform/accounts/AI_Token_Team/
git checkout feature/aitokenteam

tofu init

aws ecr create-repository --repository-name agent/eliza

aws ssm put-parameter --name "agent_openai_key" --value "${OPENAI_API_KEY}" --type String

tofu apply --target module.ssm_observer.aws_ssm_parameter.cw_agent_config --target module.ssm_observer.aws_ssm_parameter.cw_agent_config_details
tofu apply
```

Terraform project template for deploying infrastructure across multiple environments and regions, following best practices with modular structure and automated syntax checks (GitHub Actions)

## Installation

1. setup aws account
2. create user with administrator privledges for terraform/tofu

Directly attach Policy name `AdministratorAccess` to user
replace <USERNAME> in the following url
`https://us-east-1.console.aws.amazon.com/iam/home?region=us-east-2#/users/details/<USERNAME>?section=permissions`

create access key
https://us-east-1.console.aws.amazon.com/iam/home?region=us-east-2#/users/details/mdupont/create-access-key

~/.aws/credentials

aws cli install
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

`aws configure`

opentofu install
https://opentofu.org/docs/intro/install/

Go to ami catalog in your region:
https://us-west-1.console.aws.amazon.com/ec2/home?region=us-west-1#AMICatalog:

Search for "ubuntu-noble-24.04-amd64-minimal" in the third tab "aws marketplace amis"

Accept license.

## Status report

Currently we are building out a dev infrastructure using our existing code
and adding in a docker target, this has the advantage that we can build and test
the docker outside of aws and then deploy it easily.

## Repo structure

```
terraform-template/ # Root directory of the Terraform template repository
├── README.md # Project documentation and overview
├── environments
├── accounts
│ ├── swarms # the main swarms account
├── environments
│ ├── swarms-aws-agent-api
│ │ ├── dev # Development environment configuration for the demo-azure-vm setup
│ │ │ └── us-east-1
├── modules # Directory containing reusable Terraform modules
│ ├── swarms
```

to ss to the server
`aws ssm start-session --target i-0e156165e86473c93 --profile mdupont --region us-east-2`

to install secret
`aws ssm put-parameter --name "agent_openai_key" --value "${OPENAI_API_KEY}" --type String`

If you get this error:
```
│ Error: reading SSM Parameter (arn:aws:ssm:us-east-1:AKIA4SYAMCQ5MMLC6NU3:parameter/cloudwatch-agent/config/details): operation error SSM: GetParameter, https response error StatusCode: 400, RequestID: 159177cb-91f0-4c2e-a354-07cdc2e64041, api error ValidationException: Invalid Account Id in: arn:aws:ssm:us-east-1:AKIA4SYAMCQ5MMLC6NU3:parameter/cloudwatch-agent/config/details
│ with module.eliza_server.module.eliza.module.lt_docker["t3a.small"].data.aws_ssm_parameter.cw_agent_config,
│ on ../../environments/eliza-agent-api/components/launch_template_docker_mcs/main.tf line 77, in data "aws_ssm_parameter" "cw_agent_config":
│ 77: data "aws_ssm_parameter" "cw_agent_config" {
```
we need to apply this first:
`tofu apply --target module.ssm_observer.aws_ssm_parameter.cw_agent_config --target module.ssm_observer.aws_ssm_parameter.cw_agent_config_details`

check the ECR images
`aws ecr list-images --region us-east-2 --repository-name swarms/mcs`

To login from docker to ecr
`docker login -u AWS -p $(aws ecr get-login-password --region us-east-2) 767503528736.dkr.ecr.us-east-2.amazonaws.com' 767503528736.dkr.ecr.us-east-2.amazonaws.com/agent/eliza:latest`

# setup
we dont use terraform for the ecr or the secrets because they will change so often here are the simple aws scripts for them.

`aws ecr create-repository --repository-name agent/eliza`

`set_secrets.sh` calls
`aws ssm put-parameter --name "agent_openai_key" --value "${OPENAI_API_KEY}" --type String`

## connecting with server
`ssh-ssm.py` to find the server

for example:
`aws ssm start-session --target i-0e156165e86473c93 --profile mdupont --region us-east-2`

## terraform-aws-oidc-github
https://github.com/jmikedupont2/terraform-aws-oidc-github

in my time 2024/12/18/terraform-aws-oidc-github on branch
run the tofu apply in the example after editing the variables and files.

# debug
`pnpm start:debug --characters=./characters/eliza.character.json`
start direct client here

# set the az
#~/terraform/accounts/AI_Token_Team/main.tf
edit
aws_availability_zones = ["us-west-1a","us-west-1b","us-west-1c"]

if you ge the errro :
00000003]
module.ssm_setup.module.ssm.aws_s3_bucket_lifecycle_configuration.access_log_bucket: Creation complete after 32s [id=ai-token-team-session-access-logs-20250113203757298300000002]
│ Error: creating EC2 Subnet: operation error EC2: CreateSubnet, https response error StatusCode: 400, RequestID: 05eeaa25-0855-4d71-8945-04b0d6233520, api error InvalidParameterValue: Value (us-west-1b) for parameter availabilityZone is invalid. Subnets can currently only be created in the following availability zones: us-east-1a, us-east-1b, us-east-1c, us-east-1d, us-east-1e, us-east-1f.
│ with module.eliza_server.module.vpc.module.vpc.aws_subnet.public[1],
│ on .terraform/modules/eliza_server.vpc.vpc/main.tf line 98, in resource "aws_subnet" "public":
│ 98: resource "aws_subnet" "public" {


nter a value: yes

# key pair
module.eliza_server.module.eliza.module.asg["t3a.small"].module.autoscaling.aws_autoscaling_group.this[0]: Creating...
│ Error: creating Auto Scaling Group (docker-agent-ami-t3a.small-20250113205357496400000001): operation error Auto Scaling: CreateAutoScalingGroup, https response error StatusCode: 400, RequestID: 380d0f57-bf60-40fd-ace6-d86563107c85, api error ValidationError: You must use a valid fully-formed launch template. The key pair does not exist
│ with module.eliza_server.module.eliza.module.asg["t3a.small"].module.autoscaling.aws_autoscaling_group.this[0],
│ on .terraform/modules/eliza_server.eliza.asg.autoscaling/main.tf line 347, in resource "aws_autoscaling_group" "this":
│ 347: resource "aws_autoscaling_group" "this" {
edit
~/terraform/environments/eliza-agent-api/components/keypairs/main.tf

resource "aws_key_pair" "deployer" {
key_name = "ai-token-deployer-key"
public_key = "<insert your personal cat ~/.ssh/id_pub.rsa"
}

58 changes: 58 additions & 0 deletions accounts/AI_Token_Team/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
provider "aws" {
region = "us-west-1"
#profile = "ai-token-team"
profile = "default"
}

locals {
dns = "aitokenteam.com" # fixme
region = "us-west-1"
project = "ai-token-team" # dont change
}

module "ssm_observer" {
source = "../../modules/aws/ssm/observability"
ami_id = data.aws_ami.ami.id
}

module "ssm_setup" {
source = "../../modules/aws/ssm/setup"
bucket_name = "${local.project}-session-logs"
access_log_bucket_name = "${local.project}-ssm-access-logs"
project = local.project
}

locals {
ami_name = "ubuntu-minimal/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-minimal-*"
}
data "aws_ami" "ami" { # slow
most_recent = true
owners = ["679593333241"]
name_regex = "^${local.ami_name}"
}

module "eliza_server" {
#count = 0
#aws_account_id = local.account
aws_account_id =var.aws_account_id
region = local.region
source = "../../environments/eliza-agent-api/" # FIXME rename
domain = local.dns
ami_id = data.aws_ami.ami.id
name = local.project
project = local.project
key_name = "ai-token-deployer-key"
tags = { project = local.project }

branch = "feature/AI_Token_Team"
spot_max_price = 0.028
instance_types = [
"t3a.small",
# "t3.small",
# "t2.small",
# "t3.medium" # works for sure

]

aws_availability_zones = ["us-west-1a","us-west-1b","us-west-1c"]
}
54 changes: 54 additions & 0 deletions accounts/AI_Token_Team/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
variable "project_name" {
type = string
default = "ai-token-team"
}

variable "profile" {
type = string
default = "ai-token-team"
}

variable "aws_region" {
type = string
default = "us-west-1"
}

variable "aws_account_id" {
type = string
default = "699475930706"
}

variable "iam_user" {
type = string
default = "aitokenteam"
}

variable "lock_resource" {
type = string
default = "terraform/state/lock"
}

variable "partition" {
type = string
default = "aws"
}

variable "logs_resource" {
type = string
default = "aws_logs"
}

variable "permissions_check" {
type = string
default = "config-permissions-check"
}

variable "delivery_service" {
type = string
default = "delivery.logs.amazonaws.com"
}

variable "logging_service" {
type = string
default = "logging.s3.amazonaws.com"
}
3 changes: 2 additions & 1 deletion accounts/mdupont/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
make :
#tofu init
tofu init
tofu plan
tofu apply
1 change: 1 addition & 0 deletions accounts/mdupont/custom_style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.label-customizable {font-weight: 400;}
24 changes: 10 additions & 14 deletions accounts/mdupont/data.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# task create an output file for this module to expose all interesting data, include the ids of each resource.
provider "aws" {
region = var.aws_region
}

data "aws_iam_user" "example_user" {
user_name = var.iam_user
}

data "aws_dynamodb_table" "terraform_dynamo_table" {
name = var.table_name
}
#data "aws_dynamodb_table" "terraform_dynamo_table" {
# name = var.table_name
#}


# Data resource for AWS call identity
data "aws_caller_identity" "current" {}

data "aws_s3_bucket" "terraform_logging" {
bucket = "${var.project_name}-tf-state-log-${var.aws_region}"
}

data "aws_s3_bucket" "terraform_state" {
bucket = "${var.project_name}-tf-state-${var.aws_region}"
}
#data "aws_s3_bucket" "terraform_logging" {
# bucket = "${var.project_name}-tf-state-log-${var.aws_region}"
#}

#data "aws_s3_bucket" "terraform_state" {
# bucket = "${var.project_name}-tf-state-${var.aws_region}"
#}

data "aws_cloudtrail_service_account" "main" {}
#data "aws_cloudtrail_service_account" "main" {}
Binary file added accounts/mdupont/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading