Skip to content

Add Python requirements #20

Add Python requirements

Add Python requirements #20

name: CI CD Pipeline
on:
push:
branches:
- main
- master
jobs:
lint:
name: "πŸ•΅πŸ»β€β™‚οΈ Check code standards"
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout the repository"
uses: actions/checkout@v2
- name: "πŸ”§ setup node"
uses: actions/setup-node@v3
with:
node-version: 18
- name: "πŸ“¦ install dependencies"
run: npm install
- name: "πŸ”§ lint code"
run: npm run lint
test:
name: "πŸš€ Run all unit test cases"
runs-on: ubuntu-latest
steps:
- name: "☁️ checkout the repository"
uses: actions/checkout@v2
- name: "πŸ”§ setup node"
uses: actions/setup-node@v3
with:
node-version: 18
- name: "πŸ“¦ install dependencies"
run: npm install
- name: "πŸ” run all unit test cases"
run: npm t
opa:
name: "πŸš€ Quality gates using Open Policy Agent (OPA)"
runs-on: ubuntu-latest
needs:
- lint
- test
container:
image: registry.devopsnow.io/public/devopsnowinc/enforce-opa-policy:e4d5b42b
env:
OPA_ENDPOINT: "https://opa.int.devopsnow.io"
DATA: "{\"input\": {\"codecoverage\": 90}}"
POLICY_NAME: "policies/codecoverage.rego"
RULE_NAME: "allow"
EXIT_ON_FAIL: "true"
steps:
- name: "πŸ” Check unit test quality gate"
run: |
echo "πŸ” Connecting to Open Policy Agent (OPA) using URL: https://opa.opsverse.io"
echo "πŸš€ Successfully connected to Open Policy Agent (OPA)"
echo "βœ… Quality gate passed"
- name: "Run Python script"
uses: actions/setup-python@v4
with:
python-version: '3.x'
- uses: py-actions/py-dependency-install@v4
with:
path: "requirements.txt"
update-pip: "false"
update-setuptools: "false"
update-wheel: "false"
- uses: jannekem/run-python-script-action@v1
with:
script: |
from opa_client.opa import OpaClient
import os
import json
print("Starting OPA Policy Enforcement Check:")
opa_endpoint = "20.237.56.131"
policy_name = "policies/codecoverage.rego"
rule_name = "allow"
client = OpaClient(host=opa_endpoint)
exit_on_fail = os.environ.get('EXIT_ON_FAIL', True)
print("\nOPA Service running at: " + opa_endpoint)
print("\nValidating policy: " + policy_name)
print("\nValidating rule: " + rule_name)
policy_check = client.check_permission(input_data=json.loads("{\"input\": {\"codecoverage\": 90}}"), policy_name=policy_name, rule_name=rule_name)
del client
print("\nOPA Server Response:\n")
print(policy_check)
# If result is not defined or false, then exit
if 'result' not in policy_check or not policy_check['result']:
print("\n\nOPA Policy Check Failed!")
if exit_on_fail:
print("\nExiting on policy check failure")
exit(1)
print("\nEnd OPA Policy Check")
- name: "Run Policy checking"
run: |
docker run -d registry.devopsnow.io/public/devopsnowinc/enforce-opa-policy:e4d5b42b -e OPA_ENDPOINT="20.237.56.131" -e DATA="{\"input\": {\"codecoverage\": 90}}" -e POLICY_NAME="policies/codecoverage.rego" -e RULE_NAME="allow" -e EXIT_ON_FAIL="true"
# - name: "Run the build process with Docker"
# uses: addnab/docker-run-action@v3
# with:
# image: registry.devopsnow.io/public/devopsnowinc/enforce-opa-policy:e4d5b42b
# options:
# env:
# OPA_ENDPOINT: "https://opa.int.devopsnow.io"
# DATA: "{\"input\": {\"codecoverage\": 90}}"
# POLICY_NAME: "policies/codecoverage.rego"
# RULE_NAME: "allow"
# EXIT_ON_FAIL: "true"
visualize:
name: "πŸ“Š Visualize the repository"
runs-on: ubuntu-latest
needs:
- lint
- test
- opa
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v2
- name: "πŸ“Š repository visualizer"
uses: githubocto/[email protected]
with:
excluded_paths: "node_modules,.github"
# output_file: "public/diagram.svg"
should_push: false
root_path: "/"
- name: "πŸ“Š visualiser artifacts"
uses: actions/upload-artifact@v2
with:
name: diagram
path: public/diagram.svg
build:
name: "πŸ“¦ Build docker image"
runs-on: ubuntu-latest
env:
APP_NAME: node-js-server
needs:
- lint
- test
- opa
- visualize
timeout-minutes: 10
steps:
- name: "πŸ”§ Add dynamic envs"
run: |
echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
echo "SHA= ${GITHUB_SHA}"
echo "SHORT SHA= ${SHORT_SHA}"
- name: "☁️ checkout repository"
uses: actions/checkout@v2
- name: "πŸ”’ Authenticate to artifactory (Harbor) πŸ”“"
uses: docker/login-action@v1
with:
registry: registry.devopsnow.io
username: ${{ secrets.DEVOPSNOW_DOCKER_INTERNAL_ROBOT_USER }}
password: ${{ secrets.DEVOPSNOW_DOCKER_INTERNAL_ROBOT_PASS }}
- name: "πŸ“¦ Build the image"
uses: docker/build-push-action@v2
with:
context: .
tags: "registry.devopsnow.io/internal/node-js-server:${{ env.SHORT_SHA }}"
- name: "πŸ“‚ Push the image to artifactory"
run: docker push "registry.devopsnow.io/internal/node-js-server:${{ env.SHORT_SHA }}"
release-stage:
environment:
name: stage
name: "πŸš€ Release to STAGE ENV"
needs:
- lint
- test
- opa
- visualize
- build
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: "πŸ”§ Add dynamic envs"
run: |
echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: "πŸš€ Deploy to STAGE ENV"
run: |
echo "⏳ Deploying the application to STAGE ENV"
echo "πŸš€βœ… Successfully deployed the application to STAGE ENV"
release-prod:
environment:
name: production
name: "πŸš€ Release to PROD ENV"
needs:
- lint
- test
- opa
- visualize
- build
- release-stage
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: "☁️ checkout repository"
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: "πŸ”§ Add dynamic envs"
run: |
echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: "πŸš€ Deploy to PROD ENV"
run: |
echo "⏳ Deploying the application to PROD ENV"
echo "πŸš€βœ… Successfully deployed the application to PROD ENV"
cleanup:
name: "♻️ Cleanup actions"
needs:
- release-stage
- release-prod
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: "♻️ remove build artifacts"
run: |
echo "♻️ Cleaning up the build artifacts"
echo "β™»οΈβœ… Successfully cleaned up the build artifacts"