doupoji3856 2018-02-20 16:18 采纳率: 100%
浏览 904

设置PATH变量并在Dockerfile中获取环境

I've written a Dockerfile to create containers that have Golang installed. I have a goss test running the go version command, but the test is failing because the path variable (in the Dockerfile)--for some reason--doesn't stay set.

I've also tried sourcing the .env for go from inside the Dockerfile, but that doesn't seem to work either.

Dockerfile

ENV GIMME_VERSION "v1.4.0"
ENV GO_VERSION "1.4"
ENV JENKINS_HOME "/opt/jenkins"
ENV PATH="~/bin:${PATH}"
ENV PATH=“/opt/jenkins/.gimme/versions/go1.4.linux.amd64/bin:${PATH}“
ENV GOROOT="/opt/jenkins/.gimme/versions/go${GO_VERSION}.linux.amd64"

USER root

RUN yum -y install git && \
    yum -y clean all && \
    rm -rf /var/cache/yum

WORKDIR $JENKINS_HOME

USER jenkins

RUN mkdir ~/bin && \
    curl -sL -o ~/bin/gimme https://raw.githubusercontent.com/travis-
    ci/gimme/${GIMME_VERSION}/gimme && \
    chmod +x ~/bin/gimme && \
    gimme ${GO_VERSION}

USER root

RUN source /opt/jenkins/.gimme/envs/go${GO_VERSION}.linux.amd64.env

Goss Yaml

file:
  /opt/jenkins/.gimme:
    exists: true
    filetype: directory
  /opt/jenkins/.gimme/envs/go1.4.env:
    exists: true
    filetype: file
  /opt/jenkins/.gimme/versions/go1.4.linux.amd64:
    exists: true
    filetype: directory
  /opt/jenkins/.gimme/versions/go1.4.linux.amd64/bin/go:
    exists: true
    filetype: file
  /opt/jenkins/.gimme/versions/go1.4.linux.amd64/pkg:
    exists: true
    filetype: directory
  /opt/jenkins/.gimme/versions/go1.4.linux.amd64/src:
    exists: true
    filetype: directory
  /opt/jenkins/bin/gimme:
    filetype: file
    exists: true
    mode: '0755'
command:
  'gimme version':
  exit-status: 0
  'go version':
  exit-status: 0
  • 写回答

1条回答 默认 最新

  • douqin3245 2018-02-20 16:35
    关注

    It's not very clear at a first glance, but your double quotes around PATH are not the good unicode character. You should replace them by the usual ", not (Unicode UTF8 codepoint U+201C)

    Demo: not the same:

    $ od -c <<< \"
    0000000   "  
    
    0000002
    $ od -c <<< \“
    0000000 342 200 234  
    
    0000004
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?