【问题标题】:How to use Dockerfile in Gitlab CI如何在 Gitlab CI 中使用 Dockerfile
【发布时间】:2018-02-26 05:09:43
【问题描述】:

在我的节点/反应应用程序中使用 gitlab-ci,我正在尝试使用 phusion/passenger-nodejs 作为基础 docker 映像

我可以在 .gitlab-ci.yml 中轻松指定:

image: phusion/passenger-nodejs:latest

variables:
  HOME: /root

cache:
  paths:
  - node_modules/

stages:
  - build
  - test
  - deploy

set_environment:
  stage: build
  script:
    - npm install
  tags:
  - docker

test_node:
  stage: test
  script:
    - npm install
    - npm test
  tags:
    - docker

但是,Phusion Passenger 希望您进行配置更改,例如python支持,在Dockerfile中使用他们特殊的init进程等。

#FROM phusion/passenger-ruby24:<VERSION>
#FROM phusion/passenger-jruby91:<VERSION>
FROM phusion/passenger-nodejs:<VERSION>
#FROM phusion/passenger-customizable:<VERSION>

# Set correct environment variables.
ENV HOME /root

# Use baseimage-docker's init process.
CMD ["/sbin/my_init"]

# If you're using the 'customizable' variant, you need to explicitly opt-in
# for features. 
#
# N.B. these images are based on https://github.com/phusion/baseimage-docker, 
# so anything it provides is also automatically on board in the images below 
# (e.g. older versions of Ruby, Node, Python).  
# 
# Uncomment the features you want:
#
#   Ruby support
#RUN /pd_build/ruby-2.0.*.sh
#RUN /pd_build/ruby-2.1.*.sh
#RUN /pd_build/ruby-2.2.*.sh
#RUN /pd_build/ruby-2.3.*.sh
#RUN /pd_build/ruby-2.4.*.sh
#RUN /pd_build/jruby-9.1.*.sh
#   Python support.
RUN /pd_build/python.sh
#   Node.js and Meteor standalone support.
#   (not needed if you already have the above Ruby support)
RUN /pd_build/nodejs.sh

# ...put your own build instructions here...

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

有没有办法在 gitlab-ci 中使用 Dockerfile?除了apt-get install 和添加 shell 脚本,还有什么好的解决方法吗?

【问题讨论】:

    标签: docker gitlab passenger gitlab-ci gitlab-ci-runner


    【解决方案1】:

    是的,在您放置 Dockerfile 的位置创建第二个 Gitlab 存储库。在那里您添加一个带有脚本命令的 gitlab-ci.yml 文件,该脚本命令构建您修改的图像并将其推送到您的私有注册表或 Gitlab 嵌入式 Docker 注册表,例如:

    script: docker build . -t http://myregistry:5000/mymodified image docker push http://myregistry:5000/mymodified

    在您的其他 Gitlab 存储库中,相应地更改 image: 行:

    image: http://myregistry:5000/mymodified

    可以在此处找到有关 Gitlab 嵌入式 Docker 注册表的信息 -> here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      相关资源
      最近更新 更多