增加流水线配置
This commit is contained in:
8
.dockerignore
Normal file
8
.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
Dockerfile
|
||||||
|
Jenkins.txt
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM node:14-alpine AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install --registry=https://registry.npmmirror.com
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM nginx:stable-alpine
|
||||||
|
COPY --from=build /app/dist /usr/share/nginx/html
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
156
Jenkins.txt
Normal file
156
Jenkins.txt
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image "cicd/ubuntu:22.04-docker-py312-jdk8-nodejs20-mvn389"
|
||||||
|
args '-v /var/run/docker.sock:/var/run/docker.sock -v /home/jenkins:/home/jenkins -v /etc/docker:/etc/docker'
|
||||||
|
registryUrl 'https://39.170.26.156:8443'
|
||||||
|
registryCredentialsId '3a4a4463-784d-4e91-9457-9dfd64722ecb'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
GIT_URL = 'https://wdxz-gitea.best-envision.com/qiaoxinjiu/effekt-interface-frontend.git'
|
||||||
|
GIT_BRANCH = 'master'
|
||||||
|
|
||||||
|
REGISTRY = '39.170.26.156:8443'
|
||||||
|
HARBOR_PROJECT = 'effekt'
|
||||||
|
IMAGE_REPO = 'effekt-interface-frontend'
|
||||||
|
IMAGE_NAME = "${REGISTRY}/${HARBOR_PROJECT}/${IMAGE_REPO}"
|
||||||
|
|
||||||
|
DEPLOY_HOST = '39.170.26.156'
|
||||||
|
DEPLOY_PORT = '8022'
|
||||||
|
CONTAINER_NAME = 'effekt-interface-frontend'
|
||||||
|
HOST_PORT = '8080'
|
||||||
|
CONTAINER_PORT = '80'
|
||||||
|
}
|
||||||
|
|
||||||
|
options {
|
||||||
|
timestamps()
|
||||||
|
disableConcurrentBuilds()
|
||||||
|
buildDiscarder(logRotator(numToKeepStr: '20'))
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Checkout Code') {
|
||||||
|
steps {
|
||||||
|
git branch: "${GIT_BRANCH}",
|
||||||
|
credentialsId: 'git-effekt-frontend',
|
||||||
|
url: "${GIT_URL}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Check Environment') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
echo "=== whoami ==="
|
||||||
|
whoami
|
||||||
|
echo "=== Check Docker ==="
|
||||||
|
docker --version
|
||||||
|
echo "=== Check Node ==="
|
||||||
|
node -v
|
||||||
|
npm -v
|
||||||
|
echo "=== Workspace ==="
|
||||||
|
pwd
|
||||||
|
ls -la
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Frontend') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Docker Image') {
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
docker build \
|
||||||
|
-t ${IMAGE_NAME}:${BUILD_NUMBER} \
|
||||||
|
-t ${IMAGE_NAME}:latest \
|
||||||
|
.
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Push Image To Harbor') {
|
||||||
|
steps {
|
||||||
|
withCredentials([
|
||||||
|
usernamePassword(
|
||||||
|
credentialsId: 'harbor-effekt',
|
||||||
|
usernameVariable: 'HARBOR_USER',
|
||||||
|
passwordVariable: 'HARBOR_PASS'
|
||||||
|
)
|
||||||
|
]) {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
echo "$HARBOR_PASS" | docker login ${REGISTRY} -u "$HARBOR_USER" --password-stdin
|
||||||
|
docker push ${IMAGE_NAME}:${BUILD_NUMBER}
|
||||||
|
docker push ${IMAGE_NAME}:latest
|
||||||
|
docker logout ${REGISTRY}
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Deploy To Server') {
|
||||||
|
steps {
|
||||||
|
withCredentials([
|
||||||
|
usernamePassword(
|
||||||
|
credentialsId: 'docker-host-ssh',
|
||||||
|
usernameVariable: 'DEPLOY_USER',
|
||||||
|
passwordVariable: 'DEPLOY_PASS'
|
||||||
|
),
|
||||||
|
usernamePassword(
|
||||||
|
credentialsId: 'harbor-effekt',
|
||||||
|
usernameVariable: 'HARBOR_USER',
|
||||||
|
passwordVariable: 'HARBOR_PASS'
|
||||||
|
)
|
||||||
|
]) {
|
||||||
|
sh '''
|
||||||
|
set -e
|
||||||
|
|
||||||
|
sshpass -p "$DEPLOY_PASS" ssh \
|
||||||
|
-o StrictHostKeyChecking=no \
|
||||||
|
-p "$DEPLOY_PORT" \
|
||||||
|
"$DEPLOY_USER@$DEPLOY_HOST" "
|
||||||
|
echo \\"$HARBOR_PASS\\" | docker login $REGISTRY -u \\"$HARBOR_USER\\" --password-stdin &&
|
||||||
|
docker pull $IMAGE_NAME:latest &&
|
||||||
|
docker rm -f $CONTAINER_NAME || true &&
|
||||||
|
docker run -d \
|
||||||
|
--name $CONTAINER_NAME \
|
||||||
|
--restart always \
|
||||||
|
-p $HOST_PORT:$CONTAINER_PORT \
|
||||||
|
$IMAGE_NAME:latest &&
|
||||||
|
docker logout $REGISTRY
|
||||||
|
"
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
echo '流水线执行成功:代码拉取、构建、推送、部署已完成'
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo '流水线执行失败:请查看对应阶段日志'
|
||||||
|
}
|
||||||
|
always {
|
||||||
|
sh '''
|
||||||
|
if command -v docker >/dev/null 2>&1; then
|
||||||
|
docker image prune -f || true
|
||||||
|
else
|
||||||
|
echo "docker command not found, skip image prune"
|
||||||
|
fi
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
nginx.conf
Normal file
11
nginx.conf
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user