Giter Club home page Giter Club logo

openshift-cli's Introduction

OpenShift CLI for CI/CD

This Openshift command line tool docker image ships oc and includes gettext so you can use envsubst to substitute environment variables in your CI/CD pipeline, for example using in Jenkins or a job in GitLab CI .gitlab-ci.yml file.

Image Build

Choose the version for openshift cli based on what is available on Openshift mirror: https://mirror.openshift.com/pub/

Add the version as value for ARG OC_VERSION. Example:

docker build -t myimages/openshift-cli:4.2 --build-arg OC_VERSION=4.2 .

Examples

Why should I use envsubst? You should never put secrets into your version control, so you might want to keep them in secret variables in your CI/CD system. You can use envsubst to substituted them correctly in your templates.

A CI/CD system usually sets a bunch of variables to the build environment. Below I'll show an example of GitLab CI variables set in the build environment.

  • CI_PROJECT_NAME: my_awesome_project
  • CI_BUILD_REF_SLUG: f1234d

Your app.yaml could look similar the one below:

$ cat app.yaml
...
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    labels:
      app: ${CI_PROJECT_NAME}
    name: sample
  spec:
    replicas: 1
    selector:
      app: ${CI_PROJECT_NAME}
      deployment: ${CI_BUILD_REF_SLUG}
...

After cat app.yaml | envsubst > app.yaml you'll notice the variables have been replaced with their actual values:

$ cat app.yaml
...
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    labels:
      app: my_awesome_project
    name: sample
  spec:
    replicas: 1
    selector:
      app: my_awesome_project
      deployment: f1234d
...

GitLab CI example

Below a sample job in an .gitlab-ci.yml file, please note that OpenShift does not allow _ in project names:

deploy:
  image: widerin/openshift-cli
  stage: deploy
  script:
    - oc login "$OPENSHIFT_SERVER" --token="$OPENSHIFT_TOKEN"
    - cat app.yaml | envsubst > app.yaml
    - oc replace -f app.yaml -n ${CI_PROJECT_NAME/_/}

openshift-cli's People

Contributors

saily avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.