Skip to content

Commit

Permalink
chore: write automated test for ockam examples
Browse files Browse the repository at this point in the history
  • Loading branch information
metaclips committed Jun 25, 2024
1 parent 65e49b6 commit ff0aaf1
Show file tree
Hide file tree
Showing 89 changed files with 629 additions and 115 deletions.
5 changes: 3 additions & 2 deletions examples/command/portals/ai/amazon_bedrock/ai_corp/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ run() {
aws ec2 create-key-pair --key-name "$key_name" --query 'KeyMaterial' > key.pem
chmod 400 key.pem

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type c5n.large \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "$key_name" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
Expand Down Expand Up @@ -128,7 +129,7 @@ get_configured_region() {
cleanup() {
# ----------------------------------------------------------------------------------------------------------------
# DELETE INSTANCE
rm -f user_data.sh
rm -f user_data*.sh

instance_ids=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${name}-ec2-instance" \
--query "Reservations[].Instances[?State.Name!='terminated'].InstanceId[]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async function run() {
console.log("Connected to the model.\n\nApp: ", query);
const queryResponse = await fetch("http://127.0.0.1:3000/query", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({query}),
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query }),
keepalive: true,
});

Expand All @@ -23,6 +23,7 @@ async function run() {

const answer = await queryResponse.json();
console.log(answer['answer']);
console.log("\nThe example run was successful 🥳.");
} catch (error) {
console.log("Error:", error);
}
Expand Down
6 changes: 3 additions & 3 deletions examples/command/portals/ai/amazon_bedrock/health_corp/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ run() {
aws ec2 create-key-pair --key-name "${name}-key" --query 'KeyMaterial' > key.pem
chmod 400 key.pem

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type c5n.large \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "${name}-key" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
aws ec2 create-tags --resources "$instance_id" --tags "Key=Name,Value=${name}-ec2-instance"
aws ec2 wait instance-running --instance-ids "$instance_id"
ip=$(aws ec2 describe-instances --instance-ids "$instance_id" --query 'Reservations[0].Instances[0].PublicIpAddress')
rm -f user_data.sh

until scp -o StrictHostKeyChecking=no -i ./key.pem ./client.js "ec2-user@$ip:client.js"; do sleep 10; done
ssh -o StrictHostKeyChecking=no -i ./key.pem "ec2-user@$ip" \
Expand All @@ -65,7 +65,7 @@ cleanup() {
# ----------------------------------------------------------------------------------------------------------------
# DELETE INSTANCE

rm -f user_data.sh
rm -rf user_data*.sh
instance_ids=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${name}-ec2-instance" \
--query "Reservations[].Instances[?State.Name!='terminated'].InstanceId[]")
for i in $instance_ids; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
4 changes: 4 additions & 0 deletions examples/command/portals/ai/amazon_bedrock/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ run() {
health_corp_ticket=$(ockam project ticket --usage-count 1 --expires-in 60m \
--attribute "ai-inlet=true")

if [[ -n "$OCKAM_VERSION" ]]; then
export OCKAM_VERSION="v${OCKAM_VERSION}";
fi

# Invoke `ai_corp/run.sh` in the directory that has ai_corp's configuration. Pass the above
# enrollment ticket as the first argument to run.sh script. Read ai_corp/run.sh to understand the parts
# that are provisioned in ai_corp's virtual private cloud.
Expand Down
8 changes: 4 additions & 4 deletions examples/command/portals/ai/amazon_ec2/ai_corp/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ run() {
# make sure that the current region supports the instance required to run the model
check_if_instance_type_available g5g.2xlarge

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type g5g.2xlarge \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "${name}-key" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
Expand Down Expand Up @@ -115,7 +116,7 @@ cleanup() {
# ----------------------------------------------------------------------------------------------------------------
# DELETE INSTANCE

rm -f user_data.sh
rm -f user_data*.sh
instance_ids=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${name}-ec2-instance" \
--query "Reservations[*].Instances[*].InstanceId")
for i in $instance_ids; do
Expand All @@ -132,8 +133,7 @@ cleanup() {
# DELETE NETWORK

vpc_ids=$(aws ec2 describe-vpcs \
--filters "Name=tag:Name,Values=${name}-vpc") \
--query 'Vpcs[*].VpcId'
--filters "Name=tag:Name,Values=${name}-vpc" --query 'Vpcs[*].VpcId') \

for vpc_id in $vpc_ids; do
internet_gateways=$(aws ec2 describe-internet-gateways \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async function run() {

const answer = await queryResponse.json();
console.log(answer['answer']);
console.log("\nThe example run was successful 🥳.");
} catch (error) {
console.log("Error:", error.message);
}
Expand Down
5 changes: 3 additions & 2 deletions examples/command/portals/ai/amazon_ec2/health_corp/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ run() {
aws ec2 create-key-pair --key-name "${name}-key" --query 'KeyMaterial' > key.pem
chmod 400 key.pem

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type c5n.large \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "${name}-key" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
Expand All @@ -65,7 +66,7 @@ cleanup() {
# ----------------------------------------------------------------------------------------------------------------
# DELETE INSTANCE

rm -f user_data.sh
rm -f user_data*.sh
instance_ids=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${name}-ec2-instance" \
--query "Reservations[*].Instances[*].InstanceId")
for i in $instance_ids; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
4 changes: 4 additions & 0 deletions examples/command/portals/ai/amazon_ec2/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ run() {
health_corp_ticket=$(ockam project ticket --usage-count 1 --expires-in 60m \
--attribute "ai-inlet=true")

if [[ -n "$OCKAM_VERSION" ]]; then
export OCKAM_VERSION="v${OCKAM_VERSION}";
fi

# Invoke `ai_corp/run.sh` in the directory that has ai_corp's configuration. Pass the above
# enrollment ticket as the first argument to run.sh script. Read ai_corp/run.sh to understand the parts
# that are provisioned in ai_corp's virtual private cloud.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ run() {
aws ec2 create-key-pair --key-name "${name}-key" --query 'KeyMaterial' > key.pem
chmod 400 key.pem

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type t2.micro \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "${name}-key" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
aws ec2 create-tags --resources "$instance_id" --tags "Key=Name,Value=${name}-ec2-instance"
aws ec2 wait instance-running --instance-ids "$instance_id"
ip=$(aws ec2 describe-instances --instance-ids "$instance_id" --query 'Reservations[0].Instances[0].PublicIpAddress')
rm -f user_data.sh

until scp -o StrictHostKeyChecking=no -i ./key.pem ./api.js "ec2-user@$ip:api.js"; do sleep 10; done
ssh -o StrictHostKeyChecking=no -i ./key.pem "ec2-user@$ip" \
Expand All @@ -68,7 +68,7 @@ cleanup() {
# ----------------------------------------------------------------------------------------------------------------
# DELETE INSTANCE

rm -f user_data.sh
rm -f user_data*.sh
instance_ids=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${name}-ec2-instance" \
--query "Reservations[*].Instances[*].InstanceId")
for i in $instance_ids; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ run() {
travel_app_corp_ticket=$(ockam project ticket --usage-count 1 --expires-in 60m \
--attribute "monitoring-api-inlet=true")

if [[ -n "$OCKAM_VERSION" ]]; then
export OCKAM_VERSION="v${OCKAM_VERSION}";
fi

# Invoke `monitoring_corp/run.sh` in the directory that has monitoring_corp's configuration. Pass the above
# enrollment ticket as the first argument to run.sh script. Read monitoring_corp/run.sh to understand the parts
# that are provisioned in monitoring_corp's virtual private cloud.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ run() {
aws ec2 create-key-pair --key-name "${name}-key" --query 'KeyMaterial' > key.pem
chmod 400 key.pem

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type t2.micro \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "${name}-key" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
aws ec2 create-tags --resources "$instance_id" --tags "Key=Name,Value=${name}-ec2-instance"
aws ec2 wait instance-running --instance-ids "$instance_id"
ip=$(aws ec2 describe-instances --instance-ids "$instance_id" --query 'Reservations[0].Instances[0].PublicIpAddress')
rm -f user_data.sh

until scp -o StrictHostKeyChecking=no -i ./key.pem ./client.js "ec2-user@$ip:client.js"; do sleep 10; done
ssh -o StrictHostKeyChecking=no -i ./key.pem "ec2-user@$ip" \
Expand All @@ -65,7 +65,7 @@ cleanup() {
# ----------------------------------------------------------------------------------------------------------------
# DELETE INSTANCE

rm -f user_data.sh
rm -rf user_data*.sh
instance_ids=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${name}-ec2-instance" \
--query "Reservations[*].Instances[*].InstanceId")
for i in $instance_ids; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ run() {
aws ec2 create-key-pair --key-name "${name}-key" --query 'KeyMaterial' > key.pem
chmod 400 key.pem

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type t2.micro \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "${name}-key" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ run() {
travel_app_corp_ticket=$(ockam project ticket --usage-count 1 --expires-in 60m \
--attribute "monitoring-api-inlet=true")

if [[ -n "$OCKAM_VERSION" ]]; then
export OCKAM_VERSION="v${OCKAM_VERSION}";
fi

# Invoke `monitoring_corp/run.sh` in the directory that has monitoring_corp's configuration. Pass the above
# enrollment ticket as the first argument to run.sh script. Read monitoring_corp/run.sh to understand the parts
# that are provisioned in monitoring_corp's virtual private cloud.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ run() {
aws ec2 create-key-pair --key-name "${name}-key" --query 'KeyMaterial' > key.pem
chmod 400 key.pem

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type t2.micro \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "${name}-key" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
aws ec2 create-tags --resources "$instance_id" --tags "Key=Name,Value=${name}-ec2-instance"
aws ec2 wait instance-running --instance-ids "$instance_id"
ip=$(aws ec2 describe-instances --instance-ids "$instance_id" --query 'Reservations[0].Instances[0].PublicIpAddress')
rm -f user_data.sh

until scp -o StrictHostKeyChecking=no -i ./key.pem ./client.py "ec2-user@$ip:client.py"; do sleep 10; done
ssh -o StrictHostKeyChecking=no -i ./key.pem "ec2-user@$ip" \
Expand All @@ -68,7 +68,7 @@ cleanup() {
# ----------------------------------------------------------------------------------------------------------------
# DELETE INSTANCE

rm -f user_data.sh
rm -rf user_data*.sh
instance_ids=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${name}-ec2-instance" \
--query "Reservations[*].Instances[*].InstanceId")
for i in $instance_ids; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ run() {
sg_id=$(aws ec2 create-security-group --group-name "${name}-sg" --vpc-id "$vpc_id" --query 'GroupId' \
--description "Allow TCP egress and Postgres ingress")
aws ec2 authorize-security-group-egress --group-id "$sg_id" --cidr 0.0.0.0/0 --protocol tcp --port 0-65535
aws ec2 authorize-security-group-ingress --group-id "$sg_id" --cidr "${my_ip}/32" --protocol tcp --port 22
aws ec2 authorize-security-group-ingress --group-id "$sg_id" --cidr "0.0.0.0/0" --protocol tcp --port 22

# ----------------------------------------------------------------------------------------------------------------
# CREATE INSTANCE
Expand All @@ -45,15 +45,15 @@ run() {
aws ec2 create-key-pair --key-name "${name}-key" --query 'KeyMaterial' > key.pem
chmod 400 key.pem

sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > run_ockam_temp.sh
cat run_repoaccess.sh run_ockam_temp.sh > user_data.sh
sed "s/\$ENROLLMENT_TICKET/${enrollment_ticket}/g" run_ockam.sh > user_data1.sh
sed "s/\$OCKAM_VERSION/${OCKAM_VERSION}/g" user_data1.sh > user_data2.sh
cat run_repoaccess.sh user_data2.sh > user_data.sh
instance_id=$(aws ec2 run-instances --image-id "$ami_id" --instance-type c5n.large \
--subnet-id "$subnet_id" --security-group-ids "$sg_id" \
--key-name "${name}-key" --user-data file://user_data.sh --query 'Instances[0].InstanceId')
aws ec2 create-tags --resources "$instance_id" --tags "Key=Name,Value=${name}-ec2-instance"
aws ec2 wait instance-running --instance-ids "$instance_id"
ip=$(aws ec2 describe-instances --instance-ids "$instance_id" --query 'Reservations[0].Instances[0].PublicIpAddress')
rm -f run_ockam_temp.sh user_data.sh

until scp -o StrictHostKeyChecking=no -i ./key.pem ./app.js "ec2-user@$ip:app.js"; do sleep 10; done
until scp -o StrictHostKeyChecking=no -i ./key.pem ../bank_corp/gitlab_rsa "ec2-user@$ip:gitlab_rsa"; do sleep 10; done
Expand All @@ -70,7 +70,8 @@ cleanup() {
# ----------------------------------------------------------------------------------------------------------------
# DELETE INSTANCE

rm -f run_ockam_temp.sh user_data.sh
rm -rf user_data*.sh
rm -rf run_repoaccess.sh
instance_ids=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=${name}-ec2-instance" \
--query "Reservations[*].Instances[*].InstanceId")
for i in $instance_ids; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sudo -u ec2-user bash << 'EOS'
set -ex
# Install Ockam Command
export OCKAM_VERSION="$OCKAM_VERSION"
curl --proto '=https' --tlsv1.2 -sSfL https://install.command.ockam.io | bash
source "$HOME/.ockam/env"
Expand Down
Loading

0 comments on commit ff0aaf1

Please sign in to comment.