Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add action to deploy to OpenShift #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/deploy-to-openshift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy to OpenShift

on:
pull_request:
paths:
- "src/**"
- ".github/workflows/**"
- "Makefile"
- "pyproject.toml"
- "poetry.lock"
- "deployment/**"
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

env:
PROJECT_NAME: ${{ secrets.OPENSHIFT_PROJECT_NAME }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Get latest OpenShift CLI
run: |
curl -LO "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux-4.13.13.tar.gz"
tar -xzvf openshift-client-linux-4.13.13.tar.gz
sudo mv oc /usr/local/bin/oc
oc version

- name: Login to OpenShift Cluster
run: |
oc login ${{ secrets.OPENSHIFT_SERVER_URL }} --token=${{ secrets.OPENSHIFT_API_TOKEN }} --insecure-skip-tls-verify=true

- name: Change deploy script permissions
run: |
chmod +x ./deployment/deploy.sh

- name: Deploy to OpenShift
run: |
./deployment/deploy.sh
39 changes: 39 additions & 0 deletions deployment/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Check if environment variables are set
if [[ -z "$PROJECT_NAME" ]]; then
echo "PROJECT_NAME is not set. Exiting."
exit 1
fi

# Function to check command status
check_status() {
if [[ $? != 0 ]]; then
echo "Error executing command $1, exiting."
exit 1
fi
}

# Create new project
oc new-project $PROJECT_NAME
check_status "oc new-project"

# Apply ConfigMap
oc apply -f configmap.yaml
check_status "oc apply -f configmap.yaml"

# Apply Secrets
oc apply -f secrets.yaml -n $PROJECT_NAME
check_status "oc apply -f secrets.yaml"

# Apply Deployment
oc apply -f deployment.yaml -n $PROJECT_NAME
check_status "oc apply -f deployment.yaml"

# Apply Service
oc apply -f service.yaml -n $PROJECT_NAME
check_status "oc apply -f service.yaml"

# Apply Route
oc apply -f route.yaml -n $PROJECT_NAME
check_status "oc apply -f route.yaml"