1.nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; # include /etc/nginx/conf.d/*.conf; upstream backupUrl { server 192.168.64.129:8080 weight=1 max_fails=2 fail_timeout=10s; } server { listen 80; charset utf-8; # 服务器地址或绑定域名 server_name 192.168.64.129; # start --------------------------------------------------------------------------------------------- location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; } location /api/ { proxy_pass http://192.168.64.129:8080/; #proxy_set_header Host $host; #proxy_set_header X-Real-IP $remote_addr; #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header REMOTE-HOST $remote_addr; #add_header X-Cache $upstream_cache_status; #add_header Cache-Control no-cache; } # end --------------------------------------------------------------------------------------------- error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } }
2.Dockerfile
FROM nginx:latest RUN rm /etc/nginx/conf.d/default.conf RUN rm /etc/nginx/nginx.conf COPY ./nginx/nginx.conf /etc/nginx/ COPY ./dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
3.[.drone.yml]
kind: pipeline # 定义一个管道 type: docker # 定义管道类型 name: deployment # 定义管道名称 steps: # 定义流水线执行步骤,这些步骤将顺序执行 - name: build-project # 流水线名称 image: node:latest # 定义创建容器的Docker镜像 volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置 - name: node_modules # 数据卷名称 path: /drone/src/Web/node_modules # 容器内的绝对路径 - name: node_build path: /drone/src/build commands: - rm -rf ./build/* - mkdir -p ./build/nginx - cd ./Web - export NODE_OPTIONS="--max-old-space-size=8192" - npm config set registry https://registry.npmmirror.com - npm install - npm run build - cp /drone/src/Dockerfile /drone/src/build - cp /drone/src/nginx.conf /drone/src/build/nginx/ - cp -r ./dist /drone/src/build/dist - echo project build success - name: build-docker image: plugins/docker privileged: true settings: context: /drone/src/build dockerfile: /drone/src/build/Dockerfile commands: - cd /drone/src/build - docker build -t fanqi/coreqi-web:latest . - docker stop coreqi-web && docker rm coreqi-web - docker run -d -p 10010:80 --name coreqi-web fanqi/coreqi-web:latest volumes: - name: node_build path: /drone/src/build - name: dockersock path: /var/run/docker.sock # 声明宿主机 映射到 drone执行器的数据卷,用于共享数据 volumes: - name: node_modules host: path: /mnt/drone/node/node_modules # 宿主机的绝对路径 - name: node_build host: path: /mnt/node - name: dockersock host: path: /var/run/docker.sock # 可限制哪些分支可以推送自动CICD trigger: branch: - main
标签:node,src,name,前端,实践,drone,nginx,Drone,build From: https://www.cnblogs.com/fanqisoft/p/17323390.html