How to use Dockerfile with different name in OCP Git source build - openshift

I am trying to create a Git source build of this Dockerfile: https://github.com/WASdev/ci.docker/blob/master/ga/latest/full/Dockerfile.ubi.ibmjava8
I have the following configuration in my BuildConfig:
source:
git:
uri: "https://github.com/WASdev/ci.docker"
ref: "master"
contextDir: "ga/latest/full"
However, the above assumes the use of the Dockerfile filename while I want to use Dockerfile.ubi.ibmjava8 as in docker build -f Dockerfile.ubi.ibmjava8 ..
How can I use Dockerfile.ubi.ibmjava8 instead of Dockerfile in OpenShift?

TL;DR: Yes. You will not be able to use a Dockerfile with a different name than Dockerfile
On Build Strategy Options on section Dockerfile Path you will find the constrains of OCP regarding the Docker Strategy:
By default, Docker builds use a Dockerfile (named Dockerfile) located
at the root of the context specified in the
BuildConfig.spec.source.contextDir field.
The dockerfilePath field allows the build to use a different path to
locate your Dockerfile, relative to the
BuildConfig.spec.source.contextDir field. It can be simply a different
file name other than the default Dockerfile (for example,
MyDockerfile), or a path to a Dockerfile in a subdirectory (for
example, dockerfiles/app1/Dockerfile).
And they also use an expample:
strategy:
dockerStrategy:
dockerfilePath: dockerfiles/app1/Dockerfile

Related

Unable to access secrets from Dockerfile in GitHub Actions

I am using the following project as a baseline to create a Docker container action.
The problem that I have is that I need to be able to access my secrets inside my Dockerfile. I tried almost all the tricks that I knew.
Retrieve the secret
RUN --mount=type=secret,id=API_ENDPOINT \
export API_ENDPOINT=$(cat /run/secrets/API_ENDPOINT)
Docker build is not happy because the --mount option requires BuildKit. I tried to set DOCKER_BUILDKIT=1, but I had zero success.
How can I pass the secrets? I created an env var at the top of my action (global), and all the steps have complete visibility of that secret.
env:
API_ENDPOINT: ${{secrets.API_ENDPOINT}}

openshift 3.11 - oc process - how to pass env variables?

I am looking to pass environment variable in my openshift oc process command.
I see option for param file, but nothing for env variable.
Question: Are params = environment variables? I mean can i set env variables using this option? I tried this but I did not get any env variable set after the deployment was done.
I am going through below document.
https://docs.openshift.com/container-platform/3.11/dev_guide/templates.html
Only way I am achieving setting up my env variables is like below
oc process -f helloworld.yaml | oc create -f -
curl http://servertofetchenvironmentvariables:5005/env/dev/helloworld | oc set env dc/helloworld -
This ends up two deployments. Any lead on resolving this and making it as one command will be helpful. I have to use template to create my application.
Question: Are params = environment variables?
No, parameters only apply to your template file. Your template file contains placeholders such as "${MY_PASSWORD}", which are then replaced when using oc process.
I mean can i set env variables using this option?
You can, but you would need to edit your template file to include all these environment variables and the relevant placeholder.
Only way I am achieving setting up my env variables is like below
That should definitely work, as you would then update the created DeploymentConfig (dc/helloworld in your case) with your new environment variables.
A good alternative could be to populate your environment variables using a ConfigMap (so having them totally separate from your Deployment) using envFrom like so:
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "env" ]
envFrom:
- configMapRef:
name: special-config
restartPolicy: Never
This would also decouple your configuration from your Deployment and you could store / change your environment variables in your ConfigMap.
Source: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables

Configure settings.xml for Openshift 3.10 S2I Maven Builds

I would like to to customize settings.xml for s2i maven builds in Openshift 3.10. While this is easily done in version 3.11 using config maps:
https://docs.openshift.com/container-platform/3.11/dev_guide/builds/build_inputs.html#using-secrets-during-build
I did not found any solution for 3.10. Is there a workaround / solution for this?
thank you!
In 3.11, you can create a ConfigMap for your settings.xml file
$ oc create configmap settings-mvn --from-file=settings.xml=<path/to/settings.xml>
And use that to override it in your build. (Source)
source:
git:
uri: https://github.com/wildfly/quickstart.git
contextDir: helloworld
configMaps:
- configMap:
name: settings-mvn
As you point out, 3.10, there is no support for ConfigMaps in BuildConfigs, however, you can create a secret with the same content
$ oc create secret generic settings-mvn --from-file=settings.xml=<path/to/settings.xml>
And use that to override it in your build. (Source)
source:
git:
uri: https://github.com/wildfly/quickstart.git
contextDir: helloworld
secrets:
- secret:
name: settings-mvn
Alternatively, you can also include the settings.xml file in your git repo in order to override the default settings.xml. Simply placing your file at source_dir/configuration/settings.xml should be sufficient. (Source)

