Skip to content

Commit

Permalink
Merge pull request #517 from sclorg/add_ruby_persistent
Browse files Browse the repository at this point in the history
Add support for Rails App with PostgreSQL Persistent storage
  • Loading branch information
phracek authored Feb 12, 2024
2 parents 708dea5 + b5256d9 commit 0235cf8
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 22 deletions.
112 changes: 96 additions & 16 deletions examples/rails-postgresql-persistent.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,18 @@
"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\"}]"
"image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"},{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"${NAME}:latest\"},\"fieldPath\": \"spec.template.spec.initContainers[0].image\"}]"
}
},
"spec": {
"strategy": {
"type": "Recreate",
"recreateParams": {
"pre": {
"failurePolicy": "Abort",
"execNewPod": {
"command": [
"./migrate-database.sh"
],
"containerName": "${NAME}"
}
}
}
"type": "Recreate"
},
"replicas": 1,
"selector": {
"name": "${NAME}"
"matchLabels": {
"name": "${NAME}"
}
},
"template": {
"metadata": {
Expand All @@ -185,6 +176,86 @@
}
},
"spec": {
"initContainers": [
{
"name": "ruby-init-container",
"image": " ",
"command": [
"./migrate-database.sh"
],
"env": [
{
"name": "DATABASE_SERVICE_NAME",
"value": "${DATABASE_SERVICE_NAME}"
},
{
"name": "POSTGRESQL_USER",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "database-user"
}
}
},
{
"name": "POSTGRESQL_PASSWORD",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "database-password"
}
}
},
{
"name": "SECRET_KEY_BASE",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "keybase"
}
}
},
{
"name": "POSTGRESQL_DATABASE",
"value": "${DATABASE_NAME}"
},
{
"name": "POSTGRESQL_MAX_CONNECTIONS",
"value": "${POSTGRESQL_MAX_CONNECTIONS}"
},
{
"name": "POSTGRESQL_SHARED_BUFFERS",
"value": "${POSTGRESQL_SHARED_BUFFERS}"
},
{
"name": "APPLICATION_DOMAIN",
"value": "${APPLICATION_DOMAIN}"
},
{
"name": "APPLICATION_USER",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "application-user"
}
}
},
{
"name": "APPLICATION_PASSWORD",
"valueFrom": {
"secretKeyRef" : {
"name" : "${NAME}",
"key" : "application-password"
}
}
},
{
"name": "RAILS_ENV",
"value": "${RAILS_ENV}"
}
]
}
],
"containers": [
{
"name": "${NAME}",
Expand Down Expand Up @@ -339,7 +410,7 @@
"annotations": {
"description": "Defines how to deploy the database",
"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\"}]"
"image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"postgresql:${POSTGRESQL_VERSION}\"},\"fieldPath\": \"spec.template.spec.containers[0].image\"}]"
}
},
"spec": {
Expand All @@ -348,7 +419,9 @@
},
"replicas": 1,
"selector": {
"name": "${DATABASE_SERVICE_NAME}"
"matchLabels": {
"name": "${DATABASE_SERVICE_NAME}"
}
},
"template": {
"metadata": {
Expand Down Expand Up @@ -461,6 +534,13 @@
"required": true,
"value": "3.0-ubi8"
},
{
"name": "POSTGRESQL_VERSION",
"displayName": "PostgreSQL Version",
"description": "Version of PostgreSQL image to be used (10-el8 by default).",
"required": true,
"value": "12-el8"
},
{
"name": "MEMORY_LIMIT",
"displayName": "Memory Limit",
Expand Down
8 changes: 5 additions & 3 deletions test/run-openshift-remote-cluster
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ 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_ruby_s2i_rails_templates
test_ruby_s2i_rails_persistent_templates
test_ruby_s2i_local_app_templates
test_ruby_s2i_local_persistent_templates
test_latest_imagestreams
"


trap ct_os_cleanup EXIT SIGINT

ct_os_set_ocp4 || exit $OC_ERR
Expand Down
41 changes: 38 additions & 3 deletions test/test-lib-ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ function test_ruby_imagestream() {

function test_ruby_s2i_rails_app() {
ct_os_test_s2i_app "${IMAGE_NAME}" \
"https://github.com/phracek/rails-ex#master" \
"https://github.com/sclorg/rails-ex#master" \
. \
'Welcome to your Rails application'
}


function test_ruby_s2i_templates() {
function test_ruby_s2i_rails_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" \
Expand All @@ -64,7 +64,42 @@ function test_ruby_s2i_templates() {
"quay.io/sclorg/postgresql-12-c8s|postgresql:12-el8"
}

function test_ruby_s2i_local_templates() {
function test_ruby_s2i_rails_persistent_templates() {
# TODO: this was not working because the referenced example dir was added as part of this commit
if [ "${OS}" == "rhel7" ]; then
echo "Skip testing Rails Template with Persistent storage on RHEL7."
return 0
fi
ct_os_test_template_app "${IMAGE_NAME}" \
"https://raw.githubusercontent.com/sclorg/rails-ex/master/openshift/templates/rails-postgresql-persistent.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 POSTGRESQL_VERSION=12-el8 -p NAME=ruby-testing \
-p DATABASE_USER=testu \
-p DATABASE_PASSWORD=testp" \
"quay.io/sclorg/postgresql-12-c8s|postgresql:12-el8"
}


function test_ruby_s2i_local_persistent_templates() {
# TODO: this was not working because the referenced example dir was added as part of this commit
if [ "${OS}" == "rhel7" ]; then
echo "Skip testing Rails Template with Persistent storage on RHEL7."
return 0
fi
ct_os_test_template_app "${IMAGE_NAME}" \
"${THISDIR}/examples/rails-postgresql-persistent.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 POSTGRESQL_VERSION=12-el8 -p NAME=ruby-testing \
-p DATABASE_USER=testu \
-p DATABASE_PASSWORD=testp" \
"quay.io/sclorg/postgresql-12-c8s|postgresql:12-el8"
}

function test_ruby_s2i_local_app_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" \
Expand Down

0 comments on commit 0235cf8

Please sign in to comment.