-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
start_time=$(date +%s) | ||
|
||
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' --max-time 5 http://11.1.1)" != "200" ]]; do | ||
sleep 5 | ||
|
||
elapsed_time=$(($(date +%s) - $start_time)) | ||
# A timeout error is raised after waiting for 10 minutes | ||
if [[ $elapsed_time -gt 600 ]]; then | ||
echo "Timeout error: The request took too long to complete." | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "Instance is ready!" | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
status="$(curl http://$PUBLIC_IP/health)" | ||
|
||
# Check if the variable content is equal to '{"status":"available"}' | ||
if [ "$status" != '{"status":"available"}' ]; then | ||
# If not, echo the variable value and an error message, and exit with code 1 | ||
echo "Error: Meilisearch is not running correctly." | ||
echo "Server response: $status" | ||
exit 1 | ||
else | ||
# If it is equal, echo a success message and exit with code 0 | ||
echo "Meilisearch is available." | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Test AWS image | ||
|
||
on: | ||
pull_request: | ||
push: | ||
# trying and staging branches are for BORS config | ||
branches: | ||
- trying | ||
- staging | ||
- main | ||
|
||
jobs: | ||
test-image: | ||
runs-on: ubuntu-latest | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Packer | ||
run: | | ||
wget https://releases.hashicorp.com/packer/1.7.7/packer_1.7.7_linux_amd64.zip # change version | ||
unzip packer_1.7.7_linux_amd64.zip | ||
sudo mv packer /usr/local/bin/ | ||
- name: Build image | ||
run: | | ||
image_id=$(packer build -var 'image_name=temporary-iam-used-in-packer-testing' -machine-readable -only "amazon-ebs.*" meilisearch.pkr.hcl | awk -F, '$0 ~/artifact,0,id/ {print $6}' | cut -d ":" -f 2) | ||
echo "export IMAGE_ID=$image_id" >> $GITHUB_ENV | ||
- name: check env | ||
run: echo $IMAGE_ID | ||
|
||
- name: Install Terraform | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y curl unzip | ||
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - | ||
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | ||
sudo apt-get update && sudo apt-get install -y terraform | ||
- name: Create instance | ||
run: | | ||
terraform init | ||
terraform apply -auto-approve -var ami_id=$IMAGE_ID | ||
public_ip=$(terraform output public_ip) | ||
echo "export PUBLIC_IP=$public_ip" >> $GITHUB_ENV | ||
- name: Test that the instance is running | ||
run: | | ||
sh .github/scripts/check-instance.sh | ||
- name: Test that Meilisearch is running correctly | ||
run: | | ||
sh .github/scripts/check_meilisearch_availability.sh | ||
- name: Destroy instance and AMI | ||
if: always() | ||
run: | | ||
terraform destroy -var ami_id=$IMAGE_ID -auto-approve | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
variable "ami_id" { | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
description = "The AWS region to use for resources" | ||
type = string | ||
default = "us-east-1" | ||
} | ||
|
||
provider "aws" { | ||
region = var.region | ||
} | ||
|
||
data "aws_security_group" "selected" { | ||
id = "sg-037fd498b332442c1" | ||
} | ||
|
||
resource "aws_instance" "test" { | ||
ami = var.ami_id | ||
instance_type = "t2.small" | ||
tags = { | ||
Name = "aws-packer-testing-instance" | ||
} | ||
vpc_security_group_ids = [data.aws_security_group.selected.id] | ||
|
||
provisioner "local-exec" { | ||
command = "aws ec2 deregister-image --image-id ${self.ami}" | ||
when = destroy | ||
|
||
environment = { | ||
AWS_REGION = "us-east-1" | ||
} | ||
} | ||
} | ||
|
||
output "public_ip_address" { | ||
value = aws_instance.test.public_ip | ||
} |