diff --git a/examples/rails-postgresql-persistent.json b/examples/rails-postgresql-persistent.json index a39f8464..74a5d26b 100644 --- a/examples/rails-postgresql-persistent.json +++ b/examples/rails-postgresql-persistent.json @@ -112,7 +112,7 @@ "from": { "kind": "ImageStreamTag", "namespace": "${NAMESPACE}", - "name": "ruby:2.5" + "name": "ruby:${RUBY_VERSION}" }, "env": [ { @@ -148,13 +148,14 @@ } }, { - "kind": "DeploymentConfig", - "apiVersion": "apps.openshift.io/v1", + "kind": "Deployment", + "apiVersion": "apps/v1", "metadata": { "name": "${NAME}", "annotations": { "description": "Defines how to deploy the application server", - "template.alpha.openshift.io/wait-for-ready": "true" + "template.alpha.openshift.io/wait-for-ready": "true", + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" } }, "spec": { @@ -172,24 +173,6 @@ } } }, - "triggers": [ - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "${NAME}" - ], - "from": { - "kind": "ImageStreamTag", - "name": "${NAME}:latest" - } - } - }, - { - "type": "ConfigChange" - } - ], "replicas": 1, "selector": { "name": "${NAME}" @@ -349,38 +332,20 @@ } }, { - "kind": "DeploymentConfig", - "apiVersion": "apps.openshift.io/v1", + "kind": "Deployment", + "apiVersion": "apps/v1", "metadata": { "name": "${DATABASE_SERVICE_NAME}", "annotations": { "description": "Defines how to deploy the database", - "template.alpha.openshift.io/wait-for-ready": "true" + "template.alpha.openshift.io/wait-for-ready": "true", + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:12-el8\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" } }, "spec": { "strategy": { "type": "Recreate" }, - "triggers": [ - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "postgresql" - ], - "from": { - "kind": "ImageStreamTag", - "namespace": "${NAMESPACE}", - "name": "postgresql:10" - } - } - }, - { - "type": "ConfigChange" - } - ], "replicas": 1, "selector": { "name": "${DATABASE_SERVICE_NAME}" @@ -489,6 +454,13 @@ "description": "The OpenShift Namespace where the ImageStream resides.", "value": "openshift" }, + { + "name": "RUBY_VERSION", + "displayName": "Ruby Version", + "description": "Version of Ruby image to be used (3.0-ubi8 by default).", + "required": true, + "value": "3.0-ubi8" + }, { "name": "MEMORY_LIMIT", "displayName": "Memory Limit", diff --git a/examples/rails-postgresql.json b/examples/rails-postgresql.json index ff374dce..b4822609 100644 --- a/examples/rails-postgresql.json +++ b/examples/rails-postgresql.json @@ -112,7 +112,7 @@ "from": { "kind": "ImageStreamTag", "namespace": "${NAMESPACE}", - "name": "ruby:2.5" + "name": "ruby:${RUBY_VERSION}" }, "env": [ { @@ -148,13 +148,14 @@ } }, { - "kind": "DeploymentConfig", - "apiVersion": "apps.openshift.io/v1", + "kind": "Deployment", + "apiVersion": "apps/v1", "metadata": { "name": "${NAME}", "annotations": { "description": "Defines how to deploy the application server", - "template.alpha.openshift.io/wait-for-ready": "true" + "template.alpha.openshift.io/wait-for-ready": "true", + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" } }, "spec": { @@ -172,24 +173,6 @@ } } }, - "triggers": [ - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "${NAME}" - ], - "from": { - "kind": "ImageStreamTag", - "name": "${NAME}:latest" - } - } - }, - { - "type": "ConfigChange" - } - ], "replicas": 1, "selector": { "name": "${NAME}" @@ -332,38 +315,20 @@ } }, { - "kind": "DeploymentConfig", - "apiVersion": "apps.openshift.io/v1", + "kind": "Deployment", + "apiVersion": "apps/v1", "metadata": { "name": "${DATABASE_SERVICE_NAME}", "annotations": { "description": "Defines how to deploy the database", - "template.alpha.openshift.io/wait-for-ready": "true" + "template.alpha.openshift.io/wait-for-ready": "true", + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:12-el8\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" } }, "spec": { "strategy": { "type": "Recreate" }, - "triggers": [ - { - "type": "ImageChange", - "imageChangeParams": { - "automatic": true, - "containerNames": [ - "postgresql" - ], - "from": { - "kind": "ImageStreamTag", - "namespace": "${NAMESPACE}", - "name": "postgresql:10" - } - } - }, - { - "type": "ConfigChange" - } - ], "replicas": 1, "selector": { "name": "${DATABASE_SERVICE_NAME}" @@ -470,6 +435,13 @@ "description": "The OpenShift Namespace where the ImageStream resides.", "value": "openshift" }, + { + "name": "RUBY_VERSION", + "displayName": "Ruby Version", + "description": "Version of Ruby image to be used (3.0-ubi8 by default).", + "required": true, + "value": "3.0-ubi8" + }, { "name": "MEMORY_LIMIT", "displayName": "Memory Limit", diff --git a/examples/rails.json b/examples/rails.json new file mode 100644 index 00000000..a29a4399 --- /dev/null +++ b/examples/rails.json @@ -0,0 +1,279 @@ +{ + "kind": "Template", + "apiVersion": "template.openshift.io/v1", + "metadata": { + "name": "rails-example", + "annotations": { + "openshift.io/display-name": "Rails", + "description": "An example Rails application with no database. For more information about using this template, including OpenShift considerations, see https://github.com/sclorg/rails-ex/blob/master/README.md.", + "tags": "quickstart,ruby,rails", + "iconClass": "icon-ruby", + "openshift.io/long-description": "This template defines resources needed to develop a Rails application, including a build configuration, application deployment configuration, and database deployment configuration.", + "openshift.io/provider-display-name": "Red Hat, Inc.", + "openshift.io/documentation-url": "https://github.com/sclorg/rails-ex", + "openshift.io/support-url": "https://access.redhat.com", + "template.openshift.io/bindable": "false" + } + }, + "message": "The following service(s) have been created in your project: ${NAME}.\n\nFor more information about using this template, including OpenShift considerations, see https://github.com/sclorg/dancer-ex/blob/master/README.md.", + "labels": { + "template": "rails-example", + "app": "rails-example" + }, + "objects": [ + { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "${NAME}", + "annotations": { + "description": "Exposes and load balances the application pods" + } + }, + "spec": { + "ports": [ + { + "name": "web", + "port": 8080, + "targetPort": 8080 + } + ], + "selector": { + "name": "${NAME}" + } + } + }, + { + "kind": "Route", + "apiVersion": "route.openshift.io/v1", + "metadata": { + "name": "${NAME}" + }, + "spec": { + "host": "${APPLICATION_DOMAIN}", + "to": { + "kind": "Service", + "name": "${NAME}" + } + } + }, + { + "kind": "ImageStream", + "apiVersion": "image.openshift.io/v1", + "metadata": { + "name": "${NAME}", + "annotations": { + "description": "Keeps track of changes in the application image" + } + } + }, + { + "kind": "BuildConfig", + "apiVersion": "build.openshift.io/v1", + "metadata": { + "name": "${NAME}", + "annotations": { + "description": "Defines how to build the application", + "template.alpha.openshift.io/wait-for-ready": "true" + } + }, + "spec": { + "source": { + "type": "Git", + "git": { + "uri": "${SOURCE_REPOSITORY_URL}", + "ref": "${SOURCE_REPOSITORY_REF}" + }, + "contextDir": "${CONTEXT_DIR}" + }, + "strategy": { + "type": "Source", + "sourceStrategy": { + "from": { + "kind": "ImageStreamTag", + "namespace": "${NAMESPACE}", + "name": "ruby:${RUBY_VERSION}" + }, + "env": [ + { + "name": "RUBYGEM_MIRROR", + "value": "${RUBYGEM_MIRROR}" + } + ] + } + }, + "output": { + "to": { + "kind": "ImageStreamTag", + "name": "${NAME}:latest" + } + }, + "triggers": [ + { + "type": "ImageChange" + }, + { + "type": "ConfigChange" + }, + { + "type": "GitHub", + "github": { + "secret": "${GITHUB_WEBHOOK_SECRET}" + } + } + ] + } + }, + { + "kind": "Deployment", + "apiVersion": "apps/v1", + "metadata": { + "name": "${NAME}", + "annotations": { + "description": "Defines how to deploy the application server", + "template.alpha.openshift.io/wait-for-ready": "true", + "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]" + } + }, + "spec": { + "strategy": { + "type": "RollingUpdate" + }, + "replicas": 1, + "selector": { + "matchLabels": { + "name": "${NAME}" + } + }, + "template": { + "metadata": { + "name": "${NAME}", + "labels": { + "name": "${NAME}" + } + }, + "spec": { + "containers": [ + { + "name": "rails-example", + "image": " ", + "ports": [ + { + "containerPort": 8080 + } + ], + "readinessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 3, + "httpGet": { + "path": "/", + "port": 8080 + } + }, + "livenessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 30, + "httpGet": { + "path": "/", + "port": 8080 + } + }, + "env": [ + { + "name": "RAILS_ENV", + "value": "${RAILS_ENV}" + } + ], + "resources": { + "limits": { + "memory": "${MEMORY_LIMIT}" + } + } + } + ] + } + } + } + } + ], + "parameters": [ + { + "name": "NAME", + "displayName": "Name", + "description": "The name assigned to all of the frontend objects defined in this template.", + "required": true, + "value": "rails-example" + }, + { + "name": "NAMESPACE", + "displayName": "Namespace", + "description": "The OpenShift Namespace where the ImageStream resides.", + "required": true, + "value": "openshift" + }, + { + "name": "RUBY_VERSION", + "displayName": "Ruby Version", + "description": "Version of Ruby image to be used (3.0-ubi8 by default).", + "required": true, + "value": "3.0-ubi8" + }, + { + "name": "MEMORY_LIMIT", + "displayName": "Memory Limit", + "description": "Maximum amount of memory the container can use.", + "required": true, + "value": "512Mi" + }, + { + "name": "SOURCE_REPOSITORY_URL", + "displayName": "Git Repository URL", + "required": true, + "description": "The URL of the repository with your application source code.", + "value": "https://github.com/sclorg/rails-ex.git" + }, + { + "name": "SOURCE_REPOSITORY_REF", + "displayName": "Git Reference", + "description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch." + }, + { + "name": "CONTEXT_DIR", + "displayName": "Context Directory", + "description": "Set this to the relative path to your project if it is not in the root of your repository." + }, + { + "name": "APPLICATION_DOMAIN", + "displayName": "Application Hostname", + "description": "The exposed hostname that will route to the Rails service, if left blank a value will be defaulted.", + "value": "" + }, + { + "name": "GITHUB_WEBHOOK_SECRET", + "displayName": "GitHub Webhook Secret", + "description": "Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.", + "generate": "expression", + "from": "[a-zA-Z0-9]{40}" + }, + { + "name": "SECRET_KEY_BASE", + "displayName": "Secret Key", + "description": "Your secret key for verifying the integrity of signed cookies.", + "generate": "expression", + "from": "[a-z0-9]{127}" + }, + { + "name": "RAILS_ENV", + "displayName": "Rails Environment", + "required": true, + "description": "Environment under which the sample application will run. Could be set to production, development or test.", + "value": "production" + }, + { + "name": "RUBYGEM_MIRROR", + "displayName": "Custom RubyGems Mirror URL", + "description": "The custom RubyGems mirror URL", + "value": "" + } + ] +} diff --git a/test/run-openshift-remote-cluster b/test/run-openshift-remote-cluster index 5c7e1387..06933010 100755 --- a/test/run-openshift-remote-cluster +++ b/test/run-openshift-remote-cluster @@ -13,9 +13,13 @@ THISDIR=$(dirname ${BASH_SOURCE[0]}) source "${THISDIR}/test-lib-ruby.sh" source "${THISDIR}/test-lib-remote-openshift.sh" + TEST_LIST="\ test_ruby_integration test_ruby_imagestream +test_ruby_s2i_rails_app +test_ruby_s2i_templates +test_ruby_s2i_local_templates test_latest_imagestreams " @@ -29,6 +33,8 @@ ct_os_check_login || exit $OC_ERR ct_os_tag_image_for_cvp "ruby" +ct_pull_or_import_postgresql || exit $OC_ERR + set -u # For testing on OpenShift 4 we use internal registry diff --git a/test/test-lib-ruby.sh b/test/test-lib-ruby.sh index 4ade627b..d7c4c0f7 100644 --- a/test/test-lib-ruby.sh +++ b/test/test-lib-ruby.sh @@ -11,6 +11,24 @@ THISDIR=$(dirname ${BASH_SOURCE[0]}) source "${THISDIR}/test-lib.sh" source "${THISDIR}/test-lib-openshift.sh" +function ct_pull_or_import_postgresql() { + postgresql_image="quay.io/sclorg/postgresql-12-c8s" + image_short="postgresql:12" + image_tag="${image_short}" + # Variable CVP is set by CVP pipeline + if [ "${CVP:-0}" -eq "0" ]; then + # In case of container or OpenShift 4 tests + # Pull image before going through tests + # Exit in case of failure, because postgresql container is mandatory + ct_pull_image "${postgresql_image}" "true" + else + # Import postgresql-10-centos7 image before running tests on CVP + oc import-image "${image_short}:latest" --from="${postgresql_image}:latest" --insecure=true --confirm + # Tag postgresql image to "postgresql:10" which is expected by test suite + oc tag "${image_short}:latest" "${image_tag}" + fi +} + function test_ruby_integration() { ct_os_test_s2i_app "${IMAGE_NAME}" \ "https://github.com/sclorg/s2i-ruby-container.git" \ @@ -27,6 +45,35 @@ function test_ruby_imagestream() { ".*" } +function test_ruby_s2i_rails_app() { + ct_os_test_s2i_app "${IMAGE_NAME}" \ + "https://github.com/phracek/rails-ex#master" \ + . \ + 'Welcome to your Rails application' +} + + +function test_ruby_s2i_templates() { + # TODO: this was not working because the referenced example dir was added as part of this commit + ct_os_test_template_app "${IMAGE_NAME}" \ + "https://raw.githubusercontent.com/sclorg/rails-ex/master/openshift/templates/rails.json" \ + "ruby" \ + "Welcome to your Rails application" \ + 8080 http 200 \ + "-p SOURCE_REPOSITORY_REF=master -p SOURCE_REPOSITORY_URL=https://github.com/sclorg/rails-ex -p RUBY_VERSION=${VERSION} -p NAME=ruby-testing" \ + "quay.io/sclorg/postgresql-12-c8s|postgresql:12-el8" +} + +function test_ruby_s2i_local_templates() { + # TODO: this was not working because the referenced example dir was added as part of this commit + ct_os_test_template_app "${IMAGE_NAME}" \ + "${THISDIR}/examples/rails.json" \ + "ruby" \ + "Welcome to your Rails application" \ + 8080 http 200 \ + "-p SOURCE_REPOSITORY_REF=master -p SOURCE_REPOSITORY_URL=https://github.com/sclorg/rails-ex -p RUBY_VERSION=${VERSION} -p NAME=ruby-testing" \ + "quay.io/sclorg/postgresql-12-c8s|postgresql:12-el8" +} function test_latest_imagestreams() { local result=1