Home > Mobile >  Integrating of the Docker commands to Gulp pipeline
Integrating of the Docker commands to Gulp pipeline

Time:01-02

I did not fond the Gulp plugin for the Docker. If try to google it, the Googler will think what I want to run Gulp inside inside Docker container. I don't going to do something like this.

I can't understand the practice to copy whole source code to Docker container and build the project inside especially when the source code and output are different (like TypeScript for the source and JavaScript for the output). To run the application, all we need is just a few built files like this:

enter image description here

All of the source code inside the Docker container will become to industrial wastes once project will built. Well, I don't going to waste the time to holy war about where I should to build my websites/applications. Just let us assume that my methodology - whatever good or bad - existing as the alternative.

I has been reccommended to explain what exactly I going to do. I going to:

  1. Build the project by Gulp
  2. Build the image by docker build
  3. Archive the image by docker save
  4. Deploy the image by gulp-rsync

1 and 4 are being executed by Gulp while 2 and 3 - by Docker, by other words, the Gulp chain is being interrupted by Docker chain. Is there the way to build the single Gulp chain for all of above tasks?

Dockerfile example (required for the step 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"

CodePudding user response:

I don't know are there some pitfalls, but since Gulp supports the child processes, below task (TypeScript syntax) seems to be working:

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);
    });

  }
);

Same for docker save. All that left is declare gulp.series() with right sequence.

  • Related