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}

效果展示:

在这里插入图片描述
在这里插入图片描述

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