diff --git a/.travis.yml b/.travis.yml index b2bdd482..7b722f8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,8 @@ matrix: install: - true + # This is required because sometimes Travis ends up in a detached HEAD state after git clone + - script/test/cmd/fix_detached_head.sh script: - make test diff --git a/script/test/cmd/fix_detached_head.sh b/script/test/cmd/fix_detached_head.sh new file mode 100755 index 00000000..912246a2 --- /dev/null +++ b/script/test/cmd/fix_detached_head.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Copyright 2017 The Kubernetes Authors All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Reference Link: https://github.com/theochem/horton/blob/master/tools/qa/fix_detached_head.sh + +# Only do something if the HEAD is detached. +if [ $(git rev-parse --abbrev-ref HEAD) == 'HEAD' ]; then + # Give the some random name that no serious person would use. + git checkout -b build_branch +fi diff --git a/script/test/cmd/tests.sh b/script/test/cmd/tests.sh index b3f7a7c5..07aed44c 100755 --- a/script/test/cmd/tests.sh +++ b/script/test/cmd/tests.sh @@ -17,6 +17,19 @@ KOMPOSE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/../../..) source $KOMPOSE_ROOT/script/test/cmd/lib.sh +# Get current branch and remote url of git repository +branch=$(git branch | grep \* | cut -d ' ' -f2-) + +uri=$(git remote get-url origin) +if [[ $uri != *".git"* ]]; then + uri="${uri}.git" +fi + +# Warning Template +warning="Buildconfig using $uri::$branch as source." +# Replacing variables with current branch and uri +sed -e "s;%URI%;$uri;g" -e "s;%REF%;$branch;g" $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os-template.json > /tmp/output-os.json + ####### # Tests related to docker-compose file in /script/test/fixtures/etherpad convert::expect_failure "kompose -f $KOMPOSE_ROOT/script/test/fixtures/etherpad/docker-compose.yml convert --stdout" @@ -45,8 +58,7 @@ unset $(cat $KOMPOSE_ROOT/script/test/fixtures/gitlab/envs | cut -d'=' -f1) # kubernetes test convert::expect_success_and_warning "kompose -f $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-k8s.json" "Kubernetes provider doesn't support build key - ignoring" # openshift test -convert::expect_success_and_warning "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/docker-compose.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os.json" "Buildconfig using https://github.com/kubernetes-incubator/kompose.git::HEAD as source." - +convert::expect_success_and_warning "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/docker-compose.yml convert --stdout -j" "/tmp/output-os.json" "$warning" ###### # Tests related to docker-compose file in /script/test/fixtures/entrypoint-command # kubernetes test @@ -199,11 +211,11 @@ convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/script/test/fixture # Test regarding build context (running kompose from various directories) CURRENT_DIR=$(pwd) cd "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/" -convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os.json" "Buildconfig using https://github.com/kubernetes-incubator/kompose.git::HEAD as source." +convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j" "/tmp/output-os.json" "$warning" cd "$KOMPOSE_ROOT/script/test/fixtures/" -convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j -f nginx-node-redis/docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os.json" "Buildconfig using https://github.com/kubernetes-incubator/kompose.git::HEAD as source." +convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j -f nginx-node-redis/docker-compose.yml" "/tmp/output-os.json" "$warning" cd "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/node" -convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j -f ../docker-compose.yml" "$KOMPOSE_ROOT/script/test/fixtures/nginx-node-redis/output-os.json" "Buildconfig using https://github.com/kubernetes-incubator/kompose.git::HEAD as source." +convert::expect_success_and_warning "kompose convert --provider openshift --stdout -j -f ../docker-compose.yml" "/tmp/output-os.json" "$warning" cd $CURRENT_DIR # Test related to support docker-compose.yaml beside docker-compose.yml @@ -222,4 +234,7 @@ convert::expect_success "kompose --provider=openshift convert --stdout -j" "$KOM # Return back to the original path cd $CURRENT_DIR +# Removes generated output +rm -rf /tmp/output-os.json + exit $EXIT_STATUS diff --git a/script/test/fixtures/nginx-node-redis/output-os.json b/script/test/fixtures/nginx-node-redis/output-os-template.json similarity index 97% rename from script/test/fixtures/nginx-node-redis/output-os.json rename to script/test/fixtures/nginx-node-redis/output-os-template.json index 764f1478..202cbb81 100644 --- a/script/test/fixtures/nginx-node-redis/output-os.json +++ b/script/test/fixtures/nginx-node-redis/output-os-template.json @@ -3,6 +3,58 @@ "apiVersion": "v1", "metadata": {}, "items": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "nginx", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "nginx" + } + }, + "spec": { + "ports": [ + { + "name": "80", + "port": 80, + "targetPort": 80 + } + ], + "selector": { + "io.kompose.service": "nginx" + } + }, + "status": { + "loadBalancer": {} + } + }, + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "node1", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "node1" + } + }, + "spec": { + "ports": [ + { + "name": "8080", + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "io.kompose.service": "node1" + } + }, + "status": { + "loadBalancer": {} + } + }, { "kind": "Service", "apiVersion": "v1", @@ -81,391 +133,6 @@ "loadBalancer": {} } }, - { - "kind": "Service", - "apiVersion": "v1", - "metadata": { - "name": "nginx", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "nginx" - } - }, - "spec": { - "ports": [ - { - "name": "80", - "port": 80, - "targetPort": 80 - } - ], - "selector": { - "io.kompose.service": "nginx" - } - }, - "status": { - "loadBalancer": {} - } - }, - { - "kind": "Service", - "apiVersion": "v1", - "metadata": { - "name": "node1", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "node1" - } - }, - "spec": { - "ports": [ - { - "name": "8080", - "port": 8080, - "targetPort": 8080 - } - ], - "selector": { - "io.kompose.service": "node1" - } - }, - "status": { - "loadBalancer": {} - } - }, - { - "kind": "DeploymentConfig", - "apiVersion": "v1", - "metadata": { - "name": "node2", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "node2" - } - }, - "spec": { - "strategy": { - "resources": {} - }, - "triggers": [ - { - "type": "ConfigChange" - }, - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "node2" - ], - "from": { - "kind": "ImageStreamTag", - "name": "node2:latest" - } - } - } - ], - "replicas": 1, - "test": false, - "selector": { - "io.kompose.service": "node2" - }, - "template": { - "metadata": { - "creationTimestamp": null, - "labels": { - "io.kompose.service": "node2" - } - }, - "spec": { - "containers": [ - { - "name": "node2", - "image": " ", - "ports": [ - { - "containerPort": 8080 - } - ], - "resources": {} - } - ], - "restartPolicy": "Always" - } - } - }, - "status": {} - }, - { - "kind": "ImageStream", - "apiVersion": "v1", - "metadata": { - "name": "node2", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "node2" - } - }, - "spec": {}, - "status": { - "dockerImageRepository": "" - } - }, - { - "kind": "BuildConfig", - "apiVersion": "v1", - "metadata": { - "name": "node2", - "creationTimestamp": null - }, - "spec": { - "triggers": [ - { - "type": "ConfigChange" - }, - { - "type": "ImageChange" - } - ], - "runPolicy": "Serial", - "source": { - "type": "Git", - "git": { - "uri": "https://github.com/kubernetes-incubator/kompose.git", - "ref": "HEAD" - }, - "contextDir": "script/test/fixtures/nginx-node-redis/node/" - }, - "strategy": { - "type": "Docker", - "dockerStrategy": {} - }, - "output": { - "to": { - "kind": "ImageStreamTag", - "name": "node2:latest" - } - }, - "resources": {}, - "postCommit": {}, - "nodeSelector": null - }, - "status": { - "lastVersion": 0 - } - }, - { - "kind": "DeploymentConfig", - "apiVersion": "v1", - "metadata": { - "name": "node3", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "node3" - } - }, - "spec": { - "strategy": { - "resources": {} - }, - "triggers": [ - { - "type": "ConfigChange" - }, - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "node3" - ], - "from": { - "kind": "ImageStreamTag", - "name": "node3:latest" - } - } - } - ], - "replicas": 1, - "test": false, - "selector": { - "io.kompose.service": "node3" - }, - "template": { - "metadata": { - "creationTimestamp": null, - "labels": { - "io.kompose.service": "node3" - } - }, - "spec": { - "containers": [ - { - "name": "node3", - "image": " ", - "ports": [ - { - "containerPort": 8080 - } - ], - "resources": {} - } - ], - "restartPolicy": "Always" - } - } - }, - "status": {} - }, - { - "kind": "ImageStream", - "apiVersion": "v1", - "metadata": { - "name": "node3", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "node3" - } - }, - "spec": {}, - "status": { - "dockerImageRepository": "" - } - }, - { - "kind": "BuildConfig", - "apiVersion": "v1", - "metadata": { - "name": "node3", - "creationTimestamp": null - }, - "spec": { - "triggers": [ - { - "type": "ConfigChange" - }, - { - "type": "ImageChange" - } - ], - "runPolicy": "Serial", - "source": { - "type": "Git", - "git": { - "uri": "https://github.com/kubernetes-incubator/kompose.git", - "ref": "HEAD" - }, - "contextDir": "script/test/fixtures/nginx-node-redis/node/" - }, - "strategy": { - "type": "Docker", - "dockerStrategy": {} - }, - "output": { - "to": { - "kind": "ImageStreamTag", - "name": "node3:latest" - } - }, - "resources": {}, - "postCommit": {}, - "nodeSelector": null - }, - "status": { - "lastVersion": 0 - } - }, - { - "kind": "DeploymentConfig", - "apiVersion": "v1", - "metadata": { - "name": "redis", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "redis" - } - }, - "spec": { - "strategy": { - "resources": {} - }, - "triggers": [ - { - "type": "ConfigChange" - }, - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "redis" - ], - "from": { - "kind": "ImageStreamTag", - "name": "redis:latest" - } - } - } - ], - "replicas": 1, - "test": false, - "selector": { - "io.kompose.service": "redis" - }, - "template": { - "metadata": { - "creationTimestamp": null, - "labels": { - "io.kompose.service": "redis" - } - }, - "spec": { - "containers": [ - { - "name": "redis", - "image": " ", - "ports": [ - { - "containerPort": 6379 - } - ], - "resources": {} - } - ], - "restartPolicy": "Always" - } - } - }, - "status": {} - }, - { - "kind": "ImageStream", - "apiVersion": "v1", - "metadata": { - "name": "redis", - "creationTimestamp": null, - "labels": { - "io.kompose.service": "redis" - } - }, - "spec": { - "tags": [ - { - "name": "latest", - "annotations": null, - "from": { - "kind": "DockerImage", - "name": "redis" - }, - "generation": null, - "importPolicy": {} - } - ] - }, - "status": { - "dockerImageRepository": "" - } - }, { "kind": "DeploymentConfig", "apiVersion": "v1", @@ -564,8 +231,8 @@ "source": { "type": "Git", "git": { - "uri": "https://github.com/kubernetes-incubator/kompose.git", - "ref": "HEAD" + "uri": "%URI%", + "ref": "%REF%" }, "contextDir": "script/test/fixtures/nginx-node-redis/nginx/" }, @@ -685,8 +352,8 @@ "source": { "type": "Git", "git": { - "uri": "https://github.com/kubernetes-incubator/kompose.git", - "ref": "HEAD" + "uri": "%URI%", + "ref": "%REF%" }, "contextDir": "script/test/fixtures/nginx-node-redis/node/" }, @@ -707,6 +374,339 @@ "status": { "lastVersion": 0 } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "node2", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "node2" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "node2" + ], + "from": { + "kind": "ImageStreamTag", + "name": "node2:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "node2" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "node2" + } + }, + "spec": { + "containers": [ + { + "name": "node2", + "image": " ", + "ports": [ + { + "containerPort": 8080 + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "node2", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "node2" + } + }, + "spec": {}, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "BuildConfig", + "apiVersion": "v1", + "metadata": { + "name": "node2", + "creationTimestamp": null + }, + "spec": { + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange" + } + ], + "runPolicy": "Serial", + "source": { + "type": "Git", + "git": { + "uri": "%URI%", + "ref": "%REF%" + }, + "contextDir": "script/test/fixtures/nginx-node-redis/node/" + }, + "strategy": { + "type": "Docker", + "dockerStrategy": {} + }, + "output": { + "to": { + "kind": "ImageStreamTag", + "name": "node2:latest" + } + }, + "resources": {}, + "postCommit": {}, + "nodeSelector": null + }, + "status": { + "lastVersion": 0 + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "node3", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "node3" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "node3" + ], + "from": { + "kind": "ImageStreamTag", + "name": "node3:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "node3" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "node3" + } + }, + "spec": { + "containers": [ + { + "name": "node3", + "image": " ", + "ports": [ + { + "containerPort": 8080 + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "node3", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "node3" + } + }, + "spec": {}, + "status": { + "dockerImageRepository": "" + } + }, + { + "kind": "BuildConfig", + "apiVersion": "v1", + "metadata": { + "name": "node3", + "creationTimestamp": null + }, + "spec": { + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange" + } + ], + "runPolicy": "Serial", + "source": { + "type": "Git", + "git": { + "uri": "%URI%", + "ref": "%REF%" + }, + "contextDir": "script/test/fixtures/nginx-node-redis/node/" + }, + "strategy": { + "type": "Docker", + "dockerStrategy": {} + }, + "output": { + "to": { + "kind": "ImageStreamTag", + "name": "node3:latest" + } + }, + "resources": {}, + "postCommit": {}, + "nodeSelector": null + }, + "status": { + "lastVersion": 0 + } + }, + { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "strategy": { + "resources": {} + }, + "triggers": [ + { + "type": "ConfigChange" + }, + { + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "redis" + ], + "from": { + "kind": "ImageStreamTag", + "name": "redis:latest" + } + } + } + ], + "replicas": 1, + "test": false, + "selector": { + "io.kompose.service": "redis" + }, + "template": { + "metadata": { + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "containers": [ + { + "name": "redis", + "image": " ", + "ports": [ + { + "containerPort": 6379 + } + ], + "resources": {} + } + ], + "restartPolicy": "Always" + } + } + }, + "status": {} + }, + { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "redis", + "creationTimestamp": null, + "labels": { + "io.kompose.service": "redis" + } + }, + "spec": { + "tags": [ + { + "name": "latest", + "annotations": null, + "from": { + "kind": "DockerImage", + "name": "redis" + }, + "generation": null, + "importPolicy": {} + } + ] + }, + "status": { + "dockerImageRepository": "" + } } ] }