Github Actions Pipeline for openshift deployment

Use Case

Write a github action job which would build an image and then publish to ghcr. Upon Successful publishing, trigger a openshift deployment

name: OpenShift Deployment

– main

runs-on: ubuntu-latest

- name: Checkout repository
  uses: actions/checkout@v2

- name: Build Docker image
  run: docker build -t my-image:latest .

- name: Log in to Docker registry
  run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u ${{ }} --password-stdin

- name: Push Docker image to GHCR
  run: docker push${{ github.repository_owner }}/my-image:latest

- name: Set up OpenShift CLI
  uses: redhat-actions/oc-login@v1
    openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
    openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}

- name: Trigger OpenShift deployment
  run: |
    oc project my-project
    oc rollout latest deployment/my-deployment

To use this workflow, you need to set up the following secrets in your GitHub repository:

  • OPENSHIFT_SERVER_URL: The URL of your OpenShift server.
  • OPENSHIFT_TOKEN: An authentication token to access your OpenShift cluster.

Make sure to replace my-image, my-project, and my-deployment with your own image, project, and deployment names.

This workflow listens for pushes to the main branch. When a push event occurs, it checks out the repository, builds a Docker image, logs in to GHCR using the provided GITHUB_TOKEN, pushes the image to GHCR, sets up the OpenShift CLI using the provided secrets, and finally triggers an OpenShift deployment by rolling out the latest changes to the specified deployment.

Ensure that your GitHub Actions runner has the necessary access permissions to push the Docker image to GHCR and trigger the OpenShift deployment.

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x