forked from bcgov/NotifyBC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from bcgov/feature/DESCW-2337-pipeline
add github workflow, pipeline, pipelinerun and tasks
- Loading branch information
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |