From 9a4e9535551396f48d27b9d920d5ae434f0e1e35 Mon Sep 17 00:00:00 2001 From: Suraj Deshmukh Date: Sun, 31 Jul 2016 13:34:46 +0000 Subject: [PATCH] Functional Testing Shell scripts to test k8s and os conversion which can be ran by following command in root dir `./script/test/cmd/tests.sh` --- script/test/README.md | 12 + script/test/cmd/globals.sh | 6 + script/test/cmd/lib.sh | 154 ++++++++ script/test/cmd/tests.sh | 55 +++ script/test/fixtures/etherpad/README.md | 14 + .../etherpad/docker-compose-no-image.yml | 11 + .../etherpad/docker-compose-no-ports.yml | 5 + .../test/fixtures/etherpad/docker-compose.yml | 25 ++ script/test/fixtures/etherpad/envs | 6 + script/test/fixtures/etherpad/output-k8s.json | 184 +++++++++ script/test/fixtures/etherpad/output-os.json | 188 +++++++++ script/test/fixtures/flask-redis/README.md | 10 + .../fixtures/flask-redis/docker-compose.yml | 20 + .../test/fixtures/flask-redis/output-k8s.json | 168 ++++++++ .../test/fixtures/flask-redis/output-os.json | 172 ++++++++ script/test/fixtures/gitlab/README.md | 14 + .../test/fixtures/gitlab/docker-compose.yml | 33 ++ script/test/fixtures/gitlab/envs | 5 + script/test/fixtures/gitlab/output-k8s.json | 284 ++++++++++++++ script/test/fixtures/gitlab/output-os.json | 290 ++++++++++++++ .../test/fixtures/ngnix-node-redis/README.md | 7 + .../ngnix-node-redis/docker-compose.yml | 25 ++ .../ngnix-node-redis/nginx/Dockerfile | 8 + .../ngnix-node-redis/nginx/nginx.conf | 26 ++ .../fixtures/ngnix-node-redis/node/Dockerfile | 16 + .../fixtures/ngnix-node-redis/node/index.js | 28 ++ .../ngnix-node-redis/node/package.json | 14 + .../ngnix-node-redis/node/test/dummyTest.js | 7 + .../fixtures/ngnix-node-redis/output-k8s.json | 356 +++++++++++++++++ .../fixtures/ngnix-node-redis/output-os.json | 366 ++++++++++++++++++ script/test/fixtures/wordpress/README.md | 14 + .../fixtures/wordpress/docker-compose.yml | 25 ++ script/test/fixtures/wordpress/envs | 6 + .../test/fixtures/wordpress/output-k8s.json | 180 +++++++++ script/test/fixtures/wordpress/output-os.json | 184 +++++++++ 35 files changed, 2918 insertions(+) create mode 100644 script/test/README.md create mode 100644 script/test/cmd/globals.sh create mode 100644 script/test/cmd/lib.sh create mode 100755 script/test/cmd/tests.sh create mode 100644 script/test/fixtures/etherpad/README.md create mode 100644 script/test/fixtures/etherpad/docker-compose-no-image.yml create mode 100644 script/test/fixtures/etherpad/docker-compose-no-ports.yml create mode 100644 script/test/fixtures/etherpad/docker-compose.yml create mode 100644 script/test/fixtures/etherpad/envs create mode 100644 script/test/fixtures/etherpad/output-k8s.json create mode 100644 script/test/fixtures/etherpad/output-os.json create mode 100644 script/test/fixtures/flask-redis/README.md create mode 100644 script/test/fixtures/flask-redis/docker-compose.yml create mode 100644 script/test/fixtures/flask-redis/output-k8s.json create mode 100644 script/test/fixtures/flask-redis/output-os.json create mode 100644 script/test/fixtures/gitlab/README.md create mode 100644 script/test/fixtures/gitlab/docker-compose.yml create mode 100644 script/test/fixtures/gitlab/envs create mode 100644 script/test/fixtures/gitlab/output-k8s.json create mode 100644 script/test/fixtures/gitlab/output-os.json create mode 100644 script/test/fixtures/ngnix-node-redis/README.md create mode 100644 script/test/fixtures/ngnix-node-redis/docker-compose.yml create mode 100644 script/test/fixtures/ngnix-node-redis/nginx/Dockerfile create mode 100644 script/test/fixtures/ngnix-node-redis/nginx/nginx.conf create mode 100644 script/test/fixtures/ngnix-node-redis/node/Dockerfile create mode 100644 script/test/fixtures/ngnix-node-redis/node/index.js create mode 100644 script/test/fixtures/ngnix-node-redis/node/package.json create mode 100644 script/test/fixtures/ngnix-node-redis/node/test/dummyTest.js create mode 100644 script/test/fixtures/ngnix-node-redis/output-k8s.json create mode 100644 script/test/fixtures/ngnix-node-redis/output-os.json create mode 100644 script/test/fixtures/wordpress/README.md create mode 100644 script/test/fixtures/wordpress/docker-compose.yml create mode 100644 script/test/fixtures/wordpress/envs create mode 100644 script/test/fixtures/wordpress/output-k8s.json create mode 100644 script/test/fixtures/wordpress/output-os.json diff --git a/script/test/README.md b/script/test/README.md new file mode 100644 index 00000000..c69cecba --- /dev/null +++ b/script/test/README.md @@ -0,0 +1,12 @@ +# Functional Test + +### Requirements + +Install `jq - commandline JSON processor` with minimum version of 1.5 + + +### Running tests + +Test running ./cmd/tests.sh + + diff --git a/script/test/cmd/globals.sh b/script/test/cmd/globals.sh new file mode 100644 index 00000000..c2e1f320 --- /dev/null +++ b/script/test/cmd/globals.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +TEMP_DIR="/tmp/kompose/" +TEMP_STDOUT=$TEMP_DIR/test-stdout +TEMP_STDERR=$TEMP_DIR/test-stderr +EXIT_STATUS=0 diff --git a/script/test/cmd/lib.sh b/script/test/cmd/lib.sh new file mode 100644 index 00000000..a9104846 --- /dev/null +++ b/script/test/cmd/lib.sh @@ -0,0 +1,154 @@ +#!/bin/bash + +KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..) +source $KOMPOSE_ROOT/script/test/cmd/globals.sh + +# setup all the things needed to run tests +function convert::init() { + mkdir -p $TEMP_DIR + SUCCESS_MSGS="" + FAIL_MSGS="" +} +readonly -f convert::init + +# remove all the temporary files created for test +function convert::teardown() { + rm -rf $TEMP_DIR + SUCCESS_MSGS="" + FAIL_MSGS="" +} +readonly -f convert::teardown + +# print about test start information +function convert::start_test() { + convert::init + echo -e "\n\n===> Starting test <===" + echo $@ +} +readonly -f convert::start_test + +# print in green about the test being passed +function convert::print_pass() { + tput setaf 2 + tput bold + echo -en "PASS: $@" + tput sgr0 +} +readonly -f convert::print_pass + +# print in red about the test failed +function convert::print_fail() { + tput setaf 1 + tput bold + echo -en "FAIL: $@" + tput sgr0 + +} +readonly -f convert::print_fail + +# run a cmd, which saves stdout output to TEMP_STDOUT +# and saves errors to TEMP_STDERR files and returns exit status +function convert::run_cmd() { + cmd=$@ + + $cmd 2>$TEMP_STDERR >$TEMP_STDOUT + return $? +} +readonly -f convert::run_cmd + +# run the command and match the output to the existing file +# if error then save error string in FAIL_MSGS +# if success save pass string in SUCCESS_MSGS +function convert::match_output() { + local cmd=$1 + local expected_output=$2 + + convert::run_cmd $cmd + exit_status=$? + if [ $exit_status -ne 0 ]; then FAIL_MSGS=$FAIL_MSGS"exit status: $exit_status\n"; return $exit_status; fi + + match=$(jq --argfile a $TEMP_STDOUT --argfile b $expected_output -n 'def post_recurse(f): def r: (f | select(. != null) | r), .; r; def post_recurse: post_recurse(.[]?); ($a | (post_recurse | arrays) |= sort) as $a | ($b | (post_recurse | arrays) |= sort) as $b | $a == $b') + + if ! [ $match ]; then FAIL_MSGS=$FAIL_MSGS"converted output does not match\n"; return 1; + else SUCCESS_MSGS=$SUCCESS_MSGS"converted output matches\n"; return 0; fi +} +readonly -f convert::match_output + +# function called from outside which accecpts cmd to run and +# file to compare output with +function convert::expect_success() { + local cmd=$1 + local expected_output=$2 + + convert::start_test "convert::expect_success: Running: '${cmd}' expected_output: '${expected_output}'" + + convert::match_output "$cmd" "$expected_output" + if [ $? -ne 0 ]; then convert::print_fail $FAIL_MSGS; convert::teardown; EXIT_STATUS=1; return 1; + else convert::print_pass $SUCCESS_MSGS; fi + + # check if no warnings are generated? If yes then fail + warnings=$(stat -c%s $TEMP_STDERR) + if [ $warnings -ne 0 ]; then convert::print_fail "warnings given: $(cat $TEMP_STDERR)"; EXIT_STATUS=1; fi + + convert::teardown +} +readonly -f convert::expect_success + +# function called from outside, which accepts cmd to run, +# expected output file and warnings if any +function convert::expect_success_and_warning() { + local cmd=$1 + local expected_output=$2 + local expected_warning=$3 + + convert::start_test "convert::expect_success_and_warning: Running: '${cmd}' expected_output: '${expected_output}' expected_warning: '${expected_warning}'" + + convert::match_output "$cmd" "$expected_output" + if [ $? -ne 0 ]; then convert::print_fail $FAIL_MSGS; convert::teardown; EXIT_STATUS=1; return 1; + else convert::print_pass $SUCCESS_MSGS; fi + + grep -i "$expected_warning" $TEMP_STDERR > /dev/null + local exit_status=$? + if [ $exit_status -ne 0 ]; then convert::print_fail "no warning found: '$expected_warning'"; EXIT_STATUS=1; + else convert::print_pass "warning found: '$expected_warning'"; fi + + convert::teardown + return $exit_status +} +readonly -f convert::expect_success_and_warning + +# function called from outside, which accepts cmd to run, +# expects warning, without caring if the cmd ran passed or failed +function convert::expect_warning() { + local cmd=$1 + local expected_warning=$2 + + convert::start_test "convert::expect_warning: Running: '${cmd}' expected_warning: '${expected_warning}'" + + $cmd 2>$TEMP_STDERR >$TEMP_STDOUT + + grep -i "$expected_warning" $TEMP_STDERR > /dev/null + local exit_status=$? + if [ $exit_status -ne 0 ]; then convert::print_fail "no warning found: '$expected_warning'"; EXIT_STATUS=1; + else convert::print_pass "warning found: '$expected_warning'"; fi + + convert::teardown + return $exit_status +} +readonly -f convert::expect_warning + +# function called from outside, which accepts cmd to run, +# expects failure, if the command passes then errors out. +function convert::expect_failure() { + local cmd=$1 + + convert::start_test "convert::expect_failure: Running: '${cmd}'" + convert::run_cmd $cmd + exit_status=$? + if [ $exit_status -eq 0 ]; then convert::print_fail "no error output, returned exit status 0"; EXIT_STATUS=1; + else convert::print_pass "errored out with exit status: $exit_status"; fi + + convert::teardown + return $exit_status +} +readonly -f convert::expect_failure diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh new file mode 100755 index 00000000..76d98a6c --- /dev/null +++ b/script/test/cmd/tests.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..) +source $KOMPOSE_ROOT/script/test/cmd/lib.sh + +####### +# Tests related to docker-compose file in /script/test/fixtures/etherpad +convert::expect_failure "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose.yml" +convert::expect_failure "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose-no-image.yml" +convert::expect_warning "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose-no-ports.yml" "Service cannot be created because of missing port." +export $(cat $KOMPOSE_ROOT/script/test/fixtures/etherpad/envs) +# kubernetes test +convert::expect_success_and_warning "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/etherpad/output-k8s.json" "Unsupported key depends_on - ignoring" +# openshift test +convert::expect_success_and_warning "kompose convert --stdout --dc -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/etherpad/output-os.json" "Unsupported key depends_on - ignoring" +unset $(cat $KOMPOSE_ROOT/script/test/fixtures/etherpad/envs | cut -d'=' -f1) + +###### +# Tests related to docker-compose file in script/test/fixtures/flask-redis +# kubernetes test +convert::expect_success_and_warning "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/flask-redis/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/flask-redis/output-k8s.json" "Unsupported key depends_on - ignoring" +# openshift test +convert::expect_success_and_warning "kompose convert --stdout --dc -f $KOMPOSE_ROOT/script/test/fixtures/flask-redis/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/flask-redis/output-os.json" "Unsupported key depends_on - ignoring" + +###### +# Tests related to docker-compose file in /script/test/fixtures/gitlab +convert::expect_failure "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/gitlab/docker-compose.yml" +export $(cat $KOMPOSE_ROOT/script/test/fixtures/gitlab/envs) +# kubernetes test +convert::expect_success "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/gitlab/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/gitlab/output-k8s.json" +# openshift test +convert::expect_success "kompose convert --stdout --dc -f $KOMPOSE_ROOT/script/test/fixtures/gitlab/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/gitlab/output-os.json" +unset $(cat $KOMPOSE_ROOT/script/test/fixtures/gitlab/envs | cut -d'=' -f1) + +###### +# Tests related to docker-compose file in /script/test/fixtures/ngnix-node-redis +# kubernetes test +convert::expect_success_and_warning "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/ngnix-node-redis/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/ngnix-node-redis/output-k8s.json" "Unsupported key build - ignoring" +# openshift test +convert::expect_success_and_warning "kompose convert --stdout --dc -f $KOMPOSE_ROOT/script/test/fixtures/ngnix-node-redis/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/ngnix-node-redis/output-os.json" "Unsupported key build - ignoring" + + +###### +# Tests related to docker-compose file in /script/test/fixtures/wordpress +convert::expect_failure "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/wordpress/docker-compose.yml" +export $(cat $KOMPOSE_ROOT/script/test/fixtures/wordpress/envs) +# kubernetes test +convert::expect_success_and_warning "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/wordpress/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/wordpress/output-k8s.json" "Unsupported key depends_on - ignoring" +# openshift test +convert::expect_success_and_warning "kompose convert --stdout -f $KOMPOSE_ROOT/script/test/fixtures/wordpress/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/wordpress/output-os.json" "Unsupported key depends_on - ignoring" +unset $(cat $KOMPOSE_ROOT/script/test/fixtures/wordpress/envs | cut -d'=' -f1) + + +exit $EXIT_STATUS + diff --git a/script/test/fixtures/etherpad/README.md b/script/test/fixtures/etherpad/README.md new file mode 100644 index 00000000..61887d75 --- /dev/null +++ b/script/test/fixtures/etherpad/README.md @@ -0,0 +1,14 @@ +## Docker Compose Etherpad + +Etherpad and Mariadb + +### Usage + +The simplest thing to do: + +```bash +export $(cat envs) +docker-compose up +``` + +To customize the values edit `envs` file. diff --git a/script/test/fixtures/etherpad/docker-compose-no-image.yml b/script/test/fixtures/etherpad/docker-compose-no-image.yml new file mode 100644 index 00000000..513936a4 --- /dev/null +++ b/script/test/fixtures/etherpad/docker-compose-no-image.yml @@ -0,0 +1,11 @@ +version: "2" + +services: + mariadb: + ports: + - 3306 + + etherpad: + ports: + - "80:9001" + diff --git a/script/test/fixtures/etherpad/docker-compose-no-ports.yml b/script/test/fixtures/etherpad/docker-compose-no-ports.yml new file mode 100644 index 00000000..efc1a53d --- /dev/null +++ b/script/test/fixtures/etherpad/docker-compose-no-ports.yml @@ -0,0 +1,5 @@ +version: "2" + +services: + mariadb: + image: centos/mariadb diff --git a/script/test/fixtures/etherpad/docker-compose.yml b/script/test/fixtures/etherpad/docker-compose.yml new file mode 100644 index 00000000..4cb3b23a --- /dev/null +++ b/script/test/fixtures/etherpad/docker-compose.yml @@ -0,0 +1,25 @@ +version: "2" + +services: + mariadb: + image: centos/mariadb + ports: + - "$DB_PORT" + environment: + MYSQL_ROOT_PASSWORD: $ROOT_PASS + MYSQL_DATABASE: $DB_NAME + MYSQL_PASSWORD: $DB_PASS + MYSQL_USER: $DB_USER + + etherpad: + image: centos/etherpad + ports: + - "80:9001" + depends_on: + - mariadb + environment: + DB_HOST: $DB_HOST + DB_DBID: $DB_NAME + DB_PASS: $DB_PASS + DB_PORT: $DB_PORT + DB_USER: $DB_USER diff --git a/script/test/fixtures/etherpad/envs b/script/test/fixtures/etherpad/envs new file mode 100644 index 00000000..d02528d6 --- /dev/null +++ b/script/test/fixtures/etherpad/envs @@ -0,0 +1,6 @@ +DB_HOST=mariadb +ROOT_PASS=etherpad +DB_NAME=etherpad +DB_PASS=etherpad +DB_USER=etherpad +DB_PORT=3306 diff --git a/script/test/fixtures/etherpad/output-k8s.json b/script/test/fixtures/etherpad/output-k8s.json new file mode 100644 index 00000000..ef62ccf1 --- /dev/null +++ b/script/test/fixtures/etherpad/output-k8s.json @@ -0,0 +1,184 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "mariadb", + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "ports": [ + { + "name": "3306", + "protocol": "TCP", + "port": 3306, + "targetPort": 3306 + } + ], + "selector": { + "service": "mariadb" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "etherpad", + "creationTimestamp": null, + "labels": { + "service": "etherpad" + } + }, + "spec": { + "ports": [ + { + "name": "80", + "protocol": "TCP", + "port": 80, + "targetPort": 9001 + } + ], + "selector": { + "service": "etherpad" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "etherpad", + "creationTimestamp": null, + "labels": { + "service": "etherpad" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "etherpad" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "etherpad" + } + }, + "spec": { + "containers": [ + { + "name": "etherpad", + "image": "centos/etherpad", + "ports": [ + { + "containerPort": 9001, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "DB_HOST", + "value": "mariadb" + }, + { + "name": "DB_PASS", + "value": "etherpad" + }, + { + "name": "DB_PORT", + "value": "3306" + }, + { + "name": "DB_USER", + "value": "etherpad" + }, + { + "name": "DB_DBID", + "value": "etherpad" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "mariadb", + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "mariadb" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "containers": [ + { + "name": "mariadb", + "image": "centos/mariadb", + "ports": [ + { + "containerPort": 3306, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "MYSQL_USER", + "value": "etherpad" + }, + { + "name": "MYSQL_DATABASE", + "value": "etherpad" + }, + { + "name": "MYSQL_PASSWORD", + "value": "etherpad" + }, + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "etherpad" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} diff --git a/script/test/fixtures/etherpad/output-os.json b/script/test/fixtures/etherpad/output-os.json new file mode 100644 index 00000000..02cb4534 --- /dev/null +++ b/script/test/fixtures/etherpad/output-os.json @@ -0,0 +1,188 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "etherpad", + "creationTimestamp": null, + "labels": { + "service": "etherpad" + } + }, + "spec": { + "ports": [ + { + "name": "80", + "protocol": "TCP", + "port": 80, + "targetPort": 9001 + } + ], + "selector": { + "service": "etherpad" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "mariadb", + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "ports": [ + { + "name": "3306", + "protocol": "TCP", + "port": 3306, + "targetPort": 3306 + } + ], + "selector": { + "service": "mariadb" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "etherpad", + "creationTimestamp": null, + "labels": { + "service": "etherpad" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "etherpad" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "etherpad" + } + }, + "spec": { + "containers": [ + { + "name": "etherpad", + "image": "centos/etherpad", + "ports": [ + { + "containerPort": 9001, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "DB_PORT", + "value": "3306" + }, + { + "name": "DB_USER", + "value": "etherpad" + }, + { + "name": "DB_DBID", + "value": "etherpad" + }, + { + "name": "DB_HOST", + "value": "mariadb" + }, + { + "name": "DB_PASS", + "value": "etherpad" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "mariadb", + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "mariadb" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "containers": [ + { + "name": "mariadb", + "image": "centos/mariadb", + "ports": [ + { + "containerPort": 3306, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "etherpad" + }, + { + "name": "MYSQL_USER", + "value": "etherpad" + }, + { + "name": "MYSQL_DATABASE", + "value": "etherpad" + }, + { + "name": "MYSQL_PASSWORD", + "value": "etherpad" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} diff --git a/script/test/fixtures/flask-redis/README.md b/script/test/fixtures/flask-redis/README.md new file mode 100644 index 00000000..0c6bb710 --- /dev/null +++ b/script/test/fixtures/flask-redis/README.md @@ -0,0 +1,10 @@ +## Flask and Redis + +For running this app + + +```bash +mkdir /opt/redis +sudo chcon -Rt svirt_sandbox_file_t /opt/redis +docker-compose up +``` diff --git a/script/test/fixtures/flask-redis/docker-compose.yml b/script/test/fixtures/flask-redis/docker-compose.yml new file mode 100644 index 00000000..11e647df --- /dev/null +++ b/script/test/fixtures/flask-redis/docker-compose.yml @@ -0,0 +1,20 @@ +version: "2" + +services: + redis: + image: dharmit/redis + command: redis-server + ports: + - "6379" + volumes: + - /opt/redis:/redis + + flask: + image: dharmit/flask + ports: + - "31000:5000" + depends_on: + - redis + environment: + REDIS_PORT: 6379 + REDIS_HOST: redis diff --git a/script/test/fixtures/flask-redis/output-k8s.json b/script/test/fixtures/flask-redis/output-k8s.json new file mode 100644 index 00000000..4d6f2cd1 --- /dev/null +++ b/script/test/fixtures/flask-redis/output-k8s.json @@ -0,0 +1,168 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "ports": [ + { + "name": "6379", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379 + } + ], + "selector": { + "service": "redis" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "flask", + "creationTimestamp": null, + "labels": { + "service": "flask" + } + }, + "spec": { + "ports": [ + { + "name": "31000", + "protocol": "TCP", + "port": 31000, + "targetPort": 5000 + } + ], + "selector": { + "service": "flask" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "redis" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "volumes": [ + { + "name": "fpllngzieyoh43e0133o", + "hostPath": { + "path": "/opt/redis" + } + } + ], + "containers": [ + { + "name": "redis", + "image": "dharmit/redis", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "resources": {}, + "volumeMounts": [ + { + "name": "fpllngzieyoh43e0133o", + "mountPath": "/redis" + } + ] + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "flask", + "creationTimestamp": null, + "labels": { + "service": "flask" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "flask" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "flask" + } + }, + "spec": { + "containers": [ + { + "name": "flask", + "image": "dharmit/flask", + "ports": [ + { + "containerPort": 5000, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "REDIS_HOST", + "value": "redis" + }, + { + "name": "REDIS_PORT", + "value": "6379" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} diff --git a/script/test/fixtures/flask-redis/output-os.json b/script/test/fixtures/flask-redis/output-os.json new file mode 100644 index 00000000..ae71fc4d --- /dev/null +++ b/script/test/fixtures/flask-redis/output-os.json @@ -0,0 +1,172 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "ports": [ + { + "name": "6379", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379 + } + ], + "selector": { + "service": "redis" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "flask", + "creationTimestamp": null, + "labels": { + "service": "flask" + } + }, + "spec": { + "ports": [ + { + "name": "31000", + "protocol": "TCP", + "port": 31000, + "targetPort": 5000 + } + ], + "selector": { + "service": "flask" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "redis" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "volumes": [ + { + "name": "fpllngzieyoh43e0133o", + "hostPath": { + "path": "/opt/redis" + } + } + ], + "containers": [ + { + "name": "redis", + "image": "dharmit/redis", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "resources": {}, + "volumeMounts": [ + { + "name": "fpllngzieyoh43e0133o", + "mountPath": "/redis" + } + ] + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "flask", + "creationTimestamp": null, + "labels": { + "service": "flask" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "flask" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "flask" + } + }, + "spec": { + "containers": [ + { + "name": "flask", + "image": "dharmit/flask", + "ports": [ + { + "containerPort": 5000, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "REDIS_HOST", + "value": "redis" + }, + { + "name": "REDIS_PORT", + "value": "6379" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} diff --git a/script/test/fixtures/gitlab/README.md b/script/test/fixtures/gitlab/README.md new file mode 100644 index 00000000..f275d378 --- /dev/null +++ b/script/test/fixtures/gitlab/README.md @@ -0,0 +1,14 @@ +## Gitlab + +Gitlab, Postgresql, Redis + +### Usage + +The simplest thing to do: + +```bash +export $(cat envs) +docker-compose up +``` + +To customize the values edit `envs` file. diff --git a/script/test/fixtures/gitlab/docker-compose.yml b/script/test/fixtures/gitlab/docker-compose.yml new file mode 100644 index 00000000..602db296 --- /dev/null +++ b/script/test/fixtures/gitlab/docker-compose.yml @@ -0,0 +1,33 @@ +version: "2" + +services: + postgresql: + image: swordphilic/postgresql + ports: + - "$DB_PORT" + environment: + DB_NAME: $DB_NAME + DB_PASS: $DB_PASS + DB_USER: $DB_USER + + gitlab: + image: swordphilic/gitlab + ports: + - "30000:80" + - "30001:443" + - "30002:22" + restart: always + environment: + DB_TYPE: postgres + DB_HOST: postgresql + DB_PORT: $DB_PORT + DB_NAME: $DB_NAME + DB_PASS: $DB_PASS + DB_USER: $DB_USER + REDIS_HOST: redis + REDIS_PORT: $REDIS_PORT + + redis: + image: swordphilic/redis + ports: + - "$REDIS_PORT" diff --git a/script/test/fixtures/gitlab/envs b/script/test/fixtures/gitlab/envs new file mode 100644 index 00000000..fe1e0d2e --- /dev/null +++ b/script/test/fixtures/gitlab/envs @@ -0,0 +1,5 @@ +DB_PORT=5432 +DB_NAME=gitlab +DB_PASS=gitlab +DB_USER=gitlab +REDIS_PORT=6379 diff --git a/script/test/fixtures/gitlab/output-k8s.json b/script/test/fixtures/gitlab/output-k8s.json new file mode 100644 index 00000000..aafc4de0 --- /dev/null +++ b/script/test/fixtures/gitlab/output-k8s.json @@ -0,0 +1,284 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "ports": [ + { + "name": "6379", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379 + } + ], + "selector": { + "service": "redis" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "gitlab", + "creationTimestamp": null, + "labels": { + "service": "gitlab" + } + }, + "spec": { + "ports": [ + { + "name": "30000", + "protocol": "TCP", + "port": 30000, + "targetPort": 80 + }, + { + "name": "30001", + "protocol": "TCP", + "port": 30001, + "targetPort": 443 + }, + { + "name": "30002", + "protocol": "TCP", + "port": 30002, + "targetPort": 22 + } + ], + "selector": { + "service": "gitlab" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "postgresql", + "creationTimestamp": null, + "labels": { + "service": "postgresql" + } + }, + "spec": { + "ports": [ + { + "name": "5432", + "protocol": "TCP", + "port": 5432, + "targetPort": 5432 + } + ], + "selector": { + "service": "postgresql" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "redis" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": "swordphilic/redis", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "gitlab", + "creationTimestamp": null, + "labels": { + "service": "gitlab" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "gitlab" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "gitlab" + } + }, + "spec": { + "containers": [ + { + "name": "gitlab", + "image": "swordphilic/gitlab", + "ports": [ + { + "containerPort": 80, + "protocol": "TCP" + }, + { + "containerPort": 443, + "protocol": "TCP" + }, + { + "containerPort": 22, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "DB_HOST", + "value": "postgresql" + }, + { + "name": "DB_NAME", + "value": "gitlab" + }, + { + "name": "DB_PASS", + "value": "gitlab" + }, + { + "name": "DB_PORT", + "value": "5432" + }, + { + "name": "DB_TYPE", + "value": "postgres" + }, + { + "name": "DB_USER", + "value": "gitlab" + }, + { + "name": "REDIS_HOST", + "value": "redis" + }, + { + "name": "REDIS_PORT", + "value": "6379" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "postgresql", + "creationTimestamp": null, + "labels": { + "service": "postgresql" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "postgresql" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "postgresql" + } + }, + "spec": { + "containers": [ + { + "name": "postgresql", + "image": "swordphilic/postgresql", + "ports": [ + { + "containerPort": 5432, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "DB_NAME", + "value": "gitlab" + }, + { + "name": "DB_PASS", + "value": "gitlab" + }, + { + "name": "DB_USER", + "value": "gitlab" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} diff --git a/script/test/fixtures/gitlab/output-os.json b/script/test/fixtures/gitlab/output-os.json new file mode 100644 index 00000000..b9ec8ce4 --- /dev/null +++ b/script/test/fixtures/gitlab/output-os.json @@ -0,0 +1,290 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "postgresql", + "creationTimestamp": null, + "labels": { + "service": "postgresql" + } + }, + "spec": { + "ports": [ + { + "name": "5432", + "protocol": "TCP", + "port": 5432, + "targetPort": 5432 + } + ], + "selector": { + "service": "postgresql" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "ports": [ + { + "name": "6379", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379 + } + ], + "selector": { + "service": "redis" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "gitlab", + "creationTimestamp": null, + "labels": { + "service": "gitlab" + } + }, + "spec": { + "ports": [ + { + "name": "30000", + "protocol": "TCP", + "port": 30000, + "targetPort": 80 + }, + { + "name": "30001", + "protocol": "TCP", + "port": 30001, + "targetPort": 443 + }, + { + "name": "30002", + "protocol": "TCP", + "port": 30002, + "targetPort": 22 + } + ], + "selector": { + "service": "gitlab" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "postgresql", + "creationTimestamp": null, + "labels": { + "service": "postgresql" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "postgresql" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "postgresql" + } + }, + "spec": { + "containers": [ + { + "name": "postgresql", + "image": "swordphilic/postgresql", + "ports": [ + { + "containerPort": 5432, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "DB_NAME", + "value": "gitlab" + }, + { + "name": "DB_PASS", + "value": "gitlab" + }, + { + "name": "DB_USER", + "value": "gitlab" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "redis" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": "swordphilic/redis", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "gitlab", + "creationTimestamp": null, + "labels": { + "service": "gitlab" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "gitlab" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "gitlab" + } + }, + "spec": { + "containers": [ + { + "name": "gitlab", + "image": "swordphilic/gitlab", + "ports": [ + { + "containerPort": 80, + "protocol": "TCP" + }, + { + "containerPort": 443, + "protocol": "TCP" + }, + { + "containerPort": 22, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "DB_HOST", + "value": "postgresql" + }, + { + "name": "DB_NAME", + "value": "gitlab" + }, + { + "name": "DB_PASS", + "value": "gitlab" + }, + { + "name": "DB_PORT", + "value": "5432" + }, + { + "name": "DB_TYPE", + "value": "postgres" + }, + { + "name": "DB_USER", + "value": "gitlab" + }, + { + "name": "REDIS_HOST", + "value": "redis" + }, + { + "name": "REDIS_PORT", + "value": "6379" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} diff --git a/script/test/fixtures/ngnix-node-redis/README.md b/script/test/fixtures/ngnix-node-redis/README.md new file mode 100644 index 00000000..7c87377c --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/README.md @@ -0,0 +1,7 @@ +### Usage + +Ref: http://anandmanisankar.com/posts/docker-container-nginx-node-redis-example/ + +```bash +docker-compose up +``` diff --git a/script/test/fixtures/ngnix-node-redis/docker-compose.yml b/script/test/fixtures/ngnix-node-redis/docker-compose.yml new file mode 100644 index 00000000..c81f6863 --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/docker-compose.yml @@ -0,0 +1,25 @@ +version: "2" + +services: + nginx: + build: ./nginx + ports: + - "80:80" + restart: always + + node1: + build: ./node + ports: + - "8080" + node2: + build: ./node + ports: + - "8080" + node3: + build: ./node + ports: + - "8080" + redis: + image: redis + ports: + - "6379" diff --git a/script/test/fixtures/ngnix-node-redis/nginx/Dockerfile b/script/test/fixtures/ngnix-node-redis/nginx/Dockerfile new file mode 100644 index 00000000..2e662eb7 --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/nginx/Dockerfile @@ -0,0 +1,8 @@ +# Set nginx base image +FROM nginx + +# File Author / Maintainer +MAINTAINER Anand Mani Sankar + +# Copy custom configuration file from the current directory +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/script/test/fixtures/ngnix-node-redis/nginx/nginx.conf b/script/test/fixtures/ngnix-node-redis/nginx/nginx.conf new file mode 100644 index 00000000..19cd5f97 --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/nginx/nginx.conf @@ -0,0 +1,26 @@ +worker_processes 4; + +events { worker_connections 1024; } + +http { + + upstream node-app { + least_conn; + server node1:8080 weight=60 max_fails=10 fail_timeout=60s; + server node2:8080 weight=60 max_fails=10 fail_timeout=60s; + server node3:8080 weight=60 max_fails=10 fail_timeout=60s; + } + + server { + listen 80; + + location / { + proxy_pass http://node-app; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + } +} diff --git a/script/test/fixtures/ngnix-node-redis/node/Dockerfile b/script/test/fixtures/ngnix-node-redis/node/Dockerfile new file mode 100644 index 00000000..b2f95cb4 --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/node/Dockerfile @@ -0,0 +1,16 @@ +FROM centos:7 + +RUN yum -y install epel-release && yum install -y nodejs npm gcc* make +RUN /bin/bash -c 'npm install -g nodemon' && mkdir /src + +# Define working directory +WORKDIR /src +ADD . /src + +RUN cd /src && npm install + +# Expose port +EXPOSE 8080 + +# Run app using nodemon +CMD /bin/bash -c 'nodemon /src/index.js' diff --git a/script/test/fixtures/ngnix-node-redis/node/index.js b/script/test/fixtures/ngnix-node-redis/node/index.js new file mode 100644 index 00000000..d01e517d --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/node/index.js @@ -0,0 +1,28 @@ +var express = require('express'), + http = require('http'), + redis = require('redis'); + +var app = express(); + +console.log(process.env.REDIS_PORT_6379_TCP_ADDR + ':' + process.env.REDIS_PORT_6379_TCP_PORT); + +// APPROACH 1: Using environment variables created by Docker +// var client = redis.createClient( +// process.env.REDIS_PORT_6379_TCP_PORT, +// process.env.REDIS_PORT_6379_TCP_ADDR +// ); + +// APPROACH 2: Using host entries created by Docker in /etc/hosts (RECOMMENDED) +var client = redis.createClient('6379', 'redis'); + + +app.get('/', function(req, res, next) { + client.incr('counter', function(err, counter) { + if(err) return next(err); + res.send('This page has been viewed ' + counter + ' times!'); + }); +}); + +http.createServer(app).listen(process.env.PORT || 8080, function() { + console.log('Listening on port ' + (process.env.PORT || 8080)); +}); \ No newline at end of file diff --git a/script/test/fixtures/ngnix-node-redis/node/package.json b/script/test/fixtures/ngnix-node-redis/node/package.json new file mode 100644 index 00000000..4d59b392 --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/node/package.json @@ -0,0 +1,14 @@ +{ + "name": "node", + "version": "1.0.0", + "description": "", + "main": "index.js", + "author": "Anand Mani Sankar", + "license": "ISC", + "dependencies": { + "express": "^4.12.3", + "hiredis": "^0.2.0", + "mocha": "^2.2.1", + "redis": "^0.12.1" + } +} diff --git a/script/test/fixtures/ngnix-node-redis/node/test/dummyTest.js b/script/test/fixtures/ngnix-node-redis/node/test/dummyTest.js new file mode 100644 index 00000000..6218a87f --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/node/test/dummyTest.js @@ -0,0 +1,7 @@ +var assert = require("assert"); + +describe('Dummy Test', function(){ + it('should pass', function(){ + assert.ok(true, "It is true!"); + }); +}); \ No newline at end of file diff --git a/script/test/fixtures/ngnix-node-redis/output-k8s.json b/script/test/fixtures/ngnix-node-redis/output-k8s.json new file mode 100644 index 00000000..e250fdd0 --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/output-k8s.json @@ -0,0 +1,356 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "ports": [ + { + "name": "6379", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379 + } + ], + "selector": { + "service": "redis" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "nginx", + "creationTimestamp": null, + "labels": { + "service": "nginx" + } + }, + "spec": { + "ports": [ + { + "name": "80", + "protocol": "TCP", + "port": 80, + "targetPort": 80 + } + ], + "selector": { + "service": "nginx" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "node1", + "creationTimestamp": null, + "labels": { + "service": "node1" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "protocol": "TCP", + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "service": "node1" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "node2", + "creationTimestamp": null, + "labels": { + "service": "node2" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "protocol": "TCP", + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "service": "node2" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "node3", + "creationTimestamp": null, + "labels": { + "service": "node3" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "protocol": "TCP", + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "service": "node3" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "nginx", + "creationTimestamp": null, + "labels": { + "service": "nginx" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "nginx" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "nginx" + } + }, + "spec": { + "containers": [ + { + "name": "nginx", + "ports": [ + { + "containerPort": 80, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "node1", + "creationTimestamp": null, + "labels": { + "service": "node1" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "node1" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "node1" + } + }, + "spec": { + "containers": [ + { + "name": "node1", + "ports": [ + { + "containerPort": 8080, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "node2", + "creationTimestamp": null, + "labels": { + "service": "node2" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "node2" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "node2" + } + }, + "spec": { + "containers": [ + { + "name": "node2", + "ports": [ + { + "containerPort": 8080, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "node3", + "creationTimestamp": null, + "labels": { + "service": "node3" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "node3" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "node3" + } + }, + "spec": { + "containers": [ + { + "name": "node3", + "ports": [ + { + "containerPort": 8080, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "redis" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": "redis", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} diff --git a/script/test/fixtures/ngnix-node-redis/output-os.json b/script/test/fixtures/ngnix-node-redis/output-os.json new file mode 100644 index 00000000..3f02f26c --- /dev/null +++ b/script/test/fixtures/ngnix-node-redis/output-os.json @@ -0,0 +1,366 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "node3", + "creationTimestamp": null, + "labels": { + "service": "node3" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "protocol": "TCP", + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "service": "node3" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "ports": [ + { + "name": "6379", + "protocol": "TCP", + "port": 6379, + "targetPort": 6379 + } + ], + "selector": { + "service": "redis" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "nginx", + "creationTimestamp": null, + "labels": { + "service": "nginx" + } + }, + "spec": { + "ports": [ + { + "name": "80", + "protocol": "TCP", + "port": 80, + "targetPort": 80 + } + ], + "selector": { + "service": "nginx" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "node1", + "creationTimestamp": null, + "labels": { + "service": "node1" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "protocol": "TCP", + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "service": "node1" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "node2", + "creationTimestamp": null, + "labels": { + "service": "node2" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "protocol": "TCP", + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "service": "node2" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "nginx", + "creationTimestamp": null, + "labels": { + "service": "nginx" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "nginx" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "nginx" + } + }, + "spec": { + "containers": [ + { + "name": "nginx", + "ports": [ + { + "containerPort": 80, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "node1", + "creationTimestamp": null, + "labels": { + "service": "node1" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "node1" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "node1" + } + }, + "spec": { + "containers": [ + { + "name": "node1", + "ports": [ + { + "containerPort": 8080, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "node2", + "creationTimestamp": null, + "labels": { + "service": "node2" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "node2" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "node2" + } + }, + "spec": { + "containers": [ + { + "name": "node2", + "ports": [ + { + "containerPort": 8080, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "node3", + "creationTimestamp": null, + "labels": { + "service": "node3" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "node3" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "node3" + } + }, + "spec": { + "containers": [ + { + "name": "node3", + "ports": [ + { + "containerPort": 8080, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "redis" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": "redis", + "ports": [ + { + "containerPort": 6379, + "protocol": "TCP" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} diff --git a/script/test/fixtures/wordpress/README.md b/script/test/fixtures/wordpress/README.md new file mode 100644 index 00000000..58dacca4 --- /dev/null +++ b/script/test/fixtures/wordpress/README.md @@ -0,0 +1,14 @@ +## Docker Compose Wordpress + +Wordpress and Mariadb + +### Usage + +The simplest thing to do: + +```bash +export $(cat envs) +docker-compose up +``` + +To customize the values edit `envs` file. diff --git a/script/test/fixtures/wordpress/docker-compose.yml b/script/test/fixtures/wordpress/docker-compose.yml new file mode 100644 index 00000000..fd9fb7ec --- /dev/null +++ b/script/test/fixtures/wordpress/docker-compose.yml @@ -0,0 +1,25 @@ +version: "2" + +services: + mariadb: + image: centos/mariadb + ports: + - "$DB_PORT" + environment: + MYSQL_ROOT_PASSWORD: $ROOT_PASS + MYSQL_DATABASE: $DB_NAME + MYSQL_PASSWORD: $DB_PASS + MYSQL_USER: $DB_USER + + wordpress: + image: wordpress + ports: + - "8080:80" + depends_on: + - mariadb + restart: always + environment: + WORDPRESS_DB_HOST: $DB_HOST:$DB_PORT + WORDPRESS_DB_NAME: $DB_NAME + WORDPRESS_DB_PASSWORD: $DB_PASS + WORDPRESS_DB_USER: $DB_USER diff --git a/script/test/fixtures/wordpress/envs b/script/test/fixtures/wordpress/envs new file mode 100644 index 00000000..aec23016 --- /dev/null +++ b/script/test/fixtures/wordpress/envs @@ -0,0 +1,6 @@ +DB_HOST=mariadb +ROOT_PASS=wordpress +DB_NAME=wordpress +DB_PASS=wordpress +DB_USER=wordpress +DB_PORT=3306 diff --git a/script/test/fixtures/wordpress/output-k8s.json b/script/test/fixtures/wordpress/output-k8s.json new file mode 100644 index 00000000..b347d831 --- /dev/null +++ b/script/test/fixtures/wordpress/output-k8s.json @@ -0,0 +1,180 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "mariadb", + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "ports": [ + { + "name": "3306", + "protocol": "TCP", + "port": 3306, + "targetPort": 3306 + } + ], + "selector": { + "service": "mariadb" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "service": "wordpress" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "protocol": "TCP", + "port": 8080, + "targetPort": 80 + } + ], + "selector": { + "service": "wordpress" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "mariadb", + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "mariadb" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "containers": [ + { + "name": "mariadb", + "image": "centos/mariadb", + "ports": [ + { + "containerPort": 3306, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "MYSQL_PASSWORD", + "value": "wordpress" + }, + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "wordpress" + }, + { + "name": "MYSQL_USER", + "value": "wordpress" + }, + { + "name": "MYSQL_DATABASE", + "value": "wordpress" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} +{ + "kind": "Deployment", + "apiVersion": "extensions/v1beta1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "service": "wordpress" + } + }, + "spec": { + "replicas": 1, + "selector": { + "matchLabels": { + "service": "wordpress" + } + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "wordpress" + } + }, + "spec": { + "containers": [ + { + "name": "wordpress", + "image": "wordpress", + "ports": [ + { + "containerPort": 80, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "WORDPRESS_DB_HOST", + "value": "mariadb:3306" + }, + { + "name": "WORDPRESS_DB_NAME", + "value": "wordpress" + }, + { + "name": "WORDPRESS_DB_PASSWORD", + "value": "wordpress" + }, + { + "name": "WORDPRESS_DB_USER", + "value": "wordpress" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + }, + "strategy": {} + }, + "status": {} +} diff --git a/script/test/fixtures/wordpress/output-os.json b/script/test/fixtures/wordpress/output-os.json new file mode 100644 index 00000000..9979cff7 --- /dev/null +++ b/script/test/fixtures/wordpress/output-os.json @@ -0,0 +1,184 @@ +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "service": "wordpress" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "protocol": "TCP", + "port": 8080, + "targetPort": 80 + } + ], + "selector": { + "service": "wordpress" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "mariadb", + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "ports": [ + { + "name": "3306", + "protocol": "TCP", + "port": 3306, + "targetPort": 3306 + } + ], + "selector": { + "service": "mariadb" + } + }, + "status": { + "loadBalancer": {} + } +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "wordpress", + "creationTimestamp": null, + "labels": { + "service": "wordpress" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "wordpress" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "wordpress" + } + }, + "spec": { + "containers": [ + { + "name": "wordpress", + "image": "wordpress", + "ports": [ + { + "containerPort": 80, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "WORDPRESS_DB_NAME", + "value": "wordpress" + }, + { + "name": "WORDPRESS_DB_PASSWORD", + "value": "wordpress" + }, + { + "name": "WORDPRESS_DB_USER", + "value": "wordpress" + }, + { + "name": "WORDPRESS_DB_HOST", + "value": "mariadb:3306" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +} +{ + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "mariadb", + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": null, + "replicas": 1, + "test": false, + "selector": { + "service": "mariadb" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "service": "mariadb" + } + }, + "spec": { + "containers": [ + { + "name": "mariadb", + "image": "centos/mariadb", + "ports": [ + { + "containerPort": 3306, + "protocol": "TCP" + } + ], + "env": [ + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "wordpress" + }, + { + "name": "MYSQL_USER", + "value": "wordpress" + }, + { + "name": "MYSQL_DATABASE", + "value": "wordpress" + }, + { + "name": "MYSQL_PASSWORD", + "value": "wordpress" + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} +}