diff --git a/Dockerfile b/Dockerfile index 7e5e42dc748d472565de7f1c6e8cf739fa888a3c..99923a5bc771b21fcf9ee9a17704a00a0f4898d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,7 @@ -# Use the official Python base image FROM python:3.9-slim - -# Set the working directory in the container WORKDIR /app - -# Copy the requirements file into the container at /app COPY requirements.txt /app/ - -# Install dependencies RUN pip install --no-cache-dir -r requirements.txt - -# Copy the current directory contents into the container at /app COPY . /app/ - -# Expose port 8000 to the outside world EXPOSE 8000 - -# Command to run the FastAPI application -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] +CMD uvicorn main:app --host 0.0.0.0 --port 8000 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..70ff65f9ac36d9dd21dae65f94965204bbe99938 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,89 @@ +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 + } + } +} diff --git a/Procfile b/Procfile new file mode 100644 index 0000000000000000000000000000000000000000..c2a98748b1ae4f1c6ec972476cb881a5cc888dcc --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: uvicorn main:app --reload diff --git a/k8/deployment.yaml b/k8/deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6b52a5f8a7f140bb596843ee13e8aba9f169b9da --- /dev/null +++ b/k8/deployment.yaml @@ -0,0 +1,19 @@ +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 diff --git a/k8/service.yaml b/k8/service.yaml new file mode 100644 index 0000000000000000000000000000000000000000..cf50f9a433a86ffcc33f0e30cca01d6da289bfb2 --- /dev/null +++ b/k8/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: node-app + name: python-app +spec: + ports: + - port: 8000 + targetPort: 8000 + type: LoadBalancer + selector: + app: python-app