feat: add Jenkinsfile for Pipeline CI/CD
This commit is contained in:
parent
54f66c56ed
commit
236afb5628
86
Jenkinsfile
vendored
Normal file
86
Jenkinsfile
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
CI_REGISTRY = '192.168.1.154:31010'
|
||||
DOCKER_IMAGE = 'docker/file-system-server'
|
||||
DOCKER_TAG = "${BUILD_NUMBER}"
|
||||
DEPLOY_DIR = '/home/xiangning/deploy/file-system-server'
|
||||
}
|
||||
|
||||
stages {
|
||||
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
echo '=== Checkout ==='
|
||||
checkout scm
|
||||
sh 'git log --oneline -5'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo '=== Build Docker Image ==='
|
||||
sh """
|
||||
echo "Registry: ${CI_REGISTRY}"
|
||||
echo "Image: ${DOCKER_IMAGE}:${DOCKER_TAG}"
|
||||
docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} .
|
||||
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('Push') {
|
||||
steps {
|
||||
echo '=== Push to Registry ==='
|
||||
sh """
|
||||
echo 'dockerxn001624.' | docker login -u docker --password-stdin ${CI_REGISTRY}
|
||||
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${CI_REGISTRY}/${DOCKER_IMAGE}:${DOCKER_TAG}
|
||||
docker tag ${DOCKER_IMAGE}:latest ${CI_REGISTRY}/${DOCKER_IMAGE}:latest
|
||||
docker push ${CI_REGISTRY}/${DOCKER_IMAGE}:${DOCKER_TAG}
|
||||
docker push ${CI_REGISTRY}/${DOCKER_IMAGE}:latest
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
echo '=== Deploy ==='
|
||||
sh """
|
||||
mkdir -p ${DEPLOY_DIR}
|
||||
cd ${DEPLOY_DIR}
|
||||
cat > docker-compose.yml << 'DCOF'
|
||||
services:
|
||||
file-system-server:
|
||||
image: ${CI_REGISTRY}/${DOCKER_IMAGE}:latest
|
||||
container_name: file-system-server
|
||||
ports:
|
||||
- "8991:8080"
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- GIN_MODE=release
|
||||
volumes:
|
||||
- ./logs:/app/logs
|
||||
DCOF
|
||||
docker compose pull
|
||||
docker compose down --remove-orphans || true
|
||||
docker compose up -d
|
||||
docker image prune -f
|
||||
docker compose ps
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
echo '=== CI/CD SUCCESS ==='
|
||||
}
|
||||
failure {
|
||||
echo '=== CI/CD FAILED ==='
|
||||
}
|
||||
always {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user