Comments (2)
以下是基于gitlab的分支和tag进行前端部署的.gitlab-ci.yml配置
image: node:12-alpine3.14
stages: # 分段
# - install
- build
- deploy
- clear
cache: # 缓存
paths:
- node_modules
job_install:
tags:
- test
stage: build
script:
- npm install -g cnpm --registry=https://registry.npm.taobao.org
- cnpm install
- npm run build
# 只在指定dev分支或者tag以 dev_ 开头的标签执行该job
only:
refs:
- dev
- /^dev_[0-9]+(?:.[0-9]+)+$/ # regular expression
# 打包后的文件可以在gitlab上直接下载
artifacts:
name: "dist"
paths:
- dist
job_deploy:
image: docker
stage: deploy
environment:
name: test
url: http://172.6.6.6:8000
script:
- docker build -t appimages .
- if [ $(docker ps -aq --filter name=app-container) ]; then docker rm -f app-container;fi
- docker run -d -p 8082:80 --name app-container appimages
job_clear:
image: docker
stage: clear
tags:
- test
script:
- if [ $(docker ps -aq | grep "Exited" | awk '{print $1 }') ]; then docker stop $(docker ps -a | grep "Exited" | awk '{print $1 }');fi
- if [ $(docker ps -aq | grep "Exited" | awk '{print $1 }') ]; then docker rm $(docker ps -a | grep "Exited" | awk '{print $1 }');fi
- if [ $(docker images | grep "none" | awk '{print $3}') ]; then docker rmi $(docker images | grep "none" | awk '{print $3}');fi
from daily-question.
一种基于容器及 docker-compose 或者 k8s 的思路
- 借用现有的 CICD 服务,如
github actions
或者gitlab CI
获取当前分支信息 - 借用 Docker 快速部署前端或者后端,根据分支信息启动不同的服务 (Service),根据 Docker 启动服务并配置响应的标签 (Label)
- 根据容器的标签与当前 Git 分支对前端后端设置不同的域名
以下是一个 Preview 的示例,其中服务名 cra-preview-${COMMIT_REF_NAME}
基于分支名称进行构建。
version: "3"
services:
cra-preview-${COMMIT_REF_NAME}:
build:
context: .
dockerfile: router.Dockerfile
labels:
# 配置域名: Preview
- "traefik.http.routers.cra-preview-${COMMIT_REF_NAME}.rule=Host(`${COMMIT_REF_NAME}.cra.shanyue.tech`)"
- traefik.http.routers.cra-preview-${COMMIT_REF_NAME}.tls=true
- traefik.http.routers.cra-preview-${COMMIT_REF_NAME}.tls.certresolver=le
在进行构建时,再通过 envsub
工具进行环境变量的替换
cat preview.docker-compose.yaml | envsubst > docker-compose.yaml
from daily-question.
Related Issues (20)
- 【Q737】如何取得一个数字的小数部分与整数部分 HOT 2
- 【Q738】websocket 和短轮询有什么区别 HOT 3
- 【Q739】webpack 中是如何处理 new URL 资源的
- 【Q740】vite 中是如何处理 new URL 资源的
- 【Q741】我们上传图片为 Blob/File 对象时,是如何向服务器端传送数据的 HOT 1
- [bug] B站的链接贴错了 HOT 2
- 引用仓库错了 HOT 2
- `<script type="module">` HOT 1
- 多阶段构建并不需要 docker-compose HOT 1
- 【Q742】大文件上传,如何获取到读取进度? HOT 1
- 代码
- [feature request]面试题添加难度排序以及一键生成一份面试题的工具 HOT 2
- 【Q747】如何实现一个 omit/omitBy 函数 HOT 6
- 【Q748】在 babel 编译为低版本 ES 时,为何能够编译可选链之类语法,但无法编译 API HOT 1
- 【Q743】实现 batchFn 函数,可以批量执行函数 HOT 4
- 【开源自荐】推荐一个每日更新的前端面试题库 HOT 1
- 【Q474】在 react 中,以下父子组件的 useEffect/useLayoutEffect 顺序如何 HOT 1
- 【Q745】webpack 的打包流程是什么样的 HOT 1
- 【Q744】数据库中更新一条记录时,如何自动更新其 updated_at 字段
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from daily-question.