Skip to content

Commit

Permalink
Add testing template for RAILS application with no database
Browse files Browse the repository at this point in the history
Signed-off-by: Petr "Stone" Hracek <[email protected]>
  • Loading branch information
phracek committed Jan 19, 2024
1 parent 50dbf90 commit 1bf331e
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/rails-postgresql-persistent.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
},
{
"kind": "Deployment",
"apiVersion": "apps.openshift.io/v1",
"apiVersion": "apps/v1",
"metadata": {
"name": "${NAME}",
"annotations": {
Expand Down Expand Up @@ -332,8 +332,8 @@
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "apps.openshift.io/v1",
"kind": "Deployment",
"apiVersion": "apps/v1",
"metadata": {
"name": "${DATABASE_SERVICE_NAME}",
"annotations": {
Expand Down
4 changes: 2 additions & 2 deletions examples/rails-postgresql.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
},
{
"kind": "Deployment",
"apiVersion": "apps.openshift.io/v1",
"apiVersion": "apps/v1",
"metadata": {
"name": "${NAME}",
"annotations": {
Expand Down Expand Up @@ -316,7 +316,7 @@
},
{
"kind": "Deployment",
"apiVersion": "apps.openshift.io/v1",
"apiVersion": "apps/v1",
"metadata": {
"name": "${DATABASE_SERVICE_NAME}",
"annotations": {
Expand Down
279 changes: 279 additions & 0 deletions examples/rails.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
]
}
3 changes: 3 additions & 0 deletions test/run-openshift-remote-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -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
"

Expand Down
31 changes: 21 additions & 10 deletions test/test-lib-ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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#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/phracek/rails-ex/migrate_deployment/openshift/templates/rails-postgresql.json" \
ruby \
"Everything is OK" \
"https://raw.githubusercontent.com/sclorg/rails-ex/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 RUBY_VERSION=${VERSION} -p NAME=rails-postgresql-example" \
"-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"
}

Expand Down

0 comments on commit 1bf331e

Please sign in to comment.