GitLab CI/CD 之 pipeline通过envsubst透传参数案例
本篇目录链接项目信息:项目说明:nginx项目效果展示:envsubst介绍envsubst简单应用项目信息:项目说明:通过在ci文件中的定义变量,然后将值传入到index.htm中生成index.html文件,从而满足dockerfile中的文件格式,进而完成打包操作。ci中用到的192.168.137.14:5000/centos:env这个镜像里面包含了envsubst,要不然会提示envs
·
envsubst介绍
envsubst简单应用
项目信息:
项目说明:
- 通过在ci文件中的定义变量,然后将值传入到index.htm中生成index.html文件,从而满足dockerfile中的文件格式,进而完成打包操作。
- ci中用到的192.168.137.14:5000/centos:env这个镜像里面包含了envsubst,要不然会提示envsubst 找不到。
nginx项目:
cat index.htm
nginx:${version}
cat Dockerfile
FROM nginx:latest
COPY index.html /usr/share/nginx/html/
cat .gitlab-ci.yml
image: docker:19.03.13
variables:
version: v3
stages: # List of stages for jobs, and their order of execution
- build
- test
- deploy
build-job: # This job runs in the build stage, which runs first.
stage: build
tags:
- test
script:
- which docker
lint-test-job: # This job also runs in the test stage.
stage: test # It can run at the same time as unit-test-job (in parallel).
tags:
- test
script:
- docker version
deploy-job: # This job runs in the deploy stage.
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
image: 192.168.137.14:5000/centos:env
tags:
- test
script:
- envsubst < index.htm > index.html #生成没有变量的文本文件
- docker build -t 192.168.137.14:5000/nginx:${version} -f Dockerfile .
- docker push 192.168.137.14:5000/nginx:${version}
效果展示:
更多推荐
已为社区贡献2条内容
所有评论(0)