npm start
command — this is where we will begin.npm start
command using the dapp dimg run
. Sources are usually added to some directory — for example, / app — so the docker.WORKDIR
directive is needed so that the command docker.WORKDIR
in the correct directory and not in the root of the image. The result was such a simple dappfile.yaml
: dimg: poolui from: node:9.11-alpine git: - add: / to: /app docker: WORKDIR: /app
dapp dimg build
dapp dimg run poolui -p 8080:8080 -ti --rm -- npm start
npm start
command is not enough to fully launch the application as a container.Dockerfile
in the project Dockerfile
it easy to create dappfile.yaml
, because immediately see all the commands to create an image.dappfile.yaml
for a project without a Dockerfile
, you need to determine from the description of the application assembly which commands to run. Our company engineers do this work either on the basis of their knowledge of utilities in different languages (npm, gulp, maven, composer, etc.), or in some cases, together with the customer’s developers, change the description files ( package.json
, gulpfile.js
, pom.xml
, composer.json
), so that the application build describes all the necessary dependencies.beforeInstall
stage, where installation of system packages is described, for example, if there are not enough tools in the selected base image. Then the install
stage is added, where the application sources are already available and you can run the build tools. After successfully assembling an image with two stages, you can go ahead and highlight some commands into other stages ( beforeSetup
, setup
), as well as describe sets of directories and files, changes in which will lead to reassembly.Dockerfile
is usually not applicable in the production environment. For rolling out an application in production, you need to work on defining commands for each stage of image assembly and on defining dependency files for these stages.package.json
- description of dependencies and actions for npm;bower.json
- description of application dependencies;gulpfile.js
- description of tasks.package.json
can see that gulp and bower will be needed for the build - these tools can be installed at the beforeInstall
stage, since their version will not change often. At the same stage git will be added, since It is needed for downloading dependencies. In the same file you can see the commands that were not enough: npm install
, bower install
. These commands will go to the install
stage, where dependencies are downloaded. The difference is small - for simplicity, bower install
is performed with the --allow-root
key. Rebuilding the install
stage depends on changes in the package.json
and bower.json
description files.npm start
runs the gulp
command, which will execute the default task from gulpfile.js
. This task sequentially launches three others: build
, connect
, watch
. Those. build and launch tasks are merged. This is convenient for a quick start, but in order to build an image, you will have to explicitly call the gulp build
at the setup
stage and install the reassembly setup
depending on the changes in the app
directory and the gulpfile.js
file.gulp connect
now used not npm start
, but. You gulp watch
not need to run gulp watch
, because This is a team to simplify development.dappfile.yaml
looks like this: dimg: poolui from: node:9.11-alpine git: - add: / to: /app stageDependencies: install: - package.json - bower.json beforeSetup: - app - gulpfile.js shell: beforeInstall: - apk update - apk add git - npm install --global bower - npm install --global gulp install: - cd /app - npm install - bower install --allow-root beforeSetup: - cd /app - gulp build docker: WORKDIR: "/app" CMD: ["gulp", "connect"]
dapp dimg run poolui -p 8080:8080 -ti --rm
:Server started http://localhost:8080
.gulpfile.js
so that the server gulpfile.js
on the address 0.0.0.0. Changes need to commit and run dapp dimg build
to build a new image. Since gulpfile.js
changes, then only the beforeSetup
stage needs to be rebuilt. The result can be seen in this asciicast:dapp dimg run poolui -p 8080:8080 -ti --rm
with dapp dimg run poolui -p 8080:8080 -ti --rm
:http://localhost:8080
), then you can see a similar page:gulp connect
is a module designed for development, and for production I would like to pack the application “correctly”. This option could be an image with nginx where the contents of the /app/build
directory will be copied. In dapp there are artifacts and intermediate or instrumental images - this feature will be used further./app/build
directory and it suffices to turn the described dimg into an artifact. It is worth noting that artifact cannot contain Docker directives, so they need to be removed, but otherwise there are no differences from dimg. Now you need to add a second dimg based on, for example, nginx: stable-ansible. The ready nginx image is configured to return static files from /usr/share/nginx/html
— import /app/build
into this directory. The finished dappfile.yml
looks like this: artifact: poolui-builder from: node:9.11-alpine git: - add: / to: /app stageDependencies: install: - package.json - bower.json beforeSetup: - app - gulpfile.js shell: beforeInstall: - apk update - apk add git - npm install --global bower - npm install --global gulp install: - cd /app - npm install - bower install --allow-root beforeSetup: - cd /app - gulp build --- dimg: poolui from: nginx:stable-ansible import: - artifact: poolui-builder add: /app/build to: /usr/share/nginx/html after: install
dapp dimg build
dapp dimg run poolui -p 8080:80 -ti --rm
gulp connect
: the page is shown in full. # dimgstage-poolui 0e27eaebff1f23312d18f83370ee30000a97139311fa141b86aa3f34b15e544d 6a1a7fc1aa98 8 minutes ago 25.1MB # poolui-builder dimgstage-poolui f000dbe70d25a5abb998997e6c0530db52f228fee4cdd0390046657bdb3a6d32 8f300d169e5e 17 minutes ago 241MB
dappfile.yaml
may turn dappfile.yaml
, which will reassemble only the necessary stages, speeding up the incremental builds.Source: https://habr.com/ru/post/359204/
All Articles