Skip to content

Commit

Permalink
Merge pull request #34 from bcgov/feature/DESCW-2337-pipeline
Browse files Browse the repository at this point in the history
add github workflow, pipeline, pipelinerun and tasks
  • Loading branch information
kshapka-bcgov authored Jun 19, 2024
2 parents fe64d9a + d6aa204 commit de48c4d
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/buildImageOnPush.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build API Image.
on:
push:
branches:
- v5
paths:
- 'src/**'
workflow_dispatch:
defaults:
run:
working-directory: ./
jobs:
deploy_api_on_openshift:
if: github.repository_owner == 'bcgov'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Login to OpenShift and open the correct namespace
uses: redhat-developer/[email protected]
with:
version: 'latest'
openshift_server_url: ${{ secrets.OpenShiftServerURL }}
parameters: '{"apitoken": "${{ secrets.OpenShiftToken }}", "acceptUntrustedCerts": "true"}'
cmd: |
oc project ${{ secrets.OpenShiftNamespace }}
- name: Create PipelineRun
run: |
oc create -f helm/deployments/openshift/tekton/build-pipelinerun.yaml
34 changes: 34 additions & 0 deletions helm/deployments/openshift/tekton/build-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: build-pipeline
spec:
params:
- description: The name of the secret holding the Rocket.Chat URL
name: rocketchat-url-secret
type: string
tasks:
- name: start-build
taskRef:
kind: Task
name: start-build
- name: send-to-rocketchat
params:
- name: url-secret
value: $(params.rocketchat-url-secret)
- name: options
value:
- '-X'
- POST
- '-H'
- 'Content-Type: application/json'
- '-v'
- '--data'
- >-
{"alias": "DESCW OC Alerts", "text":
"$(tasks.start-build.results.exit-status)"}
runAfter:
- start-build
taskRef:
kind: Task
name: curl
16 changes: 16 additions & 0 deletions helm/deployments/openshift/tekton/build-pipelinerun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# .github/pipelines/pipelinerun.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: build-pipelinerun-
labels:
tekton.dev/pipeline: build-pipeline
spec:
params:
- name: rocketchat-url-secret
value: rocketchat-url
pipelineRef:
name: build-pipeline
serviceAccountName: pipeline
timeouts:
pipeline: 1h0m0s
35 changes: 35 additions & 0 deletions helm/deployments/openshift/tekton/tasks/curl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: curl
labels:
app.kubernetes.io/version: '0.1'
spec:
description: This task performs curl operation to transfer data from internet.
params:
- description: Name of the secret which holds the URL to be curl'ed.
name: url-secret
type: string
- description: Options for the url command.
name: options
type: array
- default: >-
docker.io/curlimages/curl:7.72.0@sha256:bd5bbd35f89b867c1dccbc84b8be52f3f74dea20b46c5fe0db3780e040afcb6f
description: Image of curl to pull.
name: curl-image
type: string
steps:
- args:
- '$(params.options[*])'
- $(URL)
command:
- curl
env:
- name: URL
valueFrom:
secretKeyRef:
key: url
name: $(params.url-secret)
image: $(params.curl-image)
name: curl
resources: {}
27 changes: 27 additions & 0 deletions helm/deployments/openshift/tekton/tasks/start-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: start-build
spec:
results:
- description: Output of the start-build command
name: build-output
type: string
- description: Status of the build ("Build Succeeded" or "Build Failed")
name: exit-status
type: string
steps:
- image: 'quay.io/openshift/origin-cli:latest'
name: start-build
resources: {}
script: |
#!/bin/sh
output=$(oc start-build notify-bc --wait)
exit_code=$?
echo "$output" > /tekton/results/build-output
if [ "$exit_code" -eq 0 ]; then
echo -n "Build Succeeded" > /tekton/results/exit-status
else
echo -n "Build Failed" > /tekton/results/exit-status
fi
exit 0 # Continue the pipeline even if the task fails

0 comments on commit de48c4d

Please sign in to comment.