Skip to content

Commit

Permalink
[#3670] E2e tests rack resources
Browse files Browse the repository at this point in the history
### What is the feature/fix?

Create a new set of CI Tests to test apps resources, apps resources and timer.

The `example/httpd` will only include the minimum convox.yaml possible. Created a new `examples/full-convox-yaml` to include more parameters to be used on the new CI tests.

It will increase the test timer from 02:30~03:00 to 01:45 ~02:00.

### Does it has a breaking change?

No.

### How to use/test it?

N/A

### Checklist
- [N/A] New coverage tests
- [ ] Unit tests passing
- [ ] E2E tests passing
- [ ] E2E downgrade/update test passing
- [N/A] Documentation updated
- [ ] No warnings or errors on Deepsource/Codecov
  • Loading branch information
yuriadams committed May 9, 2023
1 parent 3f9972f commit 3335569
Show file tree
Hide file tree
Showing 17 changed files with 212 additions and 125 deletions.
22 changes: 5 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ workflows:
name: ci/aws/public/arm64
provider: aws
args: "InstanceType=t4g.small BuildInstance=t4g.small"
- ci:
<<: *filter-releases-any
name: ci/aws/public/full-convox-yaml
provider: aws
action: "full-convox-yaml"
- ci:
<<: *filter-releases-any
name: ci/aws/private
Expand All @@ -85,23 +90,6 @@ workflows:
name: ci/aws/downgrade
provider: aws
action: "downgrade"
- update:
<<: *filter-releases-master
context: staging
requires:
- ci/aws/public
- ci/aws/public-existing-vpc
- ci/aws/public/arm64
- ci/aws/private
name: ci/staging/rack
- deploy:
<<: *filter-releases-master
<<: *deploy
context: staging
name: ci/staging/app/docs-staging
repo: https://github.com/convox/docs
app: docs-staging
check: https://docs-staging-web.stagi-route-1l04rz3fpvbt0-2130032241.us-east-1.convox.site/

jobs:
ci:
Expand Down
28 changes: 28 additions & 0 deletions ci/additonal-test/apps-resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -ex -o pipefail

# Check if the apps resources are available within the app
ps=$(convox api get /apps/ci2/processes | jq -r '.[]|select(.status=="running")|.id' | head -n 1)

# postgres resource
convox exec -a ci2 $ps -- env | grep "POSTGRES_URL"
convox exec -a ci2 $ps -- env | grep "POSTGRES_USER"
convox exec -a ci2 $ps -- env | grep "POSTGRES_PASS"
convox exec -a ci2 $ps -- env | grep "POSTGRES_HOST"
convox exec -a ci2 $ps -- env | grep "POSTGRES_PORT"
convox exec -a ci2 $ps -- env | grep "POSTGRES_NAME"
# mysql resource
convox exec -a ci2 $ps -- env | grep "MYSQL_URL"
convox exec -a ci2 $ps -- env | grep "MYSQL_USER"
convox exec -a ci2 $ps -- env | grep "MYSQL_PASS"
convox exec -a ci2 $ps -- env | grep "MYSQL_HOST"
convox exec -a ci2 $ps -- env | grep "MYSQL_PORT"
convox exec -a ci2 $ps -- env | grep "MYSQL_NAME"
# mariadb resource
convox exec -a ci2 $ps -- env | grep "MARIADB_URL"
convox exec -a ci2 $ps -- env | grep "MARIADB_USER"
convox exec -a ci2 $ps -- env | grep "MARIADB_PASS"
convox exec -a ci2 $ps -- env | grep "MARIADB_HOST"
convox exec -a ci2 $ps -- env | grep "MARIADB_PORT"
convox exec -a ci2 $ps -- env | grep "MARIADB_NAME"
2 changes: 2 additions & 0 deletions ci/additonal-test/fetch-timeout.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -ex -o pipefail

# $1 is the http address
# $2 is the error message

Expand Down
58 changes: 58 additions & 0 deletions ci/additonal-test/rack-resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

set -ex -o pipefail

declare -a RESOURCES=("s3" "sns" "sqs" "mysql")

# syslog resource
convox rack resources create syslog Url=tcp://syslog.convox.com --name cilog --wait
convox rack resources | grep cilog | grep syslog
convox rack resources info cilog | grep -v Apps
convox rack resources url cilog | grep tcp://syslog.convox.com
convox rack resources link cilog -a ci2 --wait
convox rack resources info cilog | grep Apps | grep ci2
convox rack resources unlink cilog -a ci2 --wait
convox rack resources info cilog | grep -v Apps
convox rack resources info cilog | grep -v Apps
convox rack resources update cilog Url=tcp://syslog2.convox.com --wait
convox rack resources info cilog | grep syslog2.convox.com
convox rack resources url cilog | grep tcp://syslog2.convox.com
convox rack resources delete cilog --wait

# postgres resource
convox rack resources create postgres --name pgdb --wait
convox rack resources | grep pgdb | grep postgres
dburl=$(convox rack resources url pgdb)
convox rack resources update pgdb BackupRetentionPeriod=2 --wait
[ "$dburl" == "$(convox rack resources url pgdb)" ]
convox rack resources delete pgdb --wait

# create all 4 resources
for i in "${RESOURCES[@]}"
do
convox rack resources create $i
done

for i in "${RESOURCES[@]}"
do
# Check for resource to be marked as running
j=0
while [ "$(convox rack resources | grep $i | grep running | wc -l)" != "1" ]
do
# Exit if it takes more than 15 minutes
# mysql can take up to 15 minutes to create
if [ $((j++)) -gt 75 ]; then
exit 1
fi
echo "Waiting for resource $i to be marked as running..."
sleep 10
done
done

# delete all 4 resources
for i in "${RESOURCES[@]}"
do
name=$(convox rack resources | grep $i | awk '{print $1}')
echo "deleting resource $name"
convox rack resources delete $name --wait
done
8 changes: 8 additions & 0 deletions ci/additonal-test/timers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -ex -o pipefail

timerLog=$(convox logs -a ci2 --no-follow --since 1m | grep service/example)
if ! [[ $timerLog == *"Hello Timer"* ]]; then
echo "failed"; exit 1;
fi
9 changes: 7 additions & 2 deletions ci/apps-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ root="$(cd $(dirname ${0:-})/..; pwd)"
# cli
convox version

# app
cd $root/examples/httpd
# only deploy the example/httpd if not on full-convox-yaml ci test
if [ "${ACTION}" == "full-convox-yaml" ]; then
cd $root/examples/full-convox-yaml
else
cd $root/examples/httpd
fi

convox apps create ci2 --wait
convox apps | grep ci2
convox apps info ci2 | grep running
Expand Down
1 change: 1 addition & 0 deletions ci/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if [ ! -f /tmp/convox-rack-name ]; then
echo "ci-${CIRCLE_BUILD_NUM}-$(date +"%H%M")" > /tmp/convox-rack-name
fi

export CONVOX_LOCAL=disable
export AWS_DEFAULT_REGION=us-east-1
export AWS_REGION=us-east-1
export RACK_NAME=$(cat /tmp/convox-rack-name)
Expand Down
98 changes: 39 additions & 59 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,44 @@ set -ex
provider=$(convox api get /system | jq -r .provider)
source $(dirname $0)/env.sh

# tests to be run on a full convox.yaml app
# these tests include:
# - apps resources
# - rack resources
# - timer
if [ "${ACTION}" == "full-convox-yaml" ]; then
$root/ci/additonal-test/apps-resources.sh &
apps_resources_pid=$!

$root/ci/additonal-test/rack-resources.sh &
rack_resources_pid=$!

$root/ci/additonal-test/timers.sh &
timer_pid=$!

# Wait for all background processes to complete
wait $apps_resources_pid
apps_resources_exit_code=$?

wait $rack_resources_pid
rack_resources_exit_code=$?

wait $timer_pid
timer_exit_code=$?

echo "apps_resources_exit_code: $apps_resources_exit_code"
echo "rack_resources_exit_code: $rack_resources_exit_code"
echo "timer_exit_code: $timer_exit_code"

# Check exit codes and exit with code 1 if any of them are non-zero
if [ $apps_resources_exit_code -ne 0 ] || [ $rack_resources_exit_code -ne 0 ] || [ $timer_exit_code -ne 0 ]; then
echo "One or more scripts failed"
exit 1
fi

exit 0
fi

# cli
convox version

Expand Down Expand Up @@ -116,28 +154,6 @@ cat /tmp/file2 | grep foo
convox ps stop $ps -a ci2
convox ps -a ci2 | grep -v $ps
convox deploy -a ci2 --wait
ps=$(convox api get /apps/ci2/processes | jq -r '.[]|select(.status=="running")|.id' | head -n 1)
# postgres resource
convox exec -a ci2 $ps -- env | grep "POSTGRES_URL"
convox exec -a ci2 $ps -- env | grep "POSTGRES_USER"
convox exec -a ci2 $ps -- env | grep "POSTGRES_PASS"
convox exec -a ci2 $ps -- env | grep "POSTGRES_HOST"
convox exec -a ci2 $ps -- env | grep "POSTGRES_PORT"
convox exec -a ci2 $ps -- env | grep "POSTGRES_NAME"
# mysql resource
convox exec -a ci2 $ps -- env | grep "MYSQL_URL"
convox exec -a ci2 $ps -- env | grep "MYSQL_USER"
convox exec -a ci2 $ps -- env | grep "MYSQL_PASS"
convox exec -a ci2 $ps -- env | grep "MYSQL_HOST"
convox exec -a ci2 $ps -- env | grep "MYSQL_PORT"
convox exec -a ci2 $ps -- env | grep "MYSQL_NAME"
# mariadb resource
convox exec -a ci2 $ps -- env | grep "MARIADB_URL"
convox exec -a ci2 $ps -- env | grep "MARIADB_USER"
convox exec -a ci2 $ps -- env | grep "MARIADB_PASS"
convox exec -a ci2 $ps -- env | grep "MARIADB_HOST"
convox exec -a ci2 $ps -- env | grep "MARIADB_PORT"
convox exec -a ci2 $ps -- env | grep "MARIADB_NAME"

# test apps cancel
echo "FOO=not-bar" | convox env set -a ci2
Expand Down Expand Up @@ -195,7 +211,7 @@ esac
# gen1
case $provider in
aws)
cd $root/examples/httpd
cd $root/examples/gen1
convox apps create ci1 -g 1 --wait
convox deploy -a ci1 --wait
convox services -a ci1 | grep web | grep elb.amazonaws.com | grep 443:80
Expand Down Expand Up @@ -256,14 +272,6 @@ case $provider in
;;
esac

