From 9f18df93fa3b7f89e1730dd90625319a2e0f8e6e Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Fri, 19 Jan 2024 12:38:43 +0100 Subject: [PATCH] Add testing template for RAILS application with no database Signed-off-by: Petr "Stone" Hracek --- examples/rails-postgresql-persistent.json | 6 +- examples/rails-postgresql.json | 4 +- examples/rails.json | 279 ++++++++++++++++++++++ test/run-openshift-remote-cluster | 3 + test/test-lib-ruby.sh | 31 ++- 5 files changed, 308 insertions(+), 15 deletions(-) create mode 100644 examples/rails.json diff --git a/examples/rails-postgresql-persistent.json b/examples/rails-postgresql-persistent.json index 770a4669..74a5d26b 100644 --- a/examples/rails-postgresql-persistent.json +++ b/examples/rails-postgresql-persistent.json @@ -149,7 +149,7 @@ }, { "kind": "Deployment", - "apiVersion": "apps.openshift.io/v1", + "apiVersion": "apps/v1", "metadata": { "name": "${NAME}", "annotations": { @@ -332,8 +332,8 @@ } }, { - "kind": "DeploymentConfig", - "apiVersion": "apps.openshift.io/v1", + "kind": "Deployment", + "apiVersion": "apps/v1", "metadata": { "name": "${DATABASE_SERVICE_NAME}", "annotations": { diff --git a/examples/rails-postgresql.json b/examples/rails-postgresql.json index 0bf76953..b4822609 100644 --- a/examples/rails-postgresql.json +++ b/examples/rails-postgresql.json @@ -149,7 +149,7 @@ }, { "kind": "Deployment", - "apiVersion": "apps.openshift.io/v1", + "apiVersion": "apps/v1", "metadata": { "name": "${NAME}", "annotations": { @@ -316,7 +316,7 @@ }, { "kind": "Deployment", - "apiVersion": "apps.openshift.io/v1", + "apiVersion": "apps/v1", "metadata": { "name": "${DATABASE_SERVICE_NAME}", "annotations": { 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 f14f3e1f..06933010 100755 --- a/test/run-openshift-remote-cluster +++ b/test/run-openshift-remote-cluster @@ -13,10 +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 " diff --git a/test/test-lib-ruby.sh b/test/test-lib-ruby.sh index 3e8d5b6c..94b871a5 100644 --- a/test/test-lib-ruby.sh +++ b/test/test-lib-ruby.sh @@ -45,22 +45,33 @@ function test_ruby_imagestream() { ".*" } -#function test_ruby_s2i_rails_app() { -# ct_os_test_s2i_app "${IMAGE_NAME}" \ -# "https://github.com/phracek/rails-ex#bump_template_to_30" \ -# . \ -# 'Welcome to your Dancer application on OpenShift' -#} +function test_ruby_s2i_rails_app() { + ct_os_test_s2i_app "${IMAGE_NAME}" \ + "https://github.com/phracek/rails-ex#migrate_deployment" \ + . \ + '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/phracek/rails-ex/migrate_deployment/openshift/templates/rails-postgresql.json" \ - ruby \ - "Everything is OK" \ + "https://raw.githubusercontent.com/phracek/rails-ex/migrate_deployment/openshift/templates/rails.json" \ + "ruby" \ + "Welcome to your Rails application" \ + 8080 http 200 \ + "-p SOURCE_REPOSITORY_REF=migrate_deployment -p SOURCE_REPOSITORY_URL=https://github.com/phracek/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 RUBY_VERSION=${VERSION} -p NAME=rails-postgresql-example" \ + "-p SOURCE_REPOSITORY_REF=migrate_deployment -p SOURCE_REPOSITORY_URL=https://github.com/phracek/rails-ex -p RUBY_VERSION=${VERSION} -p NAME=ruby-testing" \ "quay.io/sclorg/postgresql-12-c8s|postgresql:12-el8" }