如何在Gitlab CI中使用Dockerfile

13

我正在为我的node/react应用使用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 希望你使用他们特殊的 init 进程,在 Dockerfile 中进行配置更改,例如添加 Python 支持等。

#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脚本之外,还有什么好的解决方法吗?
在gitlab-ci中使用Dockerfile的方式是什么?除了执行“apt-get install”和添加shell脚本之外,是否还有其他好的解决方案?
1个回答

15
是的,在第二个Gitlab存储库中创建一个位置为Dockerfile的文件。您需要添加一个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注册表的信息可以在此处找到 -> 这里

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接