Deployment Documentation
Introduction
This document outlines our deployment strategy using Docker, a popular containerization technology, to ensure our software system is accessible and consistently operates across different environments.
Frontend Deployment
Tools and Technologies
- Docker: Utilized for containerization.
- Node.js: JavaScript runtime for building the frontend.
- Nginx: Web server for serving static files.
Dockerfile for Frontend
# Build stage
FROM node:14 AS build-stage
WORKDIR /app
# Install dependencies
COPY package*.json ./
RUN npm install
# Build the application
COPY . .
RUN npm run build
# Production stage
FROM nginx:alpine
COPY /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
pipeline {
agent any
environment {
IMAGE_NAME = 'nginx-image'
IMAGE_TAG = '1.7'
DOCKERFILE_PATH = 'frontend/Dockerfile'
DOCKER_BUILD_CONTEXT = 'frontend'
DOCKER_CREDS = credentials('dockerhub_credentials')
}
stages {
stage('Build Docker Image') {
steps {
script {
// bat "docker rmi ${IMAGE_NAME}:${IMAGE_TAG}"
bat "docker build -t tlz970370568/${IMAGE_NAME}:${IMAGE_TAG} -f ${DOCKERFILE_PATH} ${DOCKER_BUILD_CONTEXT}"
// bat "docker run -d --name vue-container -p 8081:8080 ${IMAGE_NAME}:${IMAGE_TAG}"
// 登录到Docker Hub(如果需要)
bat "docker login --username ${DOCKER_CREDS_USR} --password ${DOCKER_CREDS_PSW}"
// 推送镜像到Docker Hub(如果需要)
bat "docker push tlz970370568/${IMAGE_NAME}:${IMAGE_TAG}"
}
}
}
}
post {
always {
cleanWs()
}
}
}