# timers
sleep 30

timerLog=$(convox logs -a ci2 --no-follow --since 1m | grep service/example)
if ! [[ $timerLog == *"Hello Timer"* ]]; then
echo "failed"; exit 1;
fi

# certs
case $provider in
aws)
Expand All @@ -286,34 +294,6 @@ case $provider in
;;
esac

# rack resources
case $provider in
aws)
convox rack resources create syslog Url=tcp://syslog.convox.com --name cilog --wait
convox rack resources | grep cilog | grep syslog
convox rack resources info cilog | grep -v Apps
convox rack resources url cilog | grep tcp://syslog.convox.com
convox rack resources link cilog -a ci2 --wait
convox rack resources info cilog | grep Apps | grep ci2
convox rack resources unlink cilog -a ci2 --wait
convox rack resources info cilog | grep -v Apps
convox rack resources link cilog -a ci1 --wait
convox rack resources info cilog | grep Apps | grep ci1
convox rack resources unlink cilog -a ci1 --wait
convox rack resources info cilog | grep -v Apps
convox rack resources update cilog Url=tcp://syslog2.convox.com --wait
convox rack resources info cilog | grep syslog2.convox.com
convox rack resources url cilog | grep tcp://syslog2.convox.com
convox rack resources delete cilog --wait
convox rack resources create postgres --name pgdb --wait
convox rack resources | grep pgdb | grep postgres
dburl=$(convox rack resources url pgdb)
convox rack resources update pgdb BackupRetentionPeriod=2 --wait
[ "$dburl" == "$(convox rack resources url pgdb)" ]
convox rack resources delete pgdb --wait
;;
esac

# cleanup
convox apps delete ci2 --wait

Expand Down
8 changes: 8 additions & 0 deletions examples/full-convox-yaml/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM httpd

RUN apt update > /dev/null 2>&1 && \
apt install -y curl > /dev/null 2>&1

COPY . /usr/local/apache2

RUN chmod +x /usr/local/apache2/timer-cmd.sh
49 changes: 49 additions & 0 deletions examples/full-convox-yaml/convox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resources:
postgres:
type: postgres
options:
class: db.t3.micro
version: 14
mysql:
type: mysql
options:
class: db.t3.micro
mariadb:
type: mariadb
options:
class: db.t3.micro
version: 10.6
memcached:
type: memcached
redis:
type: redis
sharedvolume:
type: efs
options:
path: "/app/httpd"
services:
web:
build: .
port: 80
volumes:
# Persistent volumes
- /my/shared/data
- /var/www/html
# Host Volumes
- /sys/fs/cgroup/:/host/sys/fs/cgroup/
- /proc/:/host/proc/
- /var/run/docker.sock:/var/run/docker.sock
# EFS Resource (shared volumes)
- sharedvolume:/app/httpd
resources:
- postgres
- mysql
- mariadb
- memcached
- redis
- sharedvolume
timers:
example:
command: /usr/local/apache2/timer-cmd.sh
schedule: "*/1 * * * ?"
service: web
File renamed without changes.
6 changes: 6 additions & 0 deletions examples/gen1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM httpd

RUN apt update > /dev/null 2>&1 && \
apt install -y curl > /dev/null 2>&1

COPY . /usr/local/apache2
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions examples/httpd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ RUN apt update > /dev/null 2>&1 && \
apt install -y curl > /dev/null 2>&1

COPY . /usr/local/apache2

RUN chmod +x /usr/local/apache2/timer-cmd.sh
Loading

0 comments on commit 3335569

Please sign in to comment.