-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add a testing CI on the aws image #19
Changes from all commits
e523092
dbdd90f
05efef8
7af4160
3a29ebb
c7e097b
f4da213
c400f4c
a26449a
ed7b9cc
a13e34b
ccb9255
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
PUBLIC_IP=$1 | ||
start_time=$(date +%s) | ||
|
||
while [ "$(curl -s -o /dev/null -w ''%{http_code}'' --max-time 5 http://$PUBLIC_IP)" != "200" ]; do | ||
sleep 5 | ||
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about |
||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
PUBLIC_IP=$1 | ||
status="$(curl http://$PUBLIC_IP/health)" | ||
|
||
# Check if the variable content is equal to '{"status":"available"}' | ||
if [ "$status" != '{"status":"available"}' ]; then | ||
echo "Error: Meilisearch is not running correctly." | ||
echo "Server response: $status" | ||
exit 1 | ||
else | ||
echo "Meilisearch is available." | ||
exit 0 | ||
fi |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||||||||||||||||
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 }} | ||||||||||||||||||||
PACKER_VERSION: "latest" | ||||||||||||||||||||
steps: | ||||||||||||||||||||
- name: Checkout code | ||||||||||||||||||||
uses: actions/checkout@v2 | ||||||||||||||||||||
|
||||||||||||||||||||
- name: Install Packer | ||||||||||||||||||||
uses: hashicorp/setup-packer@main | ||||||||||||||||||||
with: | ||||||||||||||||||||
version: ${{ env.PACKER_VERSION }} | ||||||||||||||||||||
|
||||||||||||||||||||
- name: Build image | ||||||||||||||||||||
run: | | ||||||||||||||||||||
packer init . | ||||||||||||||||||||
build_res="$(packer build -var 'image_name=${{ github.run_id }}' -machine-readable -only "amazon-ebs.*" meilisearch.pkr.hcl)" | ||||||||||||||||||||
echo $build_res | ||||||||||||||||||||
image_id="$(echo $build_res | awk -F, '$0 ~/artifact,0,id/ {print $6}' | cut -d ":" -f 2)" | ||||||||||||||||||||
echo "IMAGE_ID=$image_id" >> $GITHUB_ENV | ||||||||||||||||||||
|
||||||||||||||||||||
- name: check env.IMAGE_ID | ||||||||||||||||||||
run: echo "${{ env.IMAGE_ID }}" | ||||||||||||||||||||
- name: check IMAGE_ID | ||||||||||||||||||||
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 | ||||||||||||||||||||
Comment on lines
+42
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here for Terraform? Maybe we can use both simultaneously ... |
||||||||||||||||||||
|
||||||||||||||||||||
- name: Create instance | ||||||||||||||||||||
run: | | ||||||||||||||||||||
terraform init | ||||||||||||||||||||
terraform apply -auto-approve -var ami_id=$IMAGE_ID | ||||||||||||||||||||
public_ip="$(terraform output public_ip_address | cut -d "\"" -f 2)" | ||||||||||||||||||||
echo "PUBLIC_IP=$public_ip" >> $GITHUB_ENV | ||||||||||||||||||||
- name: Test that the instance is running | ||||||||||||||||||||
run: | | ||||||||||||||||||||
sh .github/scripts/check_instance.sh ${{ env.PUBLIC_IP }} | ||||||||||||||||||||
- name: Test that Meilisearch is running correctly | ||||||||||||||||||||
run: | | ||||||||||||||||||||
sh .github/scripts/check_meilisearch_availability.sh ${{ env.PUBLIC_IP }} | ||||||||||||||||||||
- name: Destroy instance and AMI | ||||||||||||||||||||
if: always() | ||||||||||||||||||||
run: | | ||||||||||||||||||||
terraform init | ||||||||||||||||||||
terraform destroy -var ami_id=$IMAGE_ID -auto-approve | ||||||||||||||||||||
|
||||||||||||||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
variable "ami_id" { | ||
bidoubiwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are predefined types, otherwise, you could change |
||
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use the command
-o /dev/null
to capture output if you're going to send it to/dev/null
? If you want to avoid having it printed in the terminal, the -s silent option is enough.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a copypasta from chatgpt 😅 Good catch