How can I add one or more paths to Ansible search path (for files or templates)?

In my case I am mounting my Ansible code inside a Docker container under /ansible/playbook/. Under this directory you will see the roles, inventories
I would like to mount another directory that contains some RPM files.
In Ansible I have this code:
---
- name: copy ZooKeeper rpm file
copy:
src: zookeeper-3.4.13-1.x86_64.rpm
dest: /tmp
- name: install ZooKeeper rpm package
yum:
name: /tmp/zookeeper-3.4.13-1.x86_64.rpm
state: present
The problem is that ZooKeeper does not exist in any of the default search paths:
Could not find or access 'zookeeper-3.4.13-1.x86_64.rpm'
Searched in:
/ansible/playbook/roles/kafka/files/zookeeper-3.4.13-1.x86_64.rpm
/ansible/playbook/roles/kafka/zookeeper-3.4.13-1.x86_64.rpm
/ansible/playbook/roles/kafka/tasks/files/zookeeper-3.4.13-1.x86_64.rpm
/ansible/playbook/roles/kafka/tasks/zookeeper-3.4.13-1.x86_64.rpm
/ansible/playbook/files/zookeeper-3.4.13-1.x86_64.rpm
/ansible/playbook/zookeeper-3.4.13-1.x86_64.rpm
How can I add extra search paths to this list for example:
/ansible/rpms/zookeeper-3.4.13-1.x86_64.rpm//
I don't want to hardcode absolute paths (if this works) in the Ansible code. I would like to provide something like: ANSIBLE_EXTRA_SEARCH_PATH.
How can I do this?
PS: I cannot create a symlink to my RPM directory inside the already mounted /ansible/playbook because Docker will see it and a bad link (not being able to read it, because the target directory, the one containing the RPM files is not part of the Docker container file system.)
An option would be to
put the rpm in any_path
link any_path to /ansible/playbook/rpms
use src: rpms/zookeeper-3.4.13-1.x86_64.rpm
You could use a lookup with a list of paths and the first_found query:
- name: install ZooKeeper rpm package
yum:
name: "{{ item }}/zookeeper-3.4.13-1.x86_64.rpm"
state: present
loop: "{{ query('first_found', { 'paths': mypaths}) }}"
vars:
mypaths: ['/tmp', '/opt/other_location/somedir/', '/rpms']
More information at https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#selecting-files-and-templates-based-on-variables

Read JSON-file into environment variable with Docker Compose

I've dockerized a Meteor-app with Meteord, and that works fine, my problem is that I want to pass some settings to the app.
Meteord does not start the app with a settings-file as one would usually do to give settings to an app (meteor --settings file.json). This is also possible to do with an environement variable called METEOR_SETTINGS.
As I want the webapp to run with other services, I'm using Docker Compose.
I have my settings.json-file that I want to be read in as a environment variable, so something like:
environment:
- METEOR_SETTINGS=$cat(settings.json)
This doesn't work though.
How can I make Docker compose dynamically create this environment variable based on a JSON-file?
An easy way to do this is to load the JSON file in to a local env var, then use that in your yaml file.
In docker-compose.yml
environment:
METEOR_SETTINGS: ${METEOR_SETTINGS}
Load the settings file before invoking docker-compose:
❯ METEOR_SETTINGS=$(cat settings.json) docker-compose up
Not possible without some trickery, depending on the amount of tweakable variables in settings.json:
If it's a lot of settings it's fairly easy to template the docker-compose.yml with a simple shell script that replaces a token in the template with the contents of settings.json, much like in your example. You also want to wrap the docker-compose call in that case. Simplified example:
docker-compose.yml.template:
environment:
- METEOR_SETTINGS=##_METEOR_SETTINGS_##
dc.sh:
#!/bin/sh
# replace ##_METEOR_SETTINGS_## with contents of settings.json and output to docker-compose.yml
sed -e 's|##_METEOR_SETTINGS_##|'"$(cat ./settings.json)"'|' \
"./docker-compose.yml.template" > "./docker-compose.yml"
# wrap docker-compose, passing all arguments
docker-compose "$#"
Put the 2 files into your project root, then chmod +x dc.sh to make the wrapper executable and call ./dc.sh -h.
If it's only a few settings you could handle the templating inside the container when its starting. Simply replace tokens placed in a prepared settings.json with ENV values passed to docker before starting Meteor. This allows you to just use the docker-compose ENV features to configure Meteor.