0

I have the following working dockerfile,

#using python3.6 image
FROM python:3.6
ENV PYTHONUNBUFFERED 1

#Installing required packages 
RUN apt-get update
RUN apt-get install libsasl2-dev libldap2-dev libssl-dev python3-dev psmisc -y

#Installing a pip package which has django project in-built
RUN pip install <pip-package>

#Running a script-> appmanage.py, which installs a app to django project
RUN appmanage.py appconfig 

#Running the django development server.
CMD ["manage.py","runserver","0.0.0.0:8000"]

How can i design a okd/openshift template yaml/json for this? I prefer a template in which the docker image-build will be handled in the template itself, instead of building a image with docker build and using the image name with tag in template.

rakesh kotian
  • 232
  • 1
  • 5
  • 30

1 Answers1

2

To export BuldConfig as template:

  1. Create BuildConfig with Dockerfile from a repo:

    oc new-build --name python-app --strategy=docker https://somegitrepo/python-app
    
  2. Or with inline Dockerfile:

    cat Dockerfile | oc new-build --name python-app --dockerfile=-
    
  3. Export the BuildConfig as template:

    oc export bc python-app --as-template=python-app-template
    

Then you can create DeploymentConfig from the created imagestream and export dc/is too.

Oligzeev
  • 511
  • 3
  • 7
  • I tried ```oc new-build --name python-app --strategy=docker https://somegitrepo/python-app```, the build fails with error ```/bin/sh: apt-get: command not found``` – rakesh kotian Feb 11 '20 at 15:08
  • 1
    You have to check your base image (python:3.6), it doesn't have apt-get. Stabilize your Dockerfile via 'docker build' first. Then deploy it in openshift. – Oligzeev Feb 11 '20 at 17:04
  • Yes,as you suggested the using ```docker.io/python:3.6``` worked fine.So after the build config, now if i want to template a deployment config, do i need to manually write it or is there any command to generate deployment config? – rakesh kotian Feb 11 '20 at 18:46
  • 1
    "oc new-app python-app", where 'python-app' is a your build name, so at least Deployment will be created (with image change trigger so after rebuilds deployment will be rerun automatically). Furthermore, you can generate build and deployment via one command: oc new-app --name python-app --strategy=docker https://somegitrepo/python-app – Oligzeev Feb 11 '20 at 21:22
  • Thanks this helped, can you please add documentation or blog reference link with respect to okd-3.11, in the answer , so that it helps all for better understanding. – rakesh kotian Feb 12 '20 at 08:28
  • How ```oc new-app --name python-app --strategy=docker somegitrepo/python-app ``` could be achieved in openshift web console? So that cloning the repo and running dockerfile for build happens in the openshift-webconsole. – rakesh kotian Feb 12 '20 at 14:21