test brute force #61
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
name: Build and Run Docker Image | |
on: | |
push: | |
branches: | |
- 'ci' # Trigger on push to release branches | |
jobs: | |
build_and_run: | |
runs-on: ubuntu-latest # Use a GitHub-hosted runner | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Build Image Name | |
run: | | |
echo DOCKER_IMAGE_NAME=$(echo ${{ github.event.repository.name }} | tr '[A-Z]' '[a-z]') | tee -a $GITHUB_ENV | |
echo CODELINE=$(echo ${{ github.ref_name }} | tr '[A-Z]' '[a-z]') | tee -a $GITHUB_ENV | |
echo INSTANCE_NAME=${{ github.ref_name }}_InT | tee -a $GITHUB_ENV | |
- name: Build Docker Image | |
run: | | |
docker build . --file Dockerfile --tag ${{ env.DOCKER_IMAGE_NAME }}:${{ env.CODELINE }} | |
echo '## Image Details' >> $GITHUB_STEP_SUMMARY | |
header=$(docker images | sed -r 's/\s{2,}/|/g' | grep -E '^R' | sed -r 's/^|$/\|/g') | |
echo "$header" >> $GITHUB_STEP_SUMMARY | |
echo "$header" | sed -r 's/[^|]/-/g' >> $GITHUB_STEP_SUMMARY | |
docker images | sed -r 's/\s{2,}/|/g' | grep -E 'pyterrabacktyl' | sed -r 's/^|$/\|/g' >> $GITHUB_STEP_SUMMARY | |
- name: Run Docker Container | |
run: | | |
docker run -d --name ${{ env.INSTANCE_NAME }} -p 2442:2442 ${{ env.DOCKER_IMAGE_NAME }}:${{ env.CODELINE }} | |
- name: Wait for PyTerraBackTYL to start | |
run: | | |
for ct in {0..9} | |
do | |
set +e | |
# OK=$(curl -Ss -o /dev/null -w "%{http_code}" http://localhost:2442 || true) | |
OK=$(curl -Ss -o /dev/null -w "%{http_code}") | |
set -e | |
if [ ${OK} -ne 200 ]; then | |
echo "waiting..." | |
sleep 1 | |
else | |
exit 0 | |
fi | |
done | |
exit 1 | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.9.6 # Specify the version of Terraform you want to use | |
- name: Run Terraform Test | |
run: | | |
cd .github/build_tests | |
terraform init | |
terraform plan | |
terraform apply --auto-approve | |
docker logs ${{ env.INSTANCE_NAME }} | |
echo TFSTATE=$(curl -sS http://localhost:2442/?env=InT) | tee -a $GITHUB_ENV | |
cat example_server.txt | |
- name: Validate Terraform State | |
run: | | |
cd .github/build_tests | |
TF_CONTENT=$(echo '${{ env.TFSTATE }}' | jq -r '.resources[].instances[].attributes.content | select(. != null)') | |
FILE_CONTENT=$(cat example_server.txt) | |
if [[ ${TF_CONTENT} != ${FILE_CONTENT} ]]; then | |
echo ${TF_CONTENT} != ${FILE_CONTENT} >&2 | |
exit 1 | |
fi | |
- name: Clean Up | |
# Hopefully this is being nice to GHA infra and not wasted CPU cycles | |
run: | | |
docker rm -f ${{ env.INSTANCE_NAME }} || true | |
docker rmi ${{ env.DOCKER_IMAGE_NAME }}:${{ env.CODELINE }} || true |