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

add github workflow, pipeline, pipelinerun and tasks #34

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a helm value? and if so i suspect there is a follow up pr for the tenant repo!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is the name of the openshift secret that the curl task (see that file below) will look up and use. It is provided by the pipeline-run (in this case "rocketchat-url").

- 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
Loading