如何在Gitlab CI中使用Dockerfile [英] How to use Dockerfile in Gitlab CI

查看:751
本文介绍了如何在Gitlab CI中使用Dockerfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用gitlab-ci作为我的节点/反应应用程序,我试图使用 phusion / passenger-nodejs 作为基本docker镜像

Using gitlab-ci for my node/react app, I'm trying to use phusion/passenger-nodejs as the base docker image

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

I can specify this easily in .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支持,使用其特殊的init进程等在Dockerfile中。

However, Phusion Passenger expects you to make configuration changes, e.g. python support, using their special init process, etc. in the Dockerfile.

#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脚本以外,还有其他好的方法吗?

Is there a way to use a Dockerfile with gitlab-ci? Is there a good work around other than apt-get install and adding shell scripts?

推荐答案

是的,在您放置Dockerfile的位置创建第二个Gitlab存储库。使用脚本命令在其中添加gitlab-ci.yml文件,该脚本命令会生成修改后的映像并将其推送到您的私有注册表或Gitlab嵌入式Docker注册表,例如:

Yes, create a second Gitlab repository where you place your Dockerfile in. There you add a gitlab-ci.yml file with a script command that builds you modified image and push it to your private registry or the Gitlab embedded Docker registry, eg:

脚本:
docker build。 -t http:// myregistry:5000 / mymodified image
docker push http:// myregistry:5000 / mymodified

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

Inside your other Gitlab repository, change the image: line accordingly:

image:http: // myregistry:5000 / mymodified

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

Information on the Gitlab embedded Docker registry can be found here -> here

这篇关于如何在Gitlab CI中使用Dockerfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