Skip to content
Snippets Groups Projects
Commit 4fc29ff4 authored by Vinod Bangera's avatar Vinod Bangera
Browse files

Initial commit by containerization

parent 1d6e1f01
Branches devops
No related tags found
No related merge requests found
# Use the official Python base image
FROM python:3.9-slim FROM python:3.9-slim
# Set the working directory in the container
WORKDIR /app WORKDIR /app
# Copy the requirements file into the container at /app
COPY requirements.txt /app/ COPY requirements.txt /app/
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
# Copy the current directory contents into the container at /app
COPY . /app/ COPY . /app/
# Expose port 8000 to the outside world
EXPOSE 8000 EXPOSE 8000
CMD uvicorn main:app --host 0.0.0.0 --port 8000
# Command to run the FastAPI application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
pipeline {
agent any
// tools {
// nodejs 'NodeJS'
// }
environment {
PROJECT_ID = "tech-rnd-project"
CLUSTER_NAME = "python-cluster"
LOCATION = "us-central1-a"
CREDENTIALS_ID = "335fefa0-0089-4fe2-994c-fd3bd9e2ab2b"
}
stages {
stage('Scm Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
echo 'building the software'
// sh 'npm install --force'
}
}
stage('Test') {
steps {
//add steps here
echo 'testing'
}
}
stage('Build Docker Image') {
steps {
script {
sh 'whoami'
sh 'sudo chmod 777 /var/run/docker.sock'
sh "docker build -t python-postgress ."
}
}
}
// stage('Image Scan') {
// steps {
// //add steps here
// echo 'image scanning'
// sh 'trivy image --no-progress --exit-code 1 --severity CRITICAL python-postgress'
// }
// }
stage('Push Docker Image') {
steps {
script {
echo 'Push Docker Image'
sh "docker tag python-postgress asia-south1-docker.pkg.dev/tech-rnd-project/container-python/python"
sh 'gcloud auth configure-docker asia-south1-docker.pkg.dev'
sh 'docker push asia-south1-docker.pkg.dev/tech-rnd-project/container-python/python'
// sh 'curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl'
// sh 'chmod +x kubectl'
// sh "sudo mv kubectl \$(which kubectl)"
}
}
}
stage('Deploy to K8s') {
steps {
echo 'Deployment started ...'
sh 'ls -ltr'
sh 'pwd'
echo 'Start deployment of deployment.yaml'
step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'k8', credentialsId: env.CREDENTIALS_ID, verifyDeployments: true])
echo 'Deployment Finished ...'
sh '''
'''
}
}
}
post {
always {
emailext to: 'vinod.bangera@niveussolutions.com',
subject: "jenkins build:${currentBuild.currentResult}: ${env.JOB_NAME}",
body: "${currentBuild.currentResult}: Job ${env.JOB_NAME}\nMore Info can be found in the attached log",
attachLog: true
}
}
}
web: uvicorn main:app --reload
apiVersion: apps/v1
kind: Deployment
metadata:
name: python-app
spec:
replicas: 1
selector:
matchLabels:
app: python-app
template:
metadata:
labels:
app: python-app
spec:
containers:
- name: python-app
image: asia-south1-docker.pkg.dev/tech-rnd-project/container-python/python
ports:
- containerPort: 8000
apiVersion: v1
kind: Service
metadata:
name: node-app
name: python-app
spec:
ports:
- port: 8000
targetPort: 8000
type: LoadBalancer
selector:
app: python-app
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment