Skip to content
Open

test #260

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:22.04

RUN apt-get update && apt-get install nginx -y && rm -rf /var/lib/apt/lists/*

COPY index.html /var/www/html/

COPY images/ /var/www/html/

EXPOSE 80

ENTRYPOINT ["nginx", "-g", "daemon off;"]
53 changes: 53 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
pipeline {
agent { label 'linux' }

environment {
IMAGE_NAME = "docker8098/test"
IMAGE_TAG = "v${BUILD_NUMBER}"
PROD_SERVER = "[email protected]"
}
stages{
stage('checkout') {
steps {
checkout scm
}
}
stage('testing'){
steps {
sh 'echo We are testing this code'
}
}
stage('Docker build'){
steps {
sh "docker build . -t ${IMAGE_NAME}:${IMAGE_TAG}"
}
}
stage('docker push') {
when { branch 'main'}
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh """
echo "${DOCKER_PASS}" | docker login -u "${DOCKER_USER}" --password-stdin
docker push ${IMAGE_NAME}:${IMAGE_TAG}
docker logout
"""
}
}
}
stage('Prod Deployment') {
when { branch 'main' }
steps {
sshagent(credentials: ['prod-server-ssh']) {
sh """
ssh -o StrictHostKeyChecking=no ${PROD_SERVER} "
docker pull ${IMAGE_NAME}:${IMAGE_TAG} &&
docker stop web || true &&
docker rm web || true &&
docker run -d --name web -p 80:80 ${IMAGE_NAME}:${IMAGE_TAG}
"
"""
}
}
}
}
}