Skip to content

Commit

Permalink
Add action to deploy to OpenShift
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterGerlach committed Sep 27, 2023
1 parent 89201dd commit ef20781
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/deploy-to-openshift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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: 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"

0 comments on commit ef20781

Please sign in to comment.