Openshift application lifecycle events - application creation event? - openshift

I'm trying to hook into an application created event in OpenShift - if such an event exists.
The reason being, I would like to have a command run (ideally in a new pod), for creating a database schema. It doesnt make sense to have this in the application image, as I only need this run once - when the application is created.
I have looked into pod lifecycle hooks (https://docs.openshift.com/enterprise/3.1/dev_guide/deployments.html#pod-based-lifecycle-hook) however these events happen everytime there is a new deployment. So this also is too often for my use case.
Is there a way to have an image run just once when an Openshift application is created?

You're on the right track in the comments here. In the OpenShift v2 days the same scenario existed with lifecycle hooks.
For our WordPress Quickstart in OpenShift v2, for instance, we would check to see if the database was created yet on every new deployment. If not, we initialized an empty database with the same name as the app (in this case letting WordPress create the schema afterwards, but it's the same idea needed here): OpenShift v2 WordPress deploy action hook
In OpenShift v3, there are a few ways to implement a similar lifecycle hook, but the common pattern we're using in our templates now is to leverage the ability to execute a new pod to run database setup steps just prior to the deployment phase: OpenShift v3 CakePHP pre deploy lifecycle hook
Following this pattern, you would add your code to generate your database schema in a file like the v3 CakePHP migrate-database.sh in your source repo and execute the script with a pre deploy lifecycle hook (via execNewPod), checking first to see if the database/schema (select * from someknowntable limit 1) exists before loading the schema.

Related

OpenShift post deployment initialisation script

I have an OpenShift 3.11 project using PHP and I would like to execute a script to configure the pod after it is deployed. The first thing the script will do is to create a symbolic link from the pod to the PV named /storage so that I can display the reports in the reports directory on the PV in a browser. I would also like to copy an image from my image directory - the image will indicate whether the application is running on the development system, the test system or production. The name of the appropriate image will be held in a config map which is tailored to each system.
I did consider OpenShift's Pod Based Lifecycle Hooks but they appear to run in a separate pod to the application that is deployed so the symbolic link will not be created in the application pod. The OpenShift documentation mentions you can change your image's ENTRYPOINT. The example shows running a Java application however I still require the PHP and Apache image to be deployed in addition to creating the symbolic link and copying the image.
Is it possible to perform post deployment configuration of a pod in OpenShift and if so how is it done?

GitHub Actions - how to connect to an external MySql database

I'm building an application in Python and using GitHub Actions to automate the testing 'on push'. However, I now want to connect my app to an existing MySql database.
From searching the Marketplace, Google and YouTube, I can see the following options:
use the MySql supplied with the GitHub Actions' Ubuntu virtual environment
setup a new MySql dB inside the GitHub Actions VM.
Setup MySql inside a Docker container and connect to it from another Docker container containing my app.
What I can't see is how to connect out of the GitHub Actions VM to an existing database on my network. Is it possible and should I expect to see a pre-built action to do this in the Marketplace.
Sorry for such an obtuse question: old, out-of-date programmer new to both CI/CD and containerisation. Thank you.

How to auto restart OpenShift deployment on a weekly/daily basis?

I'm having a flask app that fetches data from external source only at application startup.
I need to refresh app data, and the easiest way (without changing app logic) would be to daily restart deployment (scale pod to zero and up again).
Is this possible to achieve this in deployment configuration (DeploymentConfig)?
OpenShift version is v3.11.104.
Seems to be solvable with running an app using OpenShift Cronjob, configuring the Cronjob to be run every day, and setting ConcurrencyPolicy param to Replace.

Openshift Project hide Elasticsearch Route

I am new to OpenShift so apologies in advance if this question is not very clear.
I have a project starting in Openshift and will use the Elasticsearch provided docker image as a data store.
ElasiticSearch is bound only to local host by default when installed, and if I was running app on a server I would keep this configuration so as not to expose ElasticSearch interface as connectivity only required by the application, no need to expose outside of project.
If I make a route for Elasticsearch without changing it's default config, it is accessible to other Pods in project but also outside of the project, like the main application. Is it possible to make a route that is internal to the project only so that Elasticsearch interface is not accessible outside of the project or by other means ? Or a way to have a common local host address between pods/applications ?
I tried to group the services but still not available.
Any support to put me in right direction really appreciated.

Rebuild openshift cartridge without deleting app

I have production golang app running on openshift using this cartridge (https://github.com/smarterclayton/openshift-go-cart) with a mysql database. The cartridge has had some updates which I would like to pull into my app.
Is it possible to reploy the base cartridge into my gears without deleting the whole application?
If your repository contains .openshift/markers/hot_deploy, when you perform a git push OpenShift will not rebuild the application and perform a hot deployment instead.
See the Hot Deploying Applications section of the user guide, as well as this blog post (which somehow contains more specific details about where the marker file goes)