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
on:
push:
branches:
– main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- 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 ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push Docker image to GHCR
run: docker push ghcr.io/${{ github.repository_owner }}/my-image:latest
- name: Set up OpenShift CLI
uses: redhat-actions/oc-login@v1
with:
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-deploymentCode language: JavaScript (javascript)
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.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals