Skip to content

Commit

Permalink
Merge pull request #68 from CSCI-GA-2820-FA23-001/yantao_dev
Browse files Browse the repository at this point in the history
Create pipeline files and add clone to the pipeline
  • Loading branch information
haofrank authored Dec 5, 2023
2 parents a6f6ca2 + c47c30b commit be792dc
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 1 deletion.
77 changes: 77 additions & 0 deletions .tekton/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
creationTimestamp: '2023-12-03T20:32:31Z'
generation: 2
managedFields:
- apiVersion: tekton.dev/v1
fieldsType: FieldsV1
fieldsV1:
'f:spec':
.: {}
'f:finally': {}
'f:params': {}
'f:tasks': {}
'f:workspaces': {}
manager: Mozilla
operation: Update
time: '2023-12-03T21:55:43Z'
name: cd-pipeline
# namespace: devops-products
resourceVersion: '1583706109'
uid: 6ffec68d-1efc-4ae2-9811-9815aae271fb
spec:
params:
- description: The URL to the git repo
name: GIT_REPO
type: string
- default: master
description: The reference (branch or ref)
name: GIT_REF
type: string
tasks:
- name: git-clone
params:
- name: url
value: $(params.GIT_REPO)
- name: revision
value: $(params.GIT_REF)
- name: refspec
value: ''
- name: submodules
value: 'true'
- name: depth
value: '1'
- name: sslVerify
value: 'true'
- name: crtFileName
value: ca-bundle.crt
- name: subdirectory
value: ''
- name: sparseCheckoutDirectories
value: ''
- name: deleteExisting
value: 'true'
- name: httpProxy
value: ''
- name: httpsProxy
value: ''
- name: noProxy
value: ''
- name: verbose
value: 'true'
- name: gitInitImage
value: >-
registry.redhat.io/openshift-pipelines/pipelines-git-init-rhel8@sha256:1a50511583fc02a27012d17d942e247813404104ddd282d7e26f99765174392c
- name: userHome
value: /home/git
taskRef:
kind: ClusterTask
name: git-clone
workspaces:
- name: output
workspace: pipeline-workspace
workspaces:
- name: pipeline-workspace
optional: false
finally: []
146 changes: 146 additions & 0 deletions .tekton/tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
amespace: devops-products
name: green
# namespace: devops-products
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/categories: Testing
tekton.dev/pipelines.minVersion: "0.17.0"
tekton.dev/tags: python, green
tekton.dev/displayName: "green tests"
tekton.dev/platforms: "linux/amd64"
spec:
workspaces:
- name: source
description: >-
This task can be used to perform unit tests with green. #magic___^_^___line If you define a secret with the key `database_uri` it will create an environment variable named DATABASE_URI that can be used to connect to a test database.
params:
- name: ARGS
description: The additional arguments to be used with green
type: string
default: "-vvv --processes=1 --run-coverage --minimum-coverage=95"
- name: SECRET_NAME
description: The name of the secret containing a database_uri key
type: string
default: "postgres-creds"
- name: SECRET_KEY
description: The name of the key that contains the database uri
type: string
default: "database_uri"
steps:
- name: green
image: python:3.11-slim
workingDir: $(workspaces.source.path)
env:
- name: DATABASE_URI
valueFrom:
secretKeyRef:
name: $(params.SECRET_NAME)
key: $(params.SECRET_KEY)
script: |
#!/bin/bash
set -e
echo "***** Installing dependencies *****"
python -m pip install --upgrade pip wheel
pip install -qr requirements.txt
echo "***** Running Tests *****"
green $(params.ARGS)
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
# namespace: devops-products
name: deploy-image
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/categories: Deployment
tekton.dev/pipelines.minVersion: "0.17.0"
tekton.dev/tags: openshift, deploy
tekton.dev/displayName: "deploy image"
tekton.dev/platforms: "linux/amd64"
spec:
workspaces:
- name: source
description: >-
This task will update the deployment.yaml with the latest image name and then apply that yaml file and it's service file.
params:
- name: old_image_name
description: The fully qualified name of the old image to replace
type: string
- name: image_name
description: The fully qualified name of the new image to deploy
type: string
- name: manifest_dir
description: The directory in source that contains yaml manifests
type: string
default: "k8s"
steps:
- name: deploy
image: quay.io/openshift/origin-cli:latest
workingDir: /workspace/source
command: ["/bin/bash", "-c"]
args:
- |-
#!/bin/bash
set -e
echo Applying manifests in $(inputs.params.manifest_dir) directory
echo "********************* DEPLOYMENT ***********************"
echo "Deploying $(inputs.params.image_name) ..."
sed -i 's|'"$(inputs.params.old_image_name)"'|'"$(inputs.params.image_name)"'|g' $(inputs.params.manifest_dir)/deployment.yaml
cat $(inputs.params.manifest_dir)/deployment.yaml
echo "************************************************************"
echo "OC APPLY..."
oc apply -f $(inputs.params.manifest_dir)/deployment.yaml
oc apply -f $(inputs.params.manifest_dir)/service.yaml
echo "************************************************************"
sleep 3
echo "Pods:"
oc get pods
echo ""
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
# namespace: devops-products
name: apply-manifests
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/categories: Deployment
tekton.dev/pipelines.minVersion: "0.17.0"
tekton.dev/tags: openshift, deploy
tekton.dev/displayName: "deploy"
tekton.dev/platforms: "linux/amd64"
spec:
workspaces:
- name: source
description: >-
This task will deploy all of the yaml files in the manifest folder.
params:
- name: manifest_dir
description: The directory in source that contains yaml manifests
type: string
default: "k8s"
steps:
- name: apply
image: quay.io/openshift/origin-cli:latest
workingDir: /workspace/source
command: ["/bin/bash", "-c"]
args:
- |-
echo Applying manifests in $(inputs.params.manifest_dir) directory
oc apply -f $(inputs.params.manifest_dir)
echo -----------------------------------
20 changes: 20 additions & 0 deletions .tekton/workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# apiVersion: v1
# kind: Namespace
# metadata:
# name: devops-products
# labels:
# name: products
# ---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
# namespace: devops-products
name: pipeline-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
volumeMode: Filesystem
15 changes: 14 additions & 1 deletion service/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from service.common import status # HTTP Status Codes
from service.models import Product, Category, db


# Import Flask application
from . import app

Expand Down Expand Up @@ -118,6 +117,20 @@ def create_products():
app.logger.info("Product with ID [%s] created.", product.id)
return jsonify(message), status.HTTP_201_CREATED, {"Location": location_url}

# try:
# product.deserialize(request.get_json())
# product.create()
# message = product.serialize()
# location_url = url_for("read_products", product_id=product.id, _external=True)
# app.logger.info("Product with ID [%s] created.", product.id)
# return jsonify(message), status.HTTP_201_CREATED, {"Location": location_url}
# except sqlalchemy.exc.PendingRollbackError as rollback_error:
# # Rollback the session in case of error
# db.session.rollback()
# print("rollback")
# app.logger.error("Error creating product: %s", str(rollback_error))
# return jsonify({"error": "Error creating product"}), status.HTTP_400_BAD_REQUEST


######################################################################
# ADD MULTIPLE NEW PRODUCT
Expand Down

0 comments on commit be792dc

Please sign in to comment.