Skip to content

Commit 35ae0ea

Browse files
committed
add manifest and update the readme.
1 parent 99af279 commit 35ae0ea

File tree

4 files changed

+161
-9
lines changed

4 files changed

+161
-9
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
name: Docker
1+
name: Build Container and Push on GHCR
22

33
on:
4-
# schedule:
5-
# - cron: '28 5 * * *'
64
push:
75
branches: [ "main" ]
8-
# Publish semver tags as releases.
9-
tags: [ 'v*.*.*' ]
106
pull_request:
117
branches: [ "main" ]
128
workflow_dispatch: # Allows manual triggering of the workflow
@@ -67,6 +63,4 @@ jobs:
6763
- name: Output image digest
6864
id: output-digest
6965
run: |
70-
echo "##[group]Digest"
7166
echo "digest: ${{ steps.build-and-push.outputs.digest }} size:"
72-
echo "##[endgroup]"

README.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,102 @@
1-
# PYTHON FLASK DYNAMODB
1+
# Code2Cloud Python Flask Application
2+
3+
## Description
4+
5+
This repository contains a Python Flask application designed to demonstrate the code-to-cloud traceability feature of Prisma Cloud. The application allows users to manage customer data, showcasing CRUD (Create, Read, Update, Delete) operations, and is containerized for deployment on cloud platforms like AKS, EKS, or GKE. The pipeline utilizes GitHub Actions for CI/CD, building and pushing the Docker image to GitHub Container Registry (GHCR).
6+
7+
## Goals
8+
9+
- Demonstrate code-to-cloud traceability using Prisma Cloud.
10+
- Showcase a simple customer management system with CRUD operations.
11+
- Utilize GitHub Actions for automated CI/CD.
12+
- Deploy the application using Kubernetes manifests.
13+
14+
15+
## Features
16+
17+
- Add, edit, delete, and list customers.
18+
- Flask-based web application.
19+
- SQLite database for data storage.
20+
- CI/CD pipeline using GitHub Actions.
21+
- Containerized application deployed on Kubernetes.
22+
23+
## Prerequisites
24+
Before you begin, ensure you have the following:
25+
26+
- **System Admin Access to Prisma Cloud:** You need administrative access to Prisma Cloud to configure and monitor the security settings and ensure proper integration with your Kubernetes cluster.
27+
28+
- **Kubeadmin Access to AKS, EKS, or GKE:** Ensure you have Kubernetes admin access to your chosen cloud provider's Kubernetes service (Azure Kubernetes Service, Amazon Elastic Kubernetes Service
29+
30+
- **Prisma Cloud Defender Agent Deployed on K8s Cluster:** The Prisma Cloud Defender agent should be deployed on your Kubernetes cluster and connected to the Prisma Cloud tenant. This ensures that Prisma Cloud can monitor and protect your deployed applications.
31+
32+
## Step-by-Step Procedure
33+
34+
### Fork this Repository
35+
Click the "Fork" button in the top-right corner to create your own copy of the repository.
36+
37+
### Onboard the Forked Repository in Prisma Cloud
38+
Follow the instructions in the Prisma Cloud documentation to connect your GitHub repository:
39+
[Add GitHub Repository to Prisma Cloud](https://docs.prismacloud.io/en/classic/appsec-admin-guide/get-started/connect-your-repositories/code-repositories/add-github)
40+
41+
### Clone the repo
42+
Clone your forked repository to your local machine:
43+
```bash
44+
git clone https://github.com/<your-github-username>/code2cloud-python-flask-webserver.git
45+
```
46+
47+
### Change the Version Number in version.py
48+
Change the directory to the cloned repository:
49+
```bash
50+
cd code2cloud-python-flask-webserver
51+
```
52+
53+
Open the `version.py` file and update the version number:
54+
```python
55+
version = "0.0.10" # Update to a new version number
56+
```
57+
58+
### Push the changes to the Repository
59+
```bash
60+
git add version.py
61+
git commit -m "Update version number to 0.0.10"
62+
git push origin main
63+
```
64+
65+
### Create a PAT (Personal Access Token) Token
66+
Go to your GitHub account settings.
67+
Navigate to "Developer settings" and then "Personal access tokens."
68+
Generate a new token with write:packages scope and save it securely.
69+
70+
### Deploy the Application with Manifests Files
71+
Apply the Kubernetes manifests to create the namespace, deployment, and service:
72+
```bash
73+
kubectl apply -f manifests/deployment.yaml
74+
```
75+
76+
### Create a Secret in the K8s Cluster to Pull the Image from GHCR
77+
78+
Use the PAT token to create a Docker registry secret:
79+
```bash
80+
kubectl create secret docker-registry ghcr-io-creds \
81+
--docker-server=ghcr.io \
82+
--docker-username=<github_handle> \
83+
--docker-password=<your_pat_token> \
84+
--docker-email=<email>
85+
```
86+
87+
### Verify the Deployment
88+
Check the status of the pods to ensure they are running:
89+
```bash
90+
kubectl get pods -n code2cloud
91+
```
92+
93+
Verify the service is created and accessible:
94+
```bash
95+
kubectl get svc -n code2cloud
96+
```
97+
98+
### Access the Application
99+
Use the external IP provided by the LoadBalancer service to access the application in your browser.
100+
101+
## Conclusion
102+
By following these steps, you have successfully demonstrated the code-to-cloud traceability feature of Prisma Cloud using a Python Flask application. The application is now deployed on a Kubernetes cluster, showcasing automated CI/CD with GitHub Actions and Docker.

manifests/deployment.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: code2cloud
5+
---
6+
# Deployment manifest
7+
apiVersion: apps/v1
8+
kind: Deployment
9+
metadata:
10+
name: code2cloud-python-flask-webserver-deployment
11+
namespace: code2cloud
12+
labels:
13+
app: code2cloud-python-flask-webserver
14+
owner: smelotte
15+
spec:
16+
replicas: 1
17+
selector:
18+
matchLabels:
19+
app: code2cloud-python-flask-webserver
20+
template:
21+
metadata:
22+
labels:
23+
app: code2cloud-python-flask-webserver
24+
owner: smelotte
25+
spec:
26+
containers:
27+
- name: code2cloud-python-flask-webserver
28+
image: ghcr.io/simonpanworg/code2cloud-python-flask-webserver:v0.0.9
29+
ports:
30+
- containerPort: 5000
31+
readinessProbe:
32+
httpGet:
33+
path: /actuator/info
34+
port: 5000
35+
initialDelaySeconds: 30
36+
livenessProbe:
37+
httpGet:
38+
path: /actuator/info
39+
port: 5000
40+
initialDelaySeconds: 60
41+
imagePullSecrets:
42+
- name: ghcr-io-creds
43+
---
44+
# Service manifest
45+
apiVersion: v1
46+
kind: Service
47+
metadata:
48+
name: code2cloud-python-flask-webserver-service
49+
namespace: code2cloud
50+
spec:
51+
selector:
52+
app: code2cloud-python-flask-webserver
53+
ports:
54+
- protocol: TCP
55+
port: 80
56+
targetPort: 5000
57+
type: LoadBalancer

version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "v0.0.8"
1+
version = "v0.0.9"

0 commit comments

Comments
 (0)