dappfile.yaml
file (or dappfile.yml
). Configuration processing steps are as follows:dappfile.y[a]ml
;---
with a line break);ENV
dictionary for environment variables, defining dimg in loops, defining general assembly instructions using context inheritance. In order not to take away such opportunities from the developers, it was decided to add support for Go-templates to dappfile.yml - similar to Helm's charts.dappfile.yml
is a linear array of YAML documents, each of which is a dimg or artifact description. dimg: ~ from: alpine:latest shell: beforeInstall: - apk update
artifact: application-assets ... --- dimg: ~ ... import: - artifact: application-assets add: /app/public/assets after: install - artifact: application-assets add: /vendor to: /app/vendor after: install
git
, git remote
, shell
directives went from DSL to YAML almost “as is”, but there are two points: instead of underscores, camelCase is used (as in Kubernetes) and you need not to repeat the directives, but to merge the parameters, specifying the array: git: - add: / to: /app owner: app group: app excludePaths: - public/assets - vendor - .helm stageDependencies: install: - package.json - Bowerfile - Gemfile.lock - app/assets/* - url: https://github.com/kr/beanstalkd.git add: / to: /build shell: beforeInstall: - useradd -d /app -u 7000 -s /bin/bash app - rm -rf /usr/share/doc/* /usr/share/man/* - apt-get update - apt-get -y install apt-transport-https git curl gettext-base locales tzdata setup: - locale-gen en_US.UTF-8
dappfile.yml
, environment variables and labels can be added as follows: docker: ENV: <key>: <value> ... LABELS: <key>: <value> ...
ENV
or LABELS
, as it was in the Dappfile and in the Dockerfile. {{ $base_image := "alpine:3.6" }} dimg: app from: {{ $base_image }} ... --- dimg: worker from: {{ $base_image }}
{{ $base_image := "alpine:3.6" }} {{- define "base beforeInstall" }} - apt: name=php update_cache=yes - get_url: url: https://getcomposer.org/download/1.5.6/composer.phar dest: /usr/local/bin/composer mode: 0755 {{- end}} dimg: app from: {{ $base_image }} ansible: beforeInstall: {{- include "base beforeInstall" .}} - user: name: app uid: 48 ... --- dimg: worker from: {{ $base_image }} ansible: beforeInstall: {{- include "base beforeInstall" .}} ...
beforeInstall
stage beforeInstall
defined as a common part and then connected in each dimg.dappfile.yaml
.dappfile.yml
are executed in these containers. Builder creates a playbook and generates a command to launch it.userdel
will not be located in /sbin
, but somewhere in another directory ...useradd
, userdel
, usermod
, getent
and similar utilities to dappdeps / ansible and copy the python-apt modules.dappfile.yml
is similar to the shell
configuration. The necessary steps are listed in the ansible
key and an array of tasks is defined for each of them - almost as in a regular playbook, only the name of the stage is indicated instead of the tasks
attribute: ansible: beforeInstall: - name: "Create non-root main application user" user: name: app comment: "Non-root main application user" uid: 7000 shell: /bin/bash home: /app - name: "Disable docs and man files installation in dpkg" copy: content: | path-exclude=/usr/share/man/* path-exclude=/usr/share/doc/* dest: /etc/dpkg/dpkg.cfg.d/01_nodoc install: - name: "Precompile assets" shell: | set -e export RAILS_ENV=production source /etc/profile.d/rvm.sh cd /app bundle exec rake assets:precompile args: executable: /bin/bash
dappfile.yml
, then where is the rest (top level playbook, inventory), how to turn on become
and where are talking cows (or how to turn them off)? It's time to describe how to run Ansible.hosts
- inventory for Ansible. There is only one localhost host with the path to Python inside the mounted image dappdeps / ansible;ansible.cfg
- Ansible configuration. In the config, the local
connection type, the path to inventory, the path to callback stdout, the paths to temporary directories and the become
settings are specified: all tasks are started from the root user; if you use become_user
, then all environment variables will be accessible to the user process and $HOME
( sudo -E -H
) will be set correctly;playbook.yml
- this file is generated from the list of tasks for the stage being executed. The file specifies the hosts: all
filter and disables the implicit fact collection by setting the gather_facts: no
setting. The setup and set_fact modules are in the list of supported ones, so you can use them to explicitly collect facts.beforeInstall
stage from the example previously turns into this playbook.yml
: --- hosts: all gather_facts: no tasks: - name: "Create non-root main application user" user: name: app ... - name: "Disable docs and man files installation in dpkg" copy: content: | path-exclude=/usr/share/man/* path-exclude=/usr/share/doc/* dest: /etc/dpkg/dpkg.cfg.d/01_nodoc
become
in ansible.cfg
are: [become] become = yes become_method = sudo become_flags = -E -H become_exe = path_to_sudo_insdie_dappdeps/ansible_image
become_user: username
to run the script or copy from the user.raw
, script
, shell
and command
. raw
and script
are executed without the Ansiballz mechanism, which is slightly faster, and there is a live output for them. Using raw
you can run multiline ad-hoc scripts: - raw: | mvn -B -f pom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:resolve mvn -B -s /usr/share/maven/ref/settings-docker.xml package -DskipTests
environment
attribute is not supported, but it can be circumvented as follows: - raw: | mvn -B -f pom.xml -s $SETTINGS dependency:resolve mvn -B -s $SETTINGS package -DskipTests args: executable: SETTINGS=/usr/share/maven/ref/settings-docker.xml /bin/ash -e
git
directive. To add various kinds of configs, scripts and other small files to the image, you can use the copy module: - name: "Disable docs and man files installation in dpkg" copy: content: | path-exclude=/usr/share/man/* path-exclude=/usr/share/doc/* dest: /etc/dpkg/dpkg.cfg.d/01_nodoc
dappfile.yml
, you can use the Go-template and the function .Files.Get
: - name: "Disable docs and man files installation in dpkg" copy: content: | {{.Files.Get ".dappfiles/01_nodoc" | indent 6}} dest: /etc/dpkg/dpkg.cfg.d/01_nodoc
include*
or import*
.dappfile.yaml
has already been said. Ansible for its part supports jinja2 templates, and the separators of the two systems are the same, so the jinja call needs to be escaped from the Go template: - name: "create temp file for archive" tempfile: state: directory register: tmpdir - name: Download archive get_url: url: https://cdn.example.com/files/archive.tgz dest: '{{`{{ tmpdir.path }}`}}/archive.tgz'
ANSIBLE_ARGS="-vvv"
- then the output will contain all the arguments for tasks and all the arguments of the results (similar to using json stdout callback).dapp dimg bulid --introspect-error
. Then the build will stop after the error and the shell will be launched in the container. The command that caused the error will be visible, and in the adjacent terminal you can go to the temporary directory and edit the playbook.yml
:dappfile.yaml
was implemented on Go. Now, work continues on translating the main dapp functionality to Go: running assembly containers, builders, working with Git. Therefore, it will not be superfluous for your help in testing - including Ansible modules. We are waiting for the issue on GitHub or go to our group in the Telegram: dapp_ru .Source: https://habr.com/ru/post/351838/
All Articles