将 Docker 命令集成到 Gulp 管道

Integrating of the Docker commands to Gulp pipeline

我不喜欢 Docker 的 Gulp 插件。如果尝试 google 它,Googler 会认为我想要 运行 Gulp inside inside Docker 容器。 我不会做这样的事情

我无法理解将整个源代码复制到 Docker 容器并在其中构建项目的做法,尤其是当源代码和输出不同时(例如源代码的 TypeScript 和 JavaScript为输出)。对于 运行 应用程序,我们只需要像这样的几个构建文件:

一旦项目建成,Docker 容器中的所有源代码都将成为工业废物。好吧,我不会浪费时间去神圣 war 我应该在哪里建造我的 websites/applications。让我们假设我的方法——无论好坏——作为替代方案存在。

有人建议我解释我要做什么。 我要去:

  1. 通过Gulp
  2. 构建项目
  3. 通过docker build
  4. 构建图像
  5. 通过docker save
  6. 存档图像
  7. 通过 gulp-rsync
  8. 部署映像

1 和 4 由 Gulp 执行,而 2 和 3 - 由 Docker 执行,换句话说,Gulp 链被 Docker 链中断.有没有办法为上述所有任务构建单个 Gulp 链?

Docker文件示例(第 2 步需要)

FROM node:16

RUN mkdir -p /usr/exmpleapp.com
WORKDIR /usr/exmpleapp.com

COPY ./ProductionBuild /usr/exmpleapp.com

# Install non-bundled backend depencies only; no package(.lock).json required
RUN npm i express --no-save

EXPOSE 1337

CMD node "BackEndEntryPoint.js"

我不知道是否存在一些陷阱,但由于 Gulp 支持子进程,下面的任务(TypeScript 语法)似乎有效:

import { exec, ExecException } from "child_process";

Gulp.task(
  "build",
  (callback: (error: ExecException | null) => void): void => {

    exec("docker build -t exampleapp.com .", (
      error: ExecException | null, 
      standardOutput: string, 
      standardError: string
    ): void => {
      console.log(standardOutput);
      console.error(standardError);
      callback(error);
    });

  }
);

docker save 相同。剩下的就是用正确的顺序声明 gulp.series()