functional-tests #1311
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: functional-tests | |
on: | |
workflow_dispatch: {} | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
functional-tests: | |
runs-on: ubuntu-latest | |
env: | |
ACCOUNT_ID: "891426818781" | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v3 | |
- | |
name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.22" | |
- | |
name: Build | |
run: go build | |
- | |
name: AppPack Account | |
run: | | |
STACK_NAME=apppack-account | |
AWS_PAGER="" | |
set -ex | |
aws cloudformation create-stack \ | |
--stack-name $STACK_NAME \ | |
--template-url https://s3.amazonaws.com/apppack-cloudformations/latest/account.json \ | |
--capabilities CAPABILITY_IAM \ | |
--parameters ParameterKey=Administrators,[email protected] | |
aws cloudformation wait stack-create-complete \ | |
--stack-name $STACK_NAME | |
timeout-minutes: 10 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: us-east-1 | |
- | |
name: AppPack Cluster | |
run: | | |
./apppack create cluster \ | |
--aws-credentials \ | |
--region us-east-1 \ | |
--create-region \ | |
--dockerhub-username $DOCKERHUB_USERNAME \ | |
--dockerhub-access-token $DOCKERHUB_ACCESS_TOKEN \ | |
--domain testclusters.apppack.io \ | |
--non-interactive | |
timeout-minutes: 20 | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- | |
name: Create app | |
run: | | |
./apppack create app \ | |
--aws-credentials \ | |
--region us-east-1 \ | |
--non-interactive \ | |
--cluster apppack \ | |
--repository https://github.com/apppackio/apppack-demo-python.git \ | |
--branch main \ | |
--users [email protected] \ | |
app-test | |
timeout-minutes: 5 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- | |
name: Verify user | |
run: | | |
echo "Waiting for user to get created..." | |
while [ "$(aws dynamodb get-item --table-name apppack --key '{"primary_id": {"S": "USER#[email protected]"}, "secondary_id": {"S": "891426818781#app-test"}}' --query Item)" = "null" ]; do | |
sleep 10 | |
done | |
timeout-minutes: 3 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.APPPACK_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.APPPACK_AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: us-east-1 | |
# TODO: authorize CLI | |
# - | |
# name: Deploy app | |
# run: | | |
# ./apppack build start -a app-test --wait | |
# timeout-minutes: 5 | |
# - | |
# name: Check app | |
# run: curl --fail https://app-test.testclusters.apppack.io | |
- | |
name: Destroy app | |
run: | | |
yes apppack-app-app-test | ./apppack destroy app app-test --aws-credentials --region us-east-1 | |
if: always() | |
timeout-minutes: 5 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- | |
name: Destroy cluster | |
run: | | |
yes apppack-cluster-apppack | ./apppack destroy cluster apppack --aws-credentials --region us-east-1 | |
if: always() | |
timeout-minutes: 10 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Check and Delete CNAME and A Records | |
if: always() | |
run: | | |
hosted_zone_id="Z05906472T84V7X7Q6UDY" | |
# Record details | |
cname_record_name="_5b8b09a8917e1fbb8c6aead5121fb550.testclusters.apppack.io" | |
a_record_name="*.testcluster.apppack.io" | |
# Function to check and delete a record | |
delete_record() { | |
record_name=$1 | |
record_type=$2 | |
echo "Checking if $record_type record '$record_name' exists ..." | |
record_value=$(aws route53 list-resource-record-sets --hosted-zone-id $hosted_zone_id \ | |
--query "ResourceRecordSets[?Name == '$record_name.']" \ | |
--output text) | |
if [[ -n "$record_value" ]]; then | |
echo "$record_type record exists, deleting..." | |
# Extract the actual value of the record to use in the deletion | |
record_actual_value=$(aws route53 list-resource-record-sets --hosted-zone-id $hosted_zone_id \ | |
--query "ResourceRecordSets[?Name == '$record_name.'].ResourceRecords[0].Value" \ | |
--output text) | |
# Delete the record | |
aws route53 change-resource-record-sets --hosted-zone-id "$hosted_zone_id" \ | |
--change-batch "{ | |
\"Changes\": [{ | |
\"Action\": \"DELETE\", | |
\"ResourceRecordSet\": { | |
\"Name\": \"$record_name\", | |
\"Type\": \"$record_type\", | |
\"TTL\": 300, | |
\"ResourceRecords\": [{\"Value\": \"$record_actual_value\"}] | |
} | |
}] | |
}" | |
echo "$record_type record '$record_name' deleted successfully." | |
else | |
echo "$record_type record '$record_name' does not exist, skipping deletion." | |
fi | |
} | |
# Delete CNAME record | |
delete_record "$cname_record_name" "CNAME" | |
# Delete A record | |
delete_record "$a_record_name" "A" | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: us-east-1 | |
- | |
name: Destroy region | |
run: | | |
yes apppack-region-us-east-1 | ./apppack destroy region --aws-credentials --region us-east-1 | |
if: always() | |
timeout-minutes: 3 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- | |
name: Destroy account | |
run: | | |
yes apppack-account | ./apppack destroy account --aws-credentials --region us-east-1 | |
if: always() | |
timeout-minutes: 3 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- | |
name: Disable account | |
if: always() | |
shell: bash | |
run: | | |
aws dynamodb delete-item --table-name apppack --key '{ | |
"primary_id": {"S": "ACCT#${{ env.ACCOUNT_ID }}"}, | |
"secondary_id": {"S": "-"} | |
}' | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.APPPACK_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.APPPACK_AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: us-east-1 |