Browse Source

pushing python project

master
lenape 3 months ago
parent
commit
0d210d0524
  1. 9
      Dockerfile
  2. 31
      Jenkinsfile
  3. 35
      Jenkinsfile-push-gitea-dockerhub
  4. 1
      app.py
  5. 24
      index.html

9
Dockerfile

@ -0,0 +1,9 @@
FROM python:3.9-slim-buster
RUN apt-get update && apt-get install -y nginx
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

31
Jenkinsfile vendored

@ -0,0 +1,31 @@
pipeline {
agent any
stages {
stage('Build Docker Image') {
steps {
script {
def imageName = "python-jenkins-project:${BUILD_NUMBER}"
docker.build(imageName, '.')
env.IMAGE_NAME = imageName
}
}
}
stage('Deploy Docker Container') {
steps {
script {
sh "docker stop python-jenkins-container || true"
sh "docker rm python-jenkins-container || true"
sh "docker run -d -p 5555:80 --name python-jenkins-container ${env.IMAGE_NAME}"
}
}
}
stage('Verify Deployment') {
steps {
script {
sh "curl http://38.110.1.139:5555"
}
}
}
}
}

35
Jenkinsfile-push-gitea-dockerhub

@ -0,0 +1,35 @@
pipeline {
agent any
environment {
DOCKERHUB_REPO = 'jacqueskingram/python-jenkins-project'
GITEA_REPO = 'code.jacquesingram.online/lenape/python-jenkins-project.git'
}
stages {
stage('Build Docker Image') {
steps {
script {
def imageName = "${env.DOCKERHUB_REPO}:${BUILD_NUMBER}"
docker.build(imageName, '.')
env.IMAGE_NAME = imageName
}
}
}
stage('Push to Gitea') {
steps {
git credentialsId: 'my-gitea-credentials', url: "${env.GITEA_REPO}"
sh 'git push origin main'
}
}
stage('Push to Docker Hub') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'my-dockerhub-credentials') {
docker.image(env.IMAGE_NAME).push()
}
}
}
}
}
}

1
app.py

@ -0,0 +1 @@
print("Hello from Python in Jenkins!")

24
index.html

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello World from Lenape</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
h1 {
font-family: cursive;
font-size: 3em;
color: #333;
}
</style>
</head>
<body>
<h1>Hello World from Lenape</h1>
</body>
</html>
Loading…
Cancel
Save