node.js - gitlab.com CI - 在 docker 中使用 docker 构建 NodeJS 应用程序

标签 node.js docker gitlab gitlab-ci gitlab-ci-runner

我目前面临 gitlab.com 共享运行程序的问题。我试图在我的管道中实现的是:
- NPM 安装并使用 grunt 制作一些 uncss、最小化和压缩任务
- 打扫干净 - 构建包含应用程序的 Docker 容器
- 将容器移至 gitlab 注册表

不幸的是我已经很长时间没有让它运行了!我尝试了很多不同的 gitlab.ci 配置 - 但没有成功。问题是,我必须使用“image: docker:latest”来运行所有 docker-tools。但是我没有在容器中安装 Node 和 grunt。
反过来也行不通。我试图使用 image: centos:latest 并手动安装 docker - 但这也不起作用,因为我总是收到 Failed to get D-Bus connection: Operation not allowed
有谁对 gitlab-ci 在 docker 共享运行器中使用 docker build 命令有更多经验吗?
非常感谢任何帮助!

谢谢
詹尼克

最佳答案

Gitlab 可能有点棘手:) 我没有基于 CentOS 的示例,但我有一个基于 Ubuntu 的示例(如果对您有帮助的话)。这是我的一个工作 gitlab 管道的一些复制粘贴,它使用 gulp (你应该能够轻松地调整它以适应你的 grunt)。

.gitlab-ci.yml 看起来像这样(在开头调整 CONTAINER... 变量):

variables:
  CONTAINER_TEST_IMAGE: registry.gitlab.com/psono/psono-client:$CI_BUILD_REF_NAME
  CONTAINER_RELEASE_IMAGE: registry.gitlab.com/psono/psono-client:latest

stages:
  - build

docker-image:
  stage: build
  image: ubuntu:16.04
  services:
    - docker:dind
  variables:
    DOCKER_HOST: 'tcp://docker:2375'
  script:
    - sh ./var/build-ubuntu.sh
    - docker info
    - docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" registry.gitlab.com
    - docker build -t $CONTAINER_TEST_IMAGE .
    - docker push $CONTAINER_TEST_IMAGE

此外,我还有一个“./var/build-ubuntu.sh”,您可以根据需要进行一些调整,替换一些 ubuntu 依赖项或根据需要将 gulp 切换为 grunt:

#!/usr/bin/env bash
apt-get update && \
apt-get install -y libfontconfig zip nodejs npm git apt-transport-https ca-certificates curl openssl software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -  && \
add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable" && \
apt-get update && \
apt-get install -y docker-ce && \
ln -s /usr/bin/nodejs /usr/bin/node && \
npm install && \
node --version && \
npm --version

关于node.js - gitlab.com CI - 在 docker 中使用 docker 构建 NodeJS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44343848/

相关文章:

node.js - 使用 dc 和 Node.js 预渲染图表

node.js - 发布nodejs包时,有些文件上传到npm但没有上传到Github。为什么?

node.js - 生成CSV文件时如何处理分号?

git - Github、Gitlab、Gitosis 等如何知道哪个用户登录了?

merge - gitlab 请求将分支 A 合并到开发中(后面 3 个提交)我应该担心吗?

Gitlab 阻止从功能到 master 的合并请求

javascript - Node.js - 段错误 : 11 With Quite Large Array

Docker-compose - 设置不是文字的环境变量

java - docker 中 Redis 设置集群模式的问题(Windows 7)

docker - 使用 docker 容器作为网络内的 SSH 隧道