diff --git a/.gitignore b/.gitignore index debd739e..9436b367 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,40 @@ -.kitchen/ -.ruby-version -junit*.xml - # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a packager +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + # Unit test / coverage reports htmlcov/ .tox/ @@ -15,5 +43,81 @@ htmlcov/ .cache nosetests.xml coverage.xml -*,cover +*.cover .hypothesis/ +.kitchen +.kitchen.local.yml +kitchen.local.yml +junit-*.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Bundler +.bundle/ +Gemfile.lock + +# copied `.md` files used for conversion to `.rst` using `m2r` +docs/*.md + +# Vim +*.sw? + +## Collected when centralising formulas (check and sort) +# `collectd-formula` +.pytest_cache/ +/.idea/ +Dockerfile.*_* +ignore/ +tmp/ diff --git a/.kitchen.yml b/.kitchen.yml deleted file mode 100644 index 99e01e87..00000000 --- a/.kitchen.yml +++ /dev/null @@ -1,78 +0,0 @@ ---- -driver: - name: docker - use_sudo: false - privileged: true - -provisioner: - name: salt_solo - log_level: warning - require_chef: false - formula: docker - state_top: - base: - '*': - - docker.remove - - docker - pillars: - top.sls: - base: - '*': - - docker - -platforms: - - name: ubuntu-18.04 - driver_config: - provision_command: - - apt-get update && apt-get install -y locales ifupdown - - locale-gen en_US.UTF-8 - - update-locale LANG=en_US.UTF-8 - - mkdir -p /run/sshd - run_command: /lib/systemd/systemd - - name: debian-stretch - driver_config: - provision_command: - - apt-get update && apt-get install -y locales ifupdown - - locale-gen en_US.UTF-8 - run_command: /lib/systemd/systemd - - name: debian-jessie - driver_config: - provision_command: - - apt-get update && apt-get install -y locales ifupdown - - locale-gen en_US.UTF-8 - run_command: /lib/systemd/systemd -# - name: centos-7 -# driver_config: -# run_command: /lib/systemd/systemd - -suites: - - name: default - provisioner: - pillars: - docker.sls: - docker: - use_upstream_repo: true - - name: version-1.13.1 - provisioner: - pillars: - docker.sls: - docker: - version: '1.13.1*' - use_old_repo: true - excludes: - - ubuntu-18.04 - - name: version-18 - provisioner: - pillars: - docker.sls: - docker: - version: '18.*' - use_old_repo: true - excludes: - - debian-stretch - - debian-jessie - -verifier: - name: shell - remote_exec: false - command: testinfra -vvv --connection=docker --hosts=root@$KITCHEN_CONTAINER_ID --junit-xml junit-$KITCHEN_INSTANCE.xml test/integration/$KITCHEN_SUITE diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..96fd6e53 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +# General overrides used across formulas in the org +Layout/LineLength: + # Increase from default of `80` + # Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`) + Max: 88 + +# Any offenses that should be fixed, e.g. collected via. `rubocop --auto-gen-config` diff --git a/.salt-lint b/.salt-lint new file mode 100644 index 00000000..ccd08083 --- /dev/null +++ b/.salt-lint @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +exclude_paths: [] +rules: + 204: # Lines should be no longer that 160 chars + ignore: | + docker/repo.sls +skip_list: + # Using `salt-lint` for linting other files as well, such as Jinja macros/templates + - 205 # Use ".sls" as a Salt State file extension + # Skipping `207` and `208` because `210` is sufficient, at least for the time-being + # I.e. Allows 3-digit unquoted codes to still be used, such as `644` and `755` + - 207 # File modes should always be encapsulated in quotation marks + - 208 # File modes should always contain a leading zero +tags: [] +verbosity: 1 diff --git a/.travis.yml b/.travis.yml index afd913a7..19e40baf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,116 @@ -sudo: required +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +## Machine config +os: 'linux' +arch: 'amd64' +dist: 'bionic' +version: '~> 1.0' +## Language and cache config +language: 'ruby' +cache: 'bundler' -language: python - +## Services config services: - docker -before_install: - - bundle install +## Script to run for the test stage +script: + - bin/kitchen verify "${INSTANCE}" +## Stages and jobs matrix +stages: + - test + - name: 'release' + if: 'branch = master AND type != pull_request' +jobs: + include: + ## Define the test stage that runs the linters (and testing matrix, if applicable) -env: - matrix: - - INSTANCE: default-ubuntu-1804 - - INSTANCE: default-debian-jessie - - INSTANCE: default-debian-stretch - - INSTANCE: version-1131-debian-jessie - - INSTANCE: version-1131-debian-stretch + # Run all of the linters in a single job + - language: 'node_js' + node_js: 'lts/*' + env: 'Lint' + name: 'Lint: salt-lint, yamllint, rubocop, shellcheck & commitlint' + before_install: 'skip' + script: + # Install and run `salt-lint` + - pip install --user salt-lint + - git ls-files -- '*.sls' '*.jinja' '*.j2' '*.tmpl' '*.tst' + | xargs salt-lint + # Install and run `yamllint` + # Need at least `v1.17.0` for the `yaml-files` setting + - pip install --user yamllint>=1.17.0 + - yamllint -s . + # Install and run `rubocop` + - gem install rubocop + - rubocop -d + # Run `shellcheck` (already pre-installed in Travis) + - shellcheck --version + - git ls-files -- '*.sh' '*.bash' '*.ksh' + | xargs shellcheck + # Install and run `commitlint` + - npm i -D @commitlint/config-conventional + @commitlint/travis-cli + - commitlint-travis -script: - - bundle exec kitchen verify ${INSTANCE} + ## Define the rest of the matrix based on Kitchen testing + # Make sure the instances listed below match up with + # the `platforms` defined in `kitchen.yml` + - env: INSTANCE=default-debian-10-master-py3 + # - env: INSTANCE=default-ubuntu-1804-master-py3 + # - env: INSTANCE=default-centos-8-master-py3 + # - env: INSTANCE=default-fedora-31-master-py3 + # - env: INSTANCE=default-opensuse-leap-151-master-py3 + # - env: INSTANCE=default-amazonlinux-2-master-py3 + # - env: INSTANCE=default-arch-base-latest-master-py2 + # - env: INSTANCE=default-debian-10-2019-2-py3 + - env: INSTANCE=default-debian-9-2019-2-py3 + - env: INSTANCE=default-ubuntu-1804-2019-2-py3 + # - env: INSTANCE=default-centos-8-2019-2-py3 + # - env: INSTANCE=default-fedora-31-2019-2-py3 + # - env: INSTANCE=default-opensuse-leap-151-2019-2-py3 + # - env: INSTANCE=default-centos-7-2019-2-py2 + # - env: INSTANCE=default-amazonlinux-2-2019-2-py3 + - env: INSTANCE=default-arch-base-latest-2019-2-py2 + # - env: INSTANCE=default-fedora-30-2018-3-py3 + - env: INSTANCE=default-debian-9-2018-3-py2 + # - env: INSTANCE=default-ubuntu-1604-2018-3-py2 + # - env: INSTANCE=default-centos-7-2018-3-py2 + # - env: INSTANCE=default-opensuse-leap-151-2018-3-py2 + # - env: INSTANCE=default-amazonlinux-1-2018-3-py2 + # - env: INSTANCE=default-arch-base-latest-2018-3-py2 + # - env: INSTANCE=default-debian-8-2017-7-py2 + - env: INSTANCE=default-ubuntu-1604-2017-7-py2 + # - env: INSTANCE=default-centos-6-2017-7-py2 + # - env: INSTANCE=default-fedora-30-2017-7-py2 + # - env: INSTANCE=default-opensuse-leap-151-2017-7-py2 + # - env: INSTANCE=default-amazonlinux-1-2017-7-py2 + # - env: INSTANCE=default-arch-base-latest-2017-7-py2 + + ## Define the release stage that runs `semantic-release` + - stage: 'release' + language: 'node_js' + node_js: 'lts/*' + env: 'Release' + name: 'Run semantic-release inc. file updates to AUTHORS, CHANGELOG & FORMULA' + before_install: 'skip' + script: + # Update `AUTHORS.md` + - export MAINTAINER_TOKEN=${GH_TOKEN} + - go get github.com/myii/maintainer + - maintainer contributor + + # Install all dependencies required for `semantic-release` + - npm i -D @semantic-release/changelog@3 + @semantic-release/exec@3 + @semantic-release/git@7 + deploy: + provider: 'script' + # Opt-in to `dpl v2` to complete the Travis build config validation (beta) + # * https://docs.travis-ci.com/user/build-config-validation + # Deprecated `skip_cleanup` can now be avoided, `cleanup: false` is by default + edge: true + # Run `semantic-release` + script: 'npx semantic-release@15.14' diff --git a/.yamllint b/.yamllint new file mode 100644 index 00000000..358570e0 --- /dev/null +++ b/.yamllint @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +# Extend the `default` configuration provided by `yamllint` +extends: default + +# Files to ignore completely +# 1. All YAML files under directory `node_modules/`, introduced during the Travis run +# 2. Any SLS files under directory `test/`, which are actually state files +# 3. Any YAML files under directory `.kitchen/`, introduced during local testing +ignore: | + node_modules/ + test/**/states/**/*.sls + .kitchen/ + docker/osfamilymap.yaml + +yaml-files: + # Default settings + - '*.yaml' + - '*.yml' + - .salt-lint + - .yamllint + # SaltStack Formulas additional settings + - '*.example' + - test/**/*.sls + +rules: + empty-values: + forbid-in-block-mappings: true + forbid-in-flow-mappings: true + line-length: + # Increase from default of `80` + # Based on https://github.com/PyCQA/flake8-bugbear#opinionated-warnings (`B950`) + max: 88 + octal-values: + forbid-implicit-octal: true + forbid-explicit-octal: true diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 00000000..283baf57 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,60 @@ +# Authors + +This list is sorted by the number of commits per contributor in _descending_ order. + +Avatar|Contributor|Contributions +:-:|---|:-: +@noelmcloughlin|[@noelmcloughlin](https://github.com/noelmcloughlin)|86 +@cdarwin|[@cdarwin](https://github.com/cdarwin)|25 +@myii|[@myii](https://github.com/myii)|25 +@gravyboat|[@gravyboat](https://github.com/gravyboat)|22 +@aboe76|[@aboe76](https://github.com/aboe76)|21 +@javierbertoli|[@javierbertoli](https://github.com/javierbertoli)|18 +@puneetk|[@puneetk](https://github.com/puneetk)|15 +@vladvasiliu|[@vladvasiliu](https://github.com/vladvasiliu)|12 +@nmadhok|[@nmadhok](https://github.com/nmadhok)|9 +@ticosax|[@ticosax](https://github.com/ticosax)|7 +@alexproca|[@alexproca](https://github.com/alexproca)|6 +@blbradley|[@blbradley](https://github.com/blbradley)|6 +@whiteinge|[@whiteinge](https://github.com/whiteinge)|6 +@toopy|[@toopy](https://github.com/toopy)|5 +@VBH-Jenkins|[@VBH-Jenkins](https://github.com/VBH-Jenkins)|5 +@babilen5|[@babilen5](https://github.com/babilen5)|3 +@techhat|[@techhat](https://github.com/techhat)|2 +@msciciel|[@msciciel](https://github.com/msciciel)|2 +@mingfang|[@mingfang](https://github.com/mingfang)|2 +@Poil|[@Poil](https://github.com/Poil)|2 +@stamak|[@stamak](https://github.com/stamak)|2 +@tedski|[@tedski](https://github.com/tedski)|2 +@tyhunt99|[@tyhunt99](https://github.com/tyhunt99)|2 +@DavidJFelix|[@DavidJFelix](https://github.com/DavidJFelix)|2 +@scornelissen85|[@scornelissen85](https://github.com/scornelissen85)|2 +@alxwr|[@alxwr](https://github.com/alxwr)|1 +@alinefr|[@alinefr](https://github.com/alinefr)|1 +@ernstae|[@ernstae](https://github.com/ernstae)|1 +@iggy|[@iggy](https://github.com/iggy)|1 +@solarchad|[@solarchad](https://github.com/solarchad)|1 +@blueyed|[@blueyed](https://github.com/blueyed)|1 +@comozo|[@comozo](https://github.com/comozo)|1 +@JohnMaguire|[@JohnMaguire](https://github.com/JohnMaguire)|1 +@jstjohn|[@jstjohn](https://github.com/jstjohn)|1 +@jfrederickson|[@jfrederickson](https://github.com/jfrederickson)|1 +@y2kenny|[@y2kenny](https://github.com/y2kenny)|1 +@LarsFronius|[@LarsFronius](https://github.com/LarsFronius)|1 +@xenophonf|[@xenophonf](https://github.com/xenophonf)|1 +@MrDiba|[@MrDiba](https://github.com/MrDiba)|1 +@pwaller|[@pwaller](https://github.com/pwaller)|1 +@syndicut|[@syndicut](https://github.com/syndicut)|1 +@rgreinho|[@rgreinho](https://github.com/rgreinho)|1 +@toanju|[@toanju](https://github.com/toanju)|1 +@tobias-m|[@tobias-m](https://github.com/tobias-m)|1 +@ghostsquad|[@ghostsquad](https://github.com/ghostsquad)|1 +@greut|[@greut](https://github.com/greut)|1 +@myoung34|[@myoung34](https://github.com/myoung34)|1 +@norrland|[@norrland](https://github.com/norrland)|1 +@oonska|[@oonska](https://github.com/oonska)|1 +@tiadobatima|[@tiadobatima](https://github.com/tiadobatima)|1 + +--- + +Auto-generated by a [forked version](https://github.com/myii/maintainer) of [gaocegege/maintainer](https://github.com/gaocegege/maintainer) on 2020-01-22. diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..a7a9c488 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,61 @@ +# Changelog + +# [0.43.0](https://github.com/saltstack-formulas/docker-formula/compare/v0.42.0...v0.43.0) (2020-01-22) + + +### Bug Fixes + +* **release.config.js:** use full commit hash in commit link [skip ci] ([01ece3d](https://github.com/saltstack-formulas/docker-formula/commit/01ece3dba8e581b15da1087c58b484b56177f0de)) + + +### Continuous Integration + +* **gemfile:** restrict `train` gem version until upstream fix [skip ci] ([734d4e3](https://github.com/saltstack-formulas/docker-formula/commit/734d4e3a884253ecc0f37493b0af6cf2398dbac0)) +* **kitchen:** use `debian-10-master-py3` instead of `develop` [skip ci] ([d87e787](https://github.com/saltstack-formulas/docker-formula/commit/d87e7871989b56293b577976c122c6c7095d61e3)) +* **kitchen:** use `develop` image until `master` is ready (`amazonlinux`) [skip ci] ([71c5bcb](https://github.com/saltstack-formulas/docker-formula/commit/71c5bcb0aead53192ec4bb9f560ed312c80af1f6)) +* **kitchen+travis:** upgrade matrix after `2019.2.2` release [skip ci] ([2189efb](https://github.com/saltstack-formulas/docker-formula/commit/2189efbc8af5fa6a529acbe3410b62558132a044)) +* **travis:** apply changes from build config validation [skip ci] ([f0a07fc](https://github.com/saltstack-formulas/docker-formula/commit/f0a07fc7c03107b21dd9f7161972b084893f19ee)) +* **travis:** opt-in to `dpl v2` to complete build config validation [skip ci] ([340556e](https://github.com/saltstack-formulas/docker-formula/commit/340556e081780d890db064dc84d7fdd177e55d93)) +* **travis:** quote pathspecs used with `git ls-files` [skip ci] ([12bf914](https://github.com/saltstack-formulas/docker-formula/commit/12bf914e2468ce8b09f172c12c5df8aa4b7175e5)) +* **travis:** run `shellcheck` during lint job [skip ci] ([ba127a0](https://github.com/saltstack-formulas/docker-formula/commit/ba127a08113bf43f3bbb7691d1bc670e659e4c45)) +* **travis:** use `major.minor` for `semantic-release` version [skip ci] ([2590d61](https://github.com/saltstack-formulas/docker-formula/commit/2590d61eeadb82ae420db450f3885b95a77be52c)) +* **travis:** use build config validation (beta) [skip ci] ([fe184e9](https://github.com/saltstack-formulas/docker-formula/commit/fe184e95123ad90c2a38515a50118f5ab82cac1b)) + + +### Features + +* support optional container removal before start in upstart/systemd ([cc10d97](https://github.com/saltstack-formulas/docker-formula/commit/cc10d97ee0a8f85f8d94f6ec4b1918c906338afd)) + + +### Performance Improvements + +* **travis:** improve `salt-lint` invocation [skip ci] ([18fa798](https://github.com/saltstack-formulas/docker-formula/commit/18fa79879dbb37c90c45c836018126dfbd61f5e2)) + +# [0.42.0](https://github.com/saltstack-formulas/docker-formula/compare/v0.41.0...v0.42.0) (2019-10-23) + + +### Bug Fixes + +* **compose-ng.sls:** fix `salt-lint` errors ([](https://github.com/saltstack-formulas/docker-formula/commit/9e8e1e8)) +* **pillar.example:** ensure `docker.config` is available ([](https://github.com/saltstack-formulas/docker-formula/commit/dce112a)) + + +### Continuous Integration + +* **travis:** update `salt-lint` config for `v0.0.10` ([](https://github.com/saltstack-formulas/docker-formula/commit/3eaed1b)) + + +### Documentation + +* **readme:** move to `docs/` directory and modify accordingly ([](https://github.com/saltstack-formulas/docker-formula/commit/222fc6d)) + + +### Features + +* **semantic-release:** implement for this formula ([](https://github.com/saltstack-formulas/docker-formula/commit/ea6be11)) + + +### Tests + +* **inspec:** add tests for package, config & service ([](https://github.com/saltstack-formulas/docker-formula/commit/451d76d)) +* **testinfra:** remove from the formula ([](https://github.com/saltstack-formulas/docker-formula/commit/62122d2)) diff --git a/FORMULA b/FORMULA new file mode 100644 index 00000000..16dcb81f --- /dev/null +++ b/FORMULA @@ -0,0 +1,9 @@ +name: docker +os: Debian, Ubuntu, Raspbian, RedHat, Fedora, CentOS, Suse, openSUSE, Gentoo, Funtoo, Arch, Manjaro, Alpine, FreeBSD, OpenBSD, Solaris, SmartOS, Windows, MacOS +os_family: Debian, RedHat, Suse, Gentoo, Arch, Alpine, FreeBSD, OpenBSD, Solaris, Windows, MacOS +version: 0.43.0 +release: 1 +minimum_version: 2017.7 +summary: docker formula +description: Formula for working with Docker +top_level_dir: docker diff --git a/Gemfile b/Gemfile index 1947ff45..8da7a69a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,11 @@ -source "https://rubygems.org" +# frozen_string_literal: true -gem "test-kitchen" -gem "kitchen-docker" -gem "kitchen-salt" +source 'https://rubygems.org' + +gem 'kitchen-docker', '>= 2.9' +gem 'kitchen-inspec', '>= 1.1' +gem 'kitchen-salt', '>= 0.6.0' +# Latest versions of `train` cause failure when running `kitchen verify` +# Downgrading to `3.2.0` until this is fixed upstream +# https://github.com/inspec/train/pull/544#issuecomment-566055052 +gem 'train', '3.2.0' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 384d707b..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,41 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - artifactory (2.5.0) - kitchen-docker (2.6.0) - test-kitchen (>= 1.0.0) - kitchen-salt (0.0.24) - test-kitchen (~> 1.4) - mixlib-install (2.1.4) - artifactory - mixlib-shellout - mixlib-versioning - thor - mixlib-shellout (2.2.7) - mixlib-versioning (1.1.0) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-ssh (3.2.0) - net-ssh-gateway (1.2.0) - net-ssh (>= 2.6.5) - safe_yaml (1.0.4) - test-kitchen (1.13.2) - mixlib-install (>= 1.2, < 3.0) - mixlib-shellout (>= 1.2, < 3.0) - net-scp (~> 1.1) - net-ssh (>= 2.9, < 4.0) - net-ssh-gateway (~> 1.2.0) - safe_yaml (~> 1.0) - thor (~> 0.18) - thor (0.19.1) - -PLATFORMS - ruby - -DEPENDENCIES - kitchen-docker - kitchen-salt - test-kitchen - -BUNDLED WITH - 1.13.6 diff --git a/bin/kitchen b/bin/kitchen new file mode 100755 index 00000000..dcfdb4ca --- /dev/null +++ b/bin/kitchen @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'kitchen' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort( + 'Your `bin/bundle` was not generated by Bundler, '\ + 'so this binstub cannot run. Replace `bin/bundle` by running '\ + '`bundle binstubs bundler --force`, then run this command again.' + ) + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('test-kitchen', 'kitchen') diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 00000000..2f9d1aa0 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], +}; diff --git a/docker/clean.sls b/docker/clean.sls new file mode 100644 index 00000000..8da519f8 --- /dev/null +++ b/docker/clean.sls @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls +{% from "docker/map.jinja" import docker with context %} + +docker-packages-cleaned-service-dead: + service.dead: + - name: docker + {% if "process_signature" in docker %} + - sig: {{ docker.process_signature }} + - onlyif: ps -ef | grep "{{ docker.process_signature }}" ##stop stderr from sig + {% endif %} + - require_in: + - pkg: docker-packages-cleaned + +docker-packages-cleaned: + pkg.removed: + - pkgs: + - {{ docker.pkg.old_name if docker.use_old_repo else docker.pkg.name }} + - docker + - docker.io + - docker-client + - docker-client-latest + - docker-common + - docker-latest + - docker-latest-logrotate + - docker-logrotate + - docker-selinux + - docker-engine-selinux + - docker-engine + {%- for pkgname in docker.pkgs %} + - {{ pkgname }} + {%- endfor %} + +{# remove pip packages installed by formula #} + +docker-pips-removed: + pip.removed: + - onlyif: python -m pip --version >/dev/null 2>&1 + - names: + {% if docker.compose_version -%} + - docker-compose == {{ docker.compose_version }} + {% else -%} + - docker-compose + {% endif -%} + {% if docker.install_docker_py -%} + {% if "python_package" in docker -%} + - {{ docker.python_package }} + {% elif "pip_version" in docker -%} + - docker-py {{ docker.pip_version }} + {% else -%} + - docker-py + {%- endif -%} + {% endif %} + {%- if docker.proxy %} + - proxy: {{ docker.proxy }} + {%- endif %} diff --git a/docker/codenamemap.yaml b/docker/codenamemap.yaml index 714cf862..0620a7ef 100644 --- a/docker/codenamemap.yaml +++ b/docker/codenamemap.yaml @@ -1,5 +1,6 @@ -# vim: sts=2 ts=2 sw=2 et ai - +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- wheezy: kernel: pkg: @@ -33,4 +34,3 @@ precise: pkgs: - linux-image-generic-lts-raring - linux-headers-generic-lts-raring - diff --git a/docker/compose-ng.sls b/docker/compose-ng.sls index e7f3c756..d1d64a5c 100644 --- a/docker/compose-ng.sls +++ b/docker/compose-ng.sls @@ -1,5 +1,7 @@ -{%- from "docker/map.jinja" import docker with context %} -{%- from "docker/map.jinja" import compose with context %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} +{%- from tplroot ~ "/map.jinja" import compose with context %} include: - docker.compose @@ -8,22 +10,22 @@ include: {%- set id = container.container_name|d(name) %} {%- set required_containers = [] %} {%- if grains['saltversioninfo'] >= [2017, 7, 0] %} -{{id}}: +{{ id }}: docker_image.present: - force: {{ docker.containers.force_present }} {%- else %} -{{id}} image: +{{ id }} image: docker.pulled: {%- endif %} {%- if ':' in container.image %} {%- set image = container.image.split(':',1) %} - - name: {{image[0]}} - - tag: {{image[1]}} + - name: {{ image[0] }} + - tag: {{ image[1] }} {%- else %} - - name: {{container.image}} + - name: {{ container.image }} {%- endif %} -{{id}} container: +{{ id }} container: {%- if grains['saltversioninfo'] >= [2017, 7, 0] %} docker_container.running: - skip_translate: {{ docker.containers.skip_translate }} @@ -35,15 +37,15 @@ include: docker.running: {%- endif %} {%- endif %} - - name: {{id}} - - image: {{container.image}} + - name: {{ id }} + - image: {{ container.image }} {%- if 'command' in container %} - - command: {{container.command}} + - command: {{ container.command }} {%- endif %} {%- if 'environment' in container and container.environment is iterable %} - environment: {%- for variable, value in container.environment.items() %} - - {{variable}}: {{value}} + - {{ variable }}: {{ value }} {%- endfor %} {%- endif %} {%- if 'ports' in container and container.ports is iterable %} @@ -52,28 +54,28 @@ include: {%- if port_mapping is string %} {%- set mapping = port_mapping.split(':',2) %} {%- if mapping|length < 2 %} - - "{{mapping[0]}}" + - "{{ mapping[0] }}" {%- else %} - - "{{mapping[-1]}}/tcp": - HostPort: "{{mapping[-2]}}" - HostIp: "{{mapping[-3]|d('')}}" + - "{{ mapping[-1] }}/tcp": + HostPort: "{{ mapping[-2] }}" + HostIp: "{{ mapping[-3]|d('') }}" {%- endif %} {%- elif port_mapping is mapping %} - - {{port_mapping}} + - {{ port_mapping }} {%- endif %} {%- endfor %} {%- endif %} {%- if 'volumes' in container %} - volumes: {%- for volume in container.volumes %} - - {{volume}} + - {{ volume }} {%- endfor %} {%- endif %} {%- if 'volumes_from' in container %} - volumes_from: {%- for volume in container.volumes_from %} {%- do required_containers.append(volume) %} - - {{volume}} + - {{ volume }} {%- endfor %} {%- endif %} {%- if 'links' in container %} @@ -81,29 +83,29 @@ include: {%- for link in container.links %} {%- set name, alias = link.split(':',1) %} {%- do required_containers.append(name) %} - {{name}}: {{alias}} + {{ name }}: {{ alias }} {%- endfor %} {%- endif %} {%- if 'restart' in container %} - restart_policy: {%- set policy = container.restart.split(':',1) %} - Name: {{policy[0]}} + Name: {{ policy[0] }} {%- if policy|length > 1 %} - MaximumRetryCount: {{policy[1]}} + MaximumRetryCount: {{ policy[1] }} {%- endif %} {%- endif %} - require: {%- if grains['saltversioninfo'] >= [2017, 7, 0] %} - - docker_image: {{id}} + - docker_image: {{ id }} {%- else %} - - docker: {{id}} image + - docker: {{ id }} image {%- endif %} {%- if required_containers is defined %} {%- for containerid in required_containers %} {%- if grains['saltversioninfo'] >= [2017, 7, 0] %} - - docker_image: {{containerid}} + - docker_image: {{ containerid }} {%- else %} - - docker: {{containerid}} + - docker: {{ containerid }} {%- endif %} {%- endfor %} {%- endif %} diff --git a/docker/compose.sls b/docker/compose.sls index 3aea9fc0..4f173c19 100644 --- a/docker/compose.sls +++ b/docker/compose.sls @@ -1,4 +1,6 @@ -{% from "docker/map.jinja" import docker with context %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} include: - docker @@ -9,7 +11,7 @@ docker-compose: - name: /usr/bin/pip install docker-compose {%- else %} pip.installed: - {%- if docker.compose_version %} + {%- if 'compose_version' in docker and docker.compose_version %} - name: docker-compose == {{ docker.compose_version }} {%- else %} - name: docker-compose diff --git a/docker/containers.sls b/docker/containers.sls index 6f103522..e0e7b94a 100644 --- a/docker/containers.sls +++ b/docker/containers.sls @@ -1,4 +1,6 @@ -{% from "docker/map.jinja" import containers with context %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import containers with context %} include: - docker diff --git a/docker/defaults.yaml b/docker/defaults.yaml index d7776a45..84a9ec3b 100644 --- a/docker/defaults.yaml +++ b/docker/defaults.yaml @@ -1,45 +1,46 @@ -# vim: sts=2 ts=2 sw=2 et ai - +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- docker: process_signature: '/usr/bin/docker' - install_docker_py: True + install_docker_py: true python_package: docker - refresh_repo: True + refresh_repo: true configfile: /etc/default/docker config: [] daemon_config: {} version: '' + rootuser: root - use_upstream_repo: True - use_old_repo: False - proxy: False + use_upstream_repo: true + use_old_repo: false + proxy: false pkgs: - iptables - ca-certificates - - python-docker pkg: name: docker-ce old_name: docker-engine # For backward compatibility, this will be overriden by docker:version, if defined version: latest - allow_updates: False - hold: False + allow_updates: false + hold: false + use_upstream_app: false # macos pip: - install_pypi_pip: False - upgrade: False + install_pypi_pip: false + upgrade: false compose_version: '' containers: skip_translate: None - force_present: False - force_running: False + force_present: false + force_running: false kernel: pkg: fromrepo: '' pkgs: [] - diff --git a/docker/files/config b/docker/files/config index b2eed115..d84dca4b 100644 --- a/docker/files/config +++ b/docker/files/config @@ -1,6 +1,3 @@ -{% from "docker/map.jinja" import docker with context %} - - # Docker Upstart and SysVinit configuration file # @@ -22,6 +19,6 @@ # This is also a handy place to tweak where Docker's temporary files go. #export TMPDIR="/mnt/bigdrive/docker-tmp" -{% for line in docker.get("config", []) %} +{% for line in config %} {{ line }} {% endfor %} diff --git a/docker/files/service_file.jinja b/docker/files/service_file.jinja index cc5b8136..c30c0318 100644 --- a/docker/files/service_file.jinja +++ b/docker/files/service_file.jinja @@ -8,6 +8,7 @@ {%- set stopoptions = stopoptions|join(' ') %} {%- set args = args|join(' ') %} +{%- set docker_prestart_remove_command = "rm -f %s"|format(name) %} {%- set docker_start_command = "run %s --name=%s %s %s %s"|format(runoptions, name, container.image, cmd, args) %} {%- set docker_stop_command = "stop %s %s"|format(stopoptions, name) %} {%- set docker_poststop_command = "rm -f %s"|format(name) %} @@ -16,4 +17,4 @@ {%- include 'docker/files/systemd.conf' %} {%- elif grains['init'] == 'upstart' %} {%- include 'docker/files/upstart.conf' %} -{%- endif %} \ No newline at end of file +{%- endif %} diff --git a/docker/files/systemd.conf b/docker/files/systemd.conf index 7ee89449..587ebae1 100644 --- a/docker/files/systemd.conf +++ b/docker/files/systemd.conf @@ -5,6 +5,7 @@ After=docker.service {%- set remove_on_stop = container.get("remove_on_stop", False) %} {%- set pull_before_start = container.get("pull_before_start") or False %} +{%- set remove_before_start = container.get("remove_before_start") or False %} [Service] Restart=always @@ -12,6 +13,9 @@ Restart=always ExecStartPre=/usr/bin/docker pull {{ container.image }} {%- endif %} +{%- if remove_before_start %} +ExecStartPre=-/usr/bin/docker {{ docker_prestart_remove_command }} +{%- endif %} ExecStart=/usr/bin/docker {{ docker_start_command }} ExecStop=/usr/bin/docker {{ docker_stop_command }} {%- if remove_on_stop %} diff --git a/docker/files/upstart.conf b/docker/files/upstart.conf index a5da4474..defd6868 100644 --- a/docker/files/upstart.conf +++ b/docker/files/upstart.conf @@ -11,10 +11,17 @@ respawn {%- set cmd = container.get("cmd", "") %} {%- set pull_before_start = container.get("pull_before_start") or False %} +{%- set remove_before_start = container.get("remove_before_start") or False %} -{%- if pull_before_start %} +{%- if pull_before_start or remove_before_start -%} pre-start script +{%- if pull_before_start %} /usr/bin/docker pull {{ container.image }} +{%- endif %} + +{%- if remove_before_start %} + /usr/bin/docker rm -f {{ name }} +{%- endif %} end script {%- endif %} diff --git a/docker/files/upstart.conf.deprecated.registry b/docker/files/upstart.conf.deprecated.registry index 1c057804..65f495c6 100644 --- a/docker/files/upstart.conf.deprecated.registry +++ b/docker/files/upstart.conf.deprecated.registry @@ -1,5 +1,7 @@ -{% from "docker/map.jinja" import registry with context %} -{% from "docker/map.jinja" import amazon with context %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import registry with context %} +{%- from tplroot ~ "/map.jinja" import amazon with context %} description "{{ registry.description }}" start on runlevel [2345] diff --git a/docker/init.sls b/docker/init.sls index 1c733e1a..e32220e2 100644 --- a/docker/init.sls +++ b/docker/init.sls @@ -1,110 +1,10 @@ -{% from "docker/map.jinja" import docker with context %} - -{%- set docker_pkg_name = docker.pkg.old_name if docker.use_old_repo else docker.pkg.name %} -{%- set docker_pkg_version = docker.version | default(docker.pkg.version) %} -{%- set docker_packages = docker.kernel.pkgs + docker.pkgs %} +# -*- coding: utf-8 -*- +# vim: ft=sls +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} +{%- set sls_package_install = tplroot ~ '.install' %} +{%- set sls_macapp_install = tplroot ~ '.macosapp' %} include: - - .kernel - - .repo - -docker-package-dependencies: - pkg.installed: - - pkgs: - {%- for pkgname in docker_packages %} - - {{ pkgname }} - {%- endfor %} - {%- if "pip" in docker and "pkgname" in docker.pip %} - - {{ docker.pip.pkgname }} - {%- endif %} - - unless: test "`uname`" = "Darwin" - - refresh: {{ docker.refresh_repo }} - -docker-package: - pkg.installed: - - name: {{ docker_pkg_name }} - - version: {{ docker_pkg_version or 'latest' }} - - refresh: {{ docker.refresh_repo }} - - require: - - pkg: docker-package-dependencies - {%- if grains['os']|lower not in ('amazon', 'fedora', 'suse',) %} - - pkgrepo: docker-package-repository - {%- endif %} - - require_in: - - file: docker-config - {%- if grains.os_family in ('Suse',) %} ##workaround https://github.com/saltstack-formulas/docker-formula/issues/198 - cmd.run: - - name: /usr/bin/pip install {{ '--upgrade' if docker.pip.upgrade else '' }} pip - {%- else %} - pip.installed: - - name: pip - - reload_modules: true - - upgrade: {{ docker.pip.upgrade }} - {%- endif %} - - onlyif: {{ docker.pip.install_pypi_pip }} #### onlyif you really need pypi pip instead of using official distro pip. - - require: - - pkg: docker-package-dependencies - -docker-config: - file.managed: - - name: {{ docker.configfile }} - - source: salt://docker/files/config - - template: jinja - - mode: 644 - - user: root - - {% if docker.daemon_config %} -docker-daemon-dir: - file.directory: - - name: /etc/docker - - user: root - - group: root - - mode: 755 - -docker-daemon-config: - file.serialize: - - name: /etc/docker/daemon.json - - user: root - - group: root - - mode: 644 - - dataset: - {{ docker.daemon_config | yaml() | indent(8) }} - - formatter: json - {% endif %} - -docker-service: - service.running: - - name: docker - - enable: True - - watch: - - file: docker-config - - pkg: docker-package - {% if docker.daemon_config %} - - file: docker-daemon-config - {% endif %} - {% if "process_signature" in docker %} - - sig: {{ docker.process_signature }} - {% endif %} - -{% if docker.install_docker_py %} -docker-py: - {%- if grains.os_family in ('Suse',) %} ##workaround https://github.com/saltstack-formulas/docker-formula/issues/198 - cmd.run: - - name: /usr/bin/pip install {{ docker.python_package }} - {%- else %} - pip.installed: - {%- if "python_package" in docker %} - - name: {{ docker.python_package }} - {%- elif "pip_version" in docker %} - - name: docker-py {{ docker.pip_version }} - {%- else %} - - name: docker-py - {%- endif %} - - reload_modules: true - {%- if docker.proxy %} - - proxy: {{ docker.proxy }} - {%- endif %} - - require: - - pkg: docker-package-dependencies - {%- endif %} -{% endif %} + - {{ sls_package_install if not docker.pkg.use_upstream_app else sls_macapp_install }} diff --git a/docker/install.sls b/docker/install.sls new file mode 100644 index 00000000..6590a41b --- /dev/null +++ b/docker/install.sls @@ -0,0 +1,134 @@ +{% from "docker/map.jinja" import docker with context %} + +{%- set docker_pkg_name = docker.pkg.old_name if docker.use_old_repo else docker.pkg.name %} +{%- set docker_pkg_version = docker.version | default(docker.pkg.version) %} +{%- set docker_packages = docker.kernel.pkgs + docker.pkgs %} + +include: + - .kernel + - .repo + +docker-package-dependencies: + pkg.installed: + - pkgs: + {%- for pkgname in docker_packages %} + - {{ pkgname }} + {%- endfor %} + {%- if "pip" in docker and "pkgname" in docker.pip %} + - {{ docker.pip.pkgname }} + {%- endif %} + - unless: test "`uname`" = "Darwin" + - refresh: {{ docker.refresh_repo }} + +docker-package: + pkg.installed: + - name: {{ docker_pkg_name }} + - version: {{ docker_pkg_version or 'latest' }} + - refresh: {{ docker.refresh_repo }} + - require: + - pkg: docker-package-dependencies + {%- if grains['os']|lower not in ('amazon', 'fedora', 'suse',) %} + - pkgrepo: docker-package-repository + {%- endif %} + {%- if grains['os']|lower not in ('suse',) %} + - allow_updates: {{ docker.pkg.allow_updates }} + - hold: {{ docker.pkg.hold }} + {%- endif %} + {%- if grains.os_family in ('Suse',) %} ##workaround https://github.com/saltstack-formulas/docker-formula/issues/198 + cmd.run: + - name: /usr/bin/pip install {{ '--upgrade' if docker.pip.upgrade else '' }} pip + {%- elif docker.pip.install_pypi_pip %} ##onlyif you really need pypi pip instead of using official distro pip + pip.installed: + - name: pip + - reload_modules: true + - upgrade: {{ docker.pip.upgrade }} + {%- endif %} + - require: + - pkg: docker-package-dependencies + + {%- if grains.os != 'MacOS' %} +docker-config: + file.managed: + - name: {{ docker.configfile }} + - source: salt://docker/files/config + - template: jinja + - mode: 644 + - user: root + - context: + config: {{ docker.config | json }} + - require: + - pkg: docker-package + - watch_in: + - service: docker-service + {%- endif %} + + {% if docker.daemon_config %} +docker-daemon-dir: + file.directory: + - name: /etc/docker + - user: root + - group: root + - mode: 755 + +docker-daemon-config: + file.serialize: + - name: /etc/docker/daemon.json + - user: root + - group: root + - mode: 644 + - dataset: + {{ docker.daemon_config | yaml() | indent(8) }} + - formatter: json + {% endif %} + +docker-service: + service.running: + - name: docker + - enable: True + - watch: + - pkg: docker-package + {% if docker.daemon_config %} + - file: docker-daemon-config + {% endif %} + {% if "process_signature" in docker %} + - sig: {{ docker.process_signature }} + {% endif %} + +docker-install-docker-service-not-running-notify: + test.show_notification: + - text: | + In certain circumstances the docker service will not start. + Your kernel is missing some modules, or not in ideal state. + See https://github.com/moby/moby/blob/master/contrib/check-config.sh + Rebooting your host may fix docker service failure! + - onfail: + - service: docker-service + - unless: {{ grains.os_family in ('MacOS', 'Windows') }} #maybe not needed? + service.enabled: + - name: docker + - onfail: + - service: docker-service + - unless: {{ grains.os_family in ('MacOS', 'Windows') }} #maybe not needed? + +{% if docker.install_docker_py %} +docker-py: + {%- if grains.os_family in ('Suse',) %} ##workaround https://github.com/saltstack-formulas/docker-formula/issues/198 + cmd.run: + - name: /usr/bin/pip install {{ docker.python_package }} + {%- else %} + pip.installed: + {%- if "python_package" in docker and docker.python_package %} + - name: {{ docker.python_package }} + {%- elif "pip_version" in docker and docker.pip_version %} + - name: docker-py {{ docker.pip_version }} + {%- else %} + - name: docker-py + {%- endif %} + - reload_modules: true + {%- if docker.proxy %} + - proxy: {{ docker.proxy }} + {%- endif %} + - require: + - pkg: docker-package-dependencies + {%- endif %} +{% endif %} diff --git a/docker/kernel.sls b/docker/kernel.sls index 4e7d8164..9f6c467f 100644 --- a/docker/kernel.sls +++ b/docker/kernel.sls @@ -1,4 +1,6 @@ -{% from "docker/map.jinja" import docker with context %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} {%- if docker.kernel is defined and grains['os_family']|lower == 'debian' %} pkgrepo-dependencies: @@ -6,7 +8,7 @@ pkgrepo-dependencies: - name: python-apt {% if "pkgrepo" in docker.kernel %} -{{ grains["oscodename"] }}-backports-repo: +{{ grains["oscodename"]|lower }}-backports-repo: pkgrepo.managed: {% for key, value in docker.kernel.pkgrepo.items() %} - {{ key }}: {{ value }} diff --git a/docker/macosapp/init.sls b/docker/macosapp/init.sls new file mode 100644 index 00000000..b16d0683 --- /dev/null +++ b/docker/macosapp/init.sls @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} +{%- set sls_package_install = tplroot ~ '.install' %} +{%- set sls_macapp_install = tplroot ~ '.macosapp.install' %} + +include: + - {{ sls_macapp_install if docker.pkg.use_upstream_app else sls_package_install }} diff --git a/docker/macosapp/install.sls b/docker/macosapp/install.sls new file mode 100644 index 00000000..ce5a5d3d --- /dev/null +++ b/docker/macosapp/install.sls @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} + + {%- if grains.os == 'MacOS' %} + +docker-macos-app-install-file-directory: + file.directory: + - name: /tmp/salt-docker-formula + - makedirs: True + - require_in: + - pkg: docker-macos-app-install-cmd-run + - cmd: docker-macos-app-install-cmd-run + +docker-macos-app-install-cmd-run: + pkg.installed: + - name: curl + cmd.run: + - name: curl -Lo /tmp/salt-docker-formula/{{ docker.pkg.app.name }} {{ docker.pkg.app.source }} + - unless: test -f /tmp/salt-docker-formula/{{ docker.pkg.app.name }} + - retry: + attempts: 3 + interval: 60 + until: True + splay: 10 + + {%- if docker.pkg.app.source_hash %} + +docker-macos-app-install-app-hash-module-run: + module.run: + - name: file.check_hash + - path: /tmp/salt-docker-formula/{{ docker.pkg.app.name }} + - file_hash: {{ docker.pkg.app.source_hash }} + - require: + - cmd: docker-macos-app-install-cmd-run + - require_in: + - macpackage: docker-macos-app-install-macpackage-installed + + {%- endif %} + +docker-macos-app-install-macpackage-installed: + macpackage.installed: + - name: /tmp/salt-docker-formula/{{ docker.pkg.app.name }} + - store: True + - dmg: True + - app: True + - force: True + - allow_untrusted: True + - onchanges: + - cmd: docker-macos-app-install-cmd-run + file.append: + - name: /Users/{{ docker.rootuser }}/.bash_profile + - text: 'export PATH=$PATH:/Applications/Docker.app/Contents/Versions/latest/bin' + - require: + - macpackage: docker-macos-app-install-macpackage-installed + + {%- endif %} diff --git a/docker/map.jinja b/docker/map.jinja index f1f39fa4..16c6b136 100644 --- a/docker/map.jinja +++ b/docker/map.jinja @@ -23,14 +23,17 @@ }, }, merge=salt['pillar.get']('registry:lookup:amazon')) %} -# Begin migration to new style map.jinja -{% import_yaml "docker/defaults.yaml" as defaults %} -{% import_yaml 'docker/osfamilymap.yaml' as osfamilymap %} -{% import_yaml "docker/codenamemap.yaml" as codemap %} -{% import_yaml "docker/osmap.yaml" as osmap %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} + +{# Begin migration to new style map.jinja using tplroot for portability #} +{% import_yaml tplroot ~ "/defaults.yaml" or {} as defaults %} +{% import_yaml tplroot ~ "/osfamilymap.yaml" or {} as osfamilymap %} +{% import_yaml tplroot ~ "/codenamemap.yaml" or {} as codemap %} +{% import_yaml tplroot ~ "/osmap.yaml" or {} as osmap %} {% set pkg = salt['pillar.get']('docker-pkg:lookup', default={}, merge=True) %} -{% do defaults.docker.update(pkg) %} +{% do defaults.docker.pkg.update(pkg) %} {% set osfamily = salt['grains.filter_by'](osfamilymap, grain='os_family') or {} %} {% do defaults.docker.update(osfamily) %} diff --git a/docker/osfamilymap.yaml b/docker/osfamilymap.yaml index 281c3cd2..e33b8a48 100644 --- a/docker/osfamilymap.yaml +++ b/docker/osfamilymap.yaml @@ -1,26 +1,76 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +# +# Setup variables using grains['os_family'] based logic. +# You just need to add the key:values for an `os_family` that differ +# from `defaults.yaml`. +# Only add an `os_family` which is/will be supported by the formula +# +# If you do not need to provide defaults via the `os_family` grain, +# you will need to provide at least an empty dict in this file, e.g. +# osfamilymap: {} +--- +{%- if grains.os == 'MacOS' %} + {% set macos_user = salt['cmd.run']("stat -f '%Su' /dev/console") %} +{%- endif %} + +Arch: + python_package: ~ + pkgs: + - python-docker + - python-pip + - python2-pip # see https://github.com/saltstack/salt/issues/48632 + pkg: + name: docker + # workaround https://github.com/saltstack-formulas/docker-formula/issues/219 + allow_updates: false + hold: false + use_upstream_app: false + pip: + install_pypi_pip: false + upgrade: false + Debian: pkgs: - apt-transport-https - - python-apt - - python-pip + - python3-apt + - python3-pip + - python3-docker repo: url_base: https://download.docker.com/linux/{{ grains['os'] |lower }} key_url: https://download.docker.com/linux/{{ grains['os'] |lower }}/gpg - version: {{ grains['oscodename'] |lower }} + version: {{ grains['oscodename']|lower if 'oscodename' in grains else '' }} file: /etc/apt/sources.list.d/docker.list RedHat: pkgs: - - python2-pip + - python3-pip + - python3-docker repo: - url_base: https://download.docker.com/linux/{{ grains['os'] |lower }}/{{ grains['osmajorrelease'] }}/$basearch/stable/ + # yamllint disable-line rule:line-length + url_base: https://download.docker.com/linux/{{ grains['os'] |lower }}/{{ '' if not 'osmajorrelease' in grains else grains['osmajorrelease'] }}/$basearch/stable/ key_url: https://download.docker.com/linux/{{ grains['os'] |lower }}/gpg - version: {{ grains['oscodename'] |lower }} + version: {{ grains['oscodename']|lower if 'oscodename' in grains else '' }} file: /etc/yum.repos.d/docker-ce.repo Suse: pkg: name: docker pkgs: - - python3-pip #python 3 is default on OpenSUSE 15.0 + - python3-pip + - python3-docker +MacOS: + rootuser: {{ macos_user | d('') }} + pkgs: + - python3-docker + pkg: + name: docker #homebrew + # workaround https://github.com/saltstack-formulas/docker-formula/issues/219 + allow_updates: false + hold: false + use_upstream_app: true #docker desktop for mac + app: + name: Docker + source: https://download.docker.com/mac/stable/Docker.dmg + source_hash: a55462f153284ff212f8857945a69d4e128afb6753f5572984877f7b6fc3fc25 diff --git a/docker/osmap.yaml b/docker/osmap.yaml index 4a9e1c1d..b522db41 100644 --- a/docker/osmap.yaml +++ b/docker/osmap.yaml @@ -1,4 +1,6 @@ - +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- CentOS: pkgs: - python2-pip @@ -6,5 +8,3 @@ CentOS: FreeBSD: pkgs: - devel/py-pip - -# vim: ft=sls diff --git a/docker/registry.sls b/docker/registry.sls index 5477c83e..f670c4c1 100644 --- a/docker/registry.sls +++ b/docker/registry.sls @@ -1,4 +1,6 @@ -{% from "docker/map.jinja" import registry with context %} +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} file-registry-upstart-conf: file.managed: diff --git a/docker/remove.sls b/docker/remove.sls index 8bd08f03..46b87123 100644 --- a/docker/remove.sls +++ b/docker/remove.sls @@ -1,54 +1,8 @@ -{% from "docker/map.jinja" import docker with context %} - -docker-packages-cleaned-service-dead: - service.dead: - - name: docker - {% if "process_signature" in docker %} - - sig: {{ docker.process_signature }} - - onlyif: ps -ef | grep "{{ docker.process_signature }}" ##stop stderr from sig - {% endif %} - - require_in: - - pkg: docker-packages-cleaned - -docker-packages-cleaned: - pkg.removed: - - pkgs: - - {{ docker.pkg.old_name if docker.use_old_repo else docker.pkg.name }} - - docker - - docker.io - - docker-client - - docker-client-latest - - docker-common - - docker-latest - - docker-latest-logrotate - - docker-logrotate - - docker-selinux - - docker-engine-selinux - - docker-engine - {%- for pkgname in docker.pkgs %} - - {{ pkgname }} - {%- endfor %} - -{# remove pip packages installed by formula #} - -docker-pips-removed: - pip.removed: - - onlyif: python -m pip --version >/dev/null 2>&1 - - names: - {% if docker.compose_version -%} - - docker-compose == {{ docker.compose_version }} - {% else -%} - - docker-compose - {% endif -%} - {% if docker.install_docker_py -%} - {% if "python_package" in docker -%} - - {{ docker.python_package }} - {% elif "pip_version" in docker -%} - - docker-py {{ docker.pip_version }} - {% else -%} - - docker-py - {%- endif -%} - {% endif %} - {%- if docker.proxy %} - - proxy: {{ docker.proxy }} - {%- endif %} +# -*- coding: utf-8 -*- +# vim: ft=sls +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} + +include: + - clean diff --git a/docker/repo.sls b/docker/repo.sls index 61a84f26..5ed8bda7 100644 --- a/docker/repo.sls +++ b/docker/repo.sls @@ -1,4 +1,7 @@ -{% from "docker/map.jinja" import docker with context %} + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import docker with context %} {% set repo_state = 'absent' %} {% if docker.use_upstream_repo or docker.use_old_repo %} @@ -13,7 +16,7 @@ docker-package-repository: pkgrepo.{{ repo_state }}: - humanname: {{ grains["os"] }} {{ grains["oscodename"]|capitalize }} {{ humanname_old }}Docker Package Repository - - name: deb {{ url }} + - name: deb [arch={{ grains["osarch"] }}] {{ url }} - file: {{ docker.repo.file }} {% if docker.use_old_repo %} - keyserver: keyserver.ubuntu.com @@ -21,7 +24,11 @@ docker-package-repository: {% else %} - key_url: {{ docker.repo.key_url }} {% endif %} + {%- if grains['saltversioninfo'] >= [2018, 3, 0] %} + - refresh: True + {%- else %} - refresh_db: True + {%- endif %} - require_in: - pkg: docker-package - require: diff --git a/docs/AUTHORS.rst b/docs/AUTHORS.rst new file mode 100644 index 00000000..3a529bf6 --- /dev/null +++ b/docs/AUTHORS.rst @@ -0,0 +1,170 @@ +.. role:: raw-html-m2r(raw) + :format: html + + +Authors +======= + +This list is sorted by the number of commits per contributor in *descending* order. + +.. list-table:: + :header-rows: 1 + + * - Avatar + - Contributor + - Contributions + * - :raw-html-m2r:`@noelmcloughlin` + - `@noelmcloughlin `_ + - 86 + * - :raw-html-m2r:`@cdarwin` + - `@cdarwin `_ + - 25 + * - :raw-html-m2r:`@myii` + - `@myii `_ + - 25 + * - :raw-html-m2r:`@gravyboat` + - `@gravyboat `_ + - 22 + * - :raw-html-m2r:`@aboe76` + - `@aboe76 `_ + - 21 + * - :raw-html-m2r:`@javierbertoli` + - `@javierbertoli `_ + - 18 + * - :raw-html-m2r:`@puneetk` + - `@puneetk `_ + - 15 + * - :raw-html-m2r:`@vladvasiliu` + - `@vladvasiliu `_ + - 12 + * - :raw-html-m2r:`@nmadhok` + - `@nmadhok `_ + - 9 + * - :raw-html-m2r:`@ticosax` + - `@ticosax `_ + - 7 + * - :raw-html-m2r:`@alexproca` + - `@alexproca `_ + - 6 + * - :raw-html-m2r:`@blbradley` + - `@blbradley `_ + - 6 + * - :raw-html-m2r:`@whiteinge` + - `@whiteinge `_ + - 6 + * - :raw-html-m2r:`@toopy` + - `@toopy `_ + - 5 + * - :raw-html-m2r:`@VBH-Jenkins` + - `@VBH-Jenkins `_ + - 5 + * - :raw-html-m2r:`@babilen5` + - `@babilen5 `_ + - 3 + * - :raw-html-m2r:`@techhat` + - `@techhat `_ + - 2 + * - :raw-html-m2r:`@msciciel` + - `@msciciel `_ + - 2 + * - :raw-html-m2r:`@mingfang` + - `@mingfang `_ + - 2 + * - :raw-html-m2r:`@Poil` + - `@Poil `_ + - 2 + * - :raw-html-m2r:`@stamak` + - `@stamak `_ + - 2 + * - :raw-html-m2r:`@tedski` + - `@tedski `_ + - 2 + * - :raw-html-m2r:`@tyhunt99` + - `@tyhunt99 `_ + - 2 + * - :raw-html-m2r:`@DavidJFelix` + - `@DavidJFelix `_ + - 2 + * - :raw-html-m2r:`@scornelissen85` + - `@scornelissen85 `_ + - 2 + * - :raw-html-m2r:`@alxwr` + - `@alxwr `_ + - 1 + * - :raw-html-m2r:`@alinefr` + - `@alinefr `_ + - 1 + * - :raw-html-m2r:`@ernstae` + - `@ernstae `_ + - 1 + * - :raw-html-m2r:`@iggy` + - `@iggy `_ + - 1 + * - :raw-html-m2r:`@solarchad` + - `@solarchad `_ + - 1 + * - :raw-html-m2r:`@blueyed` + - `@blueyed `_ + - 1 + * - :raw-html-m2r:`@comozo` + - `@comozo `_ + - 1 + * - :raw-html-m2r:`@JohnMaguire` + - `@JohnMaguire `_ + - 1 + * - :raw-html-m2r:`@jstjohn` + - `@jstjohn `_ + - 1 + * - :raw-html-m2r:`@jfrederickson` + - `@jfrederickson `_ + - 1 + * - :raw-html-m2r:`@y2kenny` + - `@y2kenny `_ + - 1 + * - :raw-html-m2r:`@LarsFronius` + - `@LarsFronius `_ + - 1 + * - :raw-html-m2r:`@xenophonf` + - `@xenophonf `_ + - 1 + * - :raw-html-m2r:`@MrDiba` + - `@MrDiba `_ + - 1 + * - :raw-html-m2r:`@pwaller` + - `@pwaller `_ + - 1 + * - :raw-html-m2r:`@syndicut` + - `@syndicut `_ + - 1 + * - :raw-html-m2r:`@rgreinho` + - `@rgreinho `_ + - 1 + * - :raw-html-m2r:`@toanju` + - `@toanju `_ + - 1 + * - :raw-html-m2r:`@tobias-m` + - `@tobias-m `_ + - 1 + * - :raw-html-m2r:`@ghostsquad` + - `@ghostsquad `_ + - 1 + * - :raw-html-m2r:`@greut` + - `@greut `_ + - 1 + * - :raw-html-m2r:`@myoung34` + - `@myoung34 `_ + - 1 + * - :raw-html-m2r:`@norrland` + - `@norrland `_ + - 1 + * - :raw-html-m2r:`@oonska` + - `@oonska `_ + - 1 + * - :raw-html-m2r:`@tiadobatima` + - `@tiadobatima `_ + - 1 + + +---- + +Auto-generated by a `forked version `_ of `gaocegege/maintainer `_ on 2020-01-22. diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst new file mode 100644 index 00000000..8def36ca --- /dev/null +++ b/docs/CHANGELOG.rst @@ -0,0 +1,74 @@ + +Changelog +========= + +`0.43.0 `_ (2020-01-22) +----------------------------------------------------------------------------------------------------------- + +Bug Fixes +^^^^^^^^^ + + +* **release.config.js:** use full commit hash in commit link [skip ci] (\ `01ece3d `_\ ) + +Continuous Integration +^^^^^^^^^^^^^^^^^^^^^^ + + +* **gemfile:** restrict ``train`` gem version until upstream fix [skip ci] (\ `734d4e3 `_\ ) +* **kitchen:** use ``debian-10-master-py3`` instead of ``develop`` [skip ci] (\ `d87e787 `_\ ) +* **kitchen:** use ``develop`` image until ``master`` is ready (\ ``amazonlinux``\ ) [skip ci] (\ `71c5bcb `_\ ) +* **kitchen+travis:** upgrade matrix after ``2019.2.2`` release [skip ci] (\ `2189efb `_\ ) +* **travis:** apply changes from build config validation [skip ci] (\ `f0a07fc `_\ ) +* **travis:** opt-in to ``dpl v2`` to complete build config validation [skip ci] (\ `340556e `_\ ) +* **travis:** quote pathspecs used with ``git ls-files`` [skip ci] (\ `12bf914 `_\ ) +* **travis:** run ``shellcheck`` during lint job [skip ci] (\ `ba127a0 `_\ ) +* **travis:** use ``major.minor`` for ``semantic-release`` version [skip ci] (\ `2590d61 `_\ ) +* **travis:** use build config validation (beta) [skip ci] (\ `fe184e9 `_\ ) + +Features +^^^^^^^^ + + +* support optional container removal before start in upstart/systemd (\ `cc10d97 `_\ ) + +Performance Improvements +^^^^^^^^^^^^^^^^^^^^^^^^ + + +* **travis:** improve ``salt-lint`` invocation [skip ci] (\ `18fa798 `_\ ) + +`0.42.0 `_ (2019-10-23) +----------------------------------------------------------------------------------------------------------- + +Bug Fixes +^^^^^^^^^ + + +* **compose-ng.sls:** fix ``salt-lint`` errors (\ ` `_\ ) +* **pillar.example:** ensure ``docker.config`` is available (\ ` `_\ ) + +Continuous Integration +^^^^^^^^^^^^^^^^^^^^^^ + + +* **travis:** update ``salt-lint`` config for ``v0.0.10`` (\ ` `_\ ) + +Documentation +^^^^^^^^^^^^^ + + +* **readme:** move to ``docs/`` directory and modify accordingly (\ ` `_\ ) + +Features +^^^^^^^^ + + +* **semantic-release:** implement for this formula (\ ` `_\ ) + +Tests +^^^^^ + + +* **inspec:** add tests for package, config & service (\ ` `_\ ) +* **testinfra:** remove from the formula (\ ` `_\ ) diff --git a/README.rst b/docs/README.rst similarity index 70% rename from README.rst rename to docs/README.rst index d5628f3c..0046062b 100644 --- a/README.rst +++ b/docs/README.rst @@ -1,22 +1,52 @@ -====== +.. _readme: + Docker ====== +|img_travis| |img_sr| + +.. |img_travis| image:: https://travis-ci.com/saltstack-formulas/docker-formula.svg?branch=master + :alt: Travis CI Build Status + :scale: 100% + :target: https://travis-ci.com/saltstack-formulas/docker-formula +.. |img_sr| image:: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg + :alt: Semantic Release + :scale: 100% + :target: https://github.com/semantic-release/semantic-release + Formulas for working with Docker -.. note:: +.. contents:: **Table of Contents** + +General notes +------------- + +See the full `SaltStack Formulas installation and usage instructions +`_. + +If you are interested in writing or contributing to formulas, please pay attention to the `Writing Formula Section +`_. - See the full `Salt Formulas installation and usage instructions - `_. +If you want to use this formula, please pay attention to the ``FORMULA`` file and/or ``git tag``, +which contains the currently released version. This formula is versioned according to `Semantic Versioning `_. + +See `Formula Versioning Section `_ for more details. + +Contributing to this repo +------------------------- + +**Commit message formatting is significant!!** + +Please see `How to contribute `_ for more details. Available states -================ +---------------- .. contents:: :local: ``docker`` ----------- +^^^^^^^^^^ Install and run Docker daemon @@ -30,7 +60,7 @@ Install and run Docker daemon ``docker.containers`` ---------------------- +^^^^^^^^^^^^^^^^^^^^^ Pulls and runs a number of docker containers with arbitrary *run* options all configurable via pillars. Salt includes *dockerio* and *dockerng* states, but both depend on *docker-py* library, which not always implements the latest *docker run* options. This gives the user more control over the docker run options, but it doesn't try to implement all the other docker commands, such as build, ps, inspect, etc. It just pulls an image and runs it. @@ -70,21 +100,35 @@ In the example pillar above: - Upstart files are created for each container, so ``service stop|start|status`` should just work - ``service stop`` will wipeout the container completely (ie ``docker stop + docker rm ``) +``docker.clean`` +^^^^^^^^^^^^^^^^ + +Stop Docker daemon and remove older docker packages (usually called 'docker' and 'docker-engine'). Linux only. + ``docker.repo`` ---------------- +^^^^^^^^^^^^^^^ Configures the upstream docker's repo (true, by default). +``docker.macosapp`` +^^^^^^^^^^^^^^^^^^^ + +Installs Docker Desktop for Mac. + +``docker.macosapp`` +^^^^^^^^^^^^^^^^^^^ + +Installs Docker Desktop for Mac. ``docker.compose`` ------------------- +^^^^^^^^^^^^^^^^^^ Installs `Docker Compose `_ (previously ``fig``) to define groups of containers and their relationships with one another. Use `docker.compose-ng` to run `docker-compose`. ``docker.compose-ng`` ---------------------- +^^^^^^^^^^^^^^^^^^^^^ The intent is to provide an interface similar to the `specification `_ provided by docker-compose. The hope is that you may provide pillar data @@ -148,7 +192,7 @@ Then you would target a host with the following states: ``docker.registry (DEPRECATED)`` --------------------------------- +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NEW: @@ -187,32 +231,57 @@ In this case, extra *docker run* options can be provided in your *"registry:look By default, the storage backend used by the registry is "filesystem". Use environment variables to override that, for example to use S3 as backend storage. ``docker.remove`` ----------------- +^^^^^^^^^^^^^^^^^ Stop Docker daemon. Remove older docker packages (usually called 'docker' and 'docker-engine'). Development -=========== +----------- Note that some of the internal states such as `docker.running` are references to the internal `dockerio states `_ Testing -======= +------- -Testing is done with `Test Kitchen `_ -for machine setup and `testinfra `_ -for integration tests. +Linux testing is done with ``kitchen-salt``. Requirements ------------- +^^^^^^^^^^^^ -* Python * Ruby * Docker -:: +.. code-block:: bash + + $ gem install bundler + $ bundle install + $ bin/kitchen test [platform] + +Where ``[platform]`` is the platform name defined in ``kitchen.yml``, +e.g. ``debian-9-2019-2-py3``. + +``bin/kitchen converge`` +^^^^^^^^^^^^^^^^^^^^^^^^ + +Creates the docker instance and runs the ``template`` main state, ready for testing. + +``bin/kitchen verify`` +^^^^^^^^^^^^^^^^^^^^^^ + +Runs the ``inspec`` tests on the actual instance. + +``bin/kitchen destroy`` +^^^^^^^^^^^^^^^^^^^^^^^ + +Removes the docker instance. + +``bin/kitchen test`` +^^^^^^^^^^^^^^^^^^^^ + +Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``. + +``bin/kitchen login`` +^^^^^^^^^^^^^^^^^^^^^ - gem install bundler - bundle install - kitchen test +Gives you SSH access to the instance for manual testing. diff --git a/kitchen.yml b/kitchen.yml new file mode 100644 index 00000000..dd30b132 --- /dev/null +++ b/kitchen.yml @@ -0,0 +1,174 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +# For help on this file's format, see https://kitchen.ci/ +driver: + name: docker + use_sudo: false + privileged: true + run_command: /lib/systemd/systemd + +# Make sure the platforms listed below match up with +# the `env.matrix` instances defined in `.travis.yml` +platforms: + ## SALT `master` + - name: debian-10-master-py3 + driver: + image: netmanagers/salt-master-py3:debian-10 + - name: ubuntu-1804-master-py3 + driver: + image: netmanagers/salt-master-py3:ubuntu-18.04 + - name: centos-8-master-py3 + driver: + image: netmanagers/salt-master-py3:centos-8 + - name: fedora-31-master-py3 + driver: + image: netmanagers/salt-master-py3:fedora-31 + - name: opensuse-leap-151-master-py3 + driver: + image: netmanagers/salt-master-py3:opensuse-leap-15.1 + run_command: /usr/lib/systemd/systemd + # Workaround to avoid intermittent failures on `opensuse-leap-15.1`: + # => SCP did not finish successfully (255): (Net::SCP::Error) + transport: + max_ssh_sessions: 1 + - name: amazonlinux-2-master-py3 + driver: + image: netmanagers/salt-master-py3:amazonlinux-2 + - name: arch-base-latest-master-py2 + driver: + image: netmanagers/salt-master-py2:arch-base-latest + run_command: /usr/lib/systemd/systemd + + ## SALT `2019.2` + - name: debian-10-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:debian-10 + - name: debian-9-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:debian-9 + - name: ubuntu-1804-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:ubuntu-18.04 + - name: centos-8-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:centos-8 + - name: fedora-31-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:fedora-31 + - name: opensuse-leap-151-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:opensuse-leap-15.1 + run_command: /usr/lib/systemd/systemd + # Workaround to avoid intermittent failures on `opensuse-leap-15.1`: + # => SCP did not finish successfully (255): (Net::SCP::Error) + transport: + max_ssh_sessions: 1 + - name: centos-7-2019-2-py2 + driver: + image: netmanagers/salt-2019.2-py2:centos-7 + - name: amazonlinux-2-2019-2-py3 + driver: + image: netmanagers/salt-2019.2-py3:amazonlinux-2 + - name: arch-base-latest-2019-2-py2 + driver: + image: netmanagers/salt-2019.2-py2:arch-base-latest + run_command: /usr/lib/systemd/systemd + + ## SALT `2018.3` + - name: fedora-30-2018-3-py3 + driver: + image: netmanagers/salt-2018.3-py3:fedora-30 + - name: debian-9-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:debian-9 + - name: ubuntu-1604-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:ubuntu-16.04 + - name: centos-7-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:centos-7 + - name: opensuse-leap-151-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:opensuse-leap-15.1 + run_command: /usr/lib/systemd/systemd + # Workaround to avoid intermittent failures on `opensuse-leap-15.1`: + # => SCP did not finish successfully (255): (Net::SCP::Error) + transport: + max_ssh_sessions: 1 + - name: amazonlinux-1-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:amazonlinux-1 + run_command: /sbin/init + - name: arch-base-latest-2018-3-py2 + driver: + image: netmanagers/salt-2018.3-py2:arch-base-latest + run_command: /usr/lib/systemd/systemd + + ## SALT `2017.7` + - name: debian-8-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:debian-8 + - name: ubuntu-1604-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:ubuntu-16.04 + - name: centos-6-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:centos-6 + run_command: /sbin/init + - name: fedora-30-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:fedora-30 + - name: opensuse-leap-151-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:opensuse-leap-15.1 + run_command: /usr/lib/systemd/systemd + # Workaround to avoid intermittent failures on `opensuse-leap-15.1`: + # => SCP did not finish successfully (255): (Net::SCP::Error) + transport: + max_ssh_sessions: 1 + - name: amazonlinux-1-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:amazonlinux-1 + run_command: /sbin/init + - name: arch-base-latest-2017-7-py2 + driver: + image: netmanagers/salt-2017.7-py2:arch-base-latest + run_command: /usr/lib/systemd/systemd + +provisioner: + name: salt_solo + log_level: debug + salt_install: none + require_chef: false + formula: docker + salt_copy_filter: + - .kitchen + - .git + +verifier: + # https://www.inspec.io/ + name: inspec + sudo: true + # cli, documentation, html, progress, json, json-min, json-rspec, junit + reporter: + - cli + +suites: + - name: default + provisioner: + state_top: + base: + '*': + - docker + - docker.containers + pillars: + top.sls: + base: + '*': + - docker + pillars_from_files: + docker.sls: pillar.example + verifier: + inspec_tests: + - path: test/integration/default diff --git a/pillar.example b/pillar.example index cc778f21..a26b48d1 100644 --- a/pillar.example +++ b/pillar.example @@ -1,5 +1,6 @@ -# vi: set ft=yaml: - +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- # example docker registry container # if you want to your own docker registry, use this docker-containers: @@ -7,11 +8,14 @@ docker-containers: # example docker registry container (if you want your own docker registry, use this) registry: - #image: 'docker.io/registry:latest' ##Fedora + # image: 'docker.io/registry:latest' ##Fedora image: "registry:latest" - cmd: - # Pull image on service restart (useful if you override the same tag. example: latest) - pull_before_start: True + cmd: ~ + # Pull image on service restart + # (useful if you override the same tag. example: latest) + pull_before_start: true + # Remove container on service start + remove_before_start: false # Do not force container removal on stop (unless true) remove_on_stop: false runoptions: @@ -25,16 +29,19 @@ docker-containers: - "--rm" stopoptions: - '-t 10' - + prometheus-server: # example Prometheus container using command arguments image: "prom/prometheus:v1.7.1" - cmd: + cmd: ~ args: - '-config.file=/prom-data/prometheus.yml' - '-storage.local.path=/prom-data/data/' - # Pull image on service restart (useful if you override the same tag. example: latest) - pull_before_start: True + # Pull image on service restart + # (useful if you override the same tag. example: latest) + pull_before_start: true + # Remove container on service start + remove_before_start: false # Do not force container removal on stop (unless true) remove_on_stop: false runoptions: @@ -48,46 +55,49 @@ docker-pkg: lookup: process_signature: /usr/bin/docker - # config for sysvinit/upstart (for systemd, use drop-ins in your own states) - config: - - DOCKER_OPTS="-s btrfs --dns 8.8.8.8" - - export http_proxy="http://172.17.42.1:3128" - # Docker compose supported attributes docker: - #install_pypi_pip: True - #install_docker_py: True + # install_pypi_pip: true + # install_docker_py: true # version of docker-compose to install (defaults to latest) - #compose_version: 1.9.0 - #configfile: /etc/default/docker - install_pypi_pip: True - + # compose_version: 1.9.0 + # configfile: /etc/default/docker + install_pypi_pip: true + + # yamllint disable-line rule:line-length ### https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file - #daemon_config: + # daemon_config: # metrics-addr: '0.0.0.0:9323' # experimental: true - # registry-mirror: 'https://proxy-docker.local:5000' + # registry-mirrors: + # - 'https://proxy-docker.local:5000' # live-restore: true # insecure-registries: # - harbor.local pkg: - # Package handling - #version: 1.13.1 - #allow_updates: True + # Package handling + # version: 1.13.1 + # allow_updates: true + use_upstream_app: false - # PIP proxy configuration (defaults to False) + # config for sysvinit/upstart (for systemd, use drop-ins in your own states) + config: + - DOCKER_OPTS="-s btrfs --dns 8.8.8.8" + - export http_proxy="http://172.17.42.1:3128" + + # PIP proxy configuration (defaults to false) # proxy: proxy.com:3128 # Global functions for docker_container states containers: skip_translate: ports - force_present: False - force_running: True + force_present: false + force_running: true compose: registry-datastore: - dvc: True + dvc: true # image: ®istry_image 'docker.io/registry:latest' ## Fedora image: ®istry_image 'registry:latest' container_name: &dvc 'registry-datastore' @@ -106,16 +116,16 @@ docker: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: '/registry' ports: - 127.0.0.1:5000:5000 - #restart: 'always' # compose v1.9 - deploy: # compose v3 + # restart: 'always' # compose v1.9 + deploy: # compose v3 restart_policy: condition: on-failure delay: 5s max_attempts: 3 window: 120s - nginx-latest: - #image: 'docker.io/nginx:latest' ##Fedora + nginx-latest: + # image: 'docker.io/nginx:latest' ##Fedora image: 'nginx:latest' container_name: 'nginx-latest' links: @@ -127,8 +137,8 @@ docker: - /srv/docker-registry/nginx/:/etc/nginx/conf.d - /srv/docker-registry/auth/:/etc/nginx/conf.d/auth - /srv/docker-registry/certs/:/etc/nginx/conf.d/certs - #restart: 'always' # compose v1.9 - deploy: # compose v3 + # restart: 'always' # compose v1.9 + deploy: # compose v3 restart_policy: condition: on-failure delay: 5s @@ -140,21 +150,21 @@ docker: # additional pillars supporting backwards compatibility only -#docker-pkg: -# lookup: - # docker-py backwards compatibility - #install_docker_py: True - #python_package: docker==2.1.0 - #pip: - # version: '== 8.1.1' - - # Old docker repositories (docker.io, lxc-docker<=1.7) backwards compatibility - #version: '1.6.2' - #pip_version: '<= 1.2.3' - -#registry: +# docker-pkg: +# lookup: +# docker-py backwards compatibility +# install_docker_py: true +# python_package: docker==2.1.0 +# pip: +# version: '== 8.1.1' +# +# Old docker repositories (docker.io, lxc-docker<=1.7) backwards compatibility +# version: '1.6.2' +# pip_version: '<= 1.2.3' +# +# registry: # lookup: - # docker registry 2.x backwards compatibility +# docker registry 2.x backwards compatibility # version: 2 # restart: always # runoptions: @@ -164,9 +174,8 @@ docker: # - "-e REGISTRY_STORAGE_S3_BUCKET=my-bucket" # - "-e REGISTRY_STORAGE_S3_ROOTDIRECTORY=my-folder/my-subfolder/my-sub-subfolder" # - "--log-driver=syslog" - # docker registry < 1, even older backwards compatibility +# docker registry < 1, even older backwards compatibility # amazon: # aws_bucket: 'my-registry' # aws_key: 'ABCDEFGHIJK123456789' # aws_secret: 'AbcD+efG-HIjK1+++23456+789' - diff --git a/pre-commit_semantic-release.sh b/pre-commit_semantic-release.sh new file mode 100755 index 00000000..ba805352 --- /dev/null +++ b/pre-commit_semantic-release.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +############################################################################### +# (A) Update `FORMULA` with `${nextRelease.version}` +############################################################################### +sed -i -e "s_^\(version:\).*_\1 ${1}_" FORMULA + + +############################################################################### +# (B) Use `m2r` to convert automatically produced `.md` docs to `.rst` +############################################################################### + +# Install `m2r` +sudo -H pip install m2r + +# Copy and then convert the `.md` docs +cp ./*.md docs/ +cd docs/ || exit +m2r --overwrite ./*.md + +# Change excess `H1` headings to `H2` in converted `CHANGELOG.rst` +sed -i -e '/^=.*$/s/=/-/g' CHANGELOG.rst +sed -i -e '1,4s/-/=/g' CHANGELOG.rst + +# Use for debugging output, when required +# cat AUTHORS.rst +# cat CHANGELOG.rst + +# Return back to the main directory +cd .. diff --git a/release-rules.js b/release-rules.js new file mode 100644 index 00000000..c63c850d --- /dev/null +++ b/release-rules.js @@ -0,0 +1,18 @@ +// No release is triggered for the types commented out below. +// Commits using these types will be incorporated into the next release. +// +// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`. +module.exports = [ + {breaking: true, release: 'major'}, + // {type: 'build', release: 'patch'}, + // {type: 'chore', release: 'patch'}, + // {type: 'ci', release: 'patch'}, + {type: 'docs', release: 'patch'}, + {type: 'feat', release: 'minor'}, + {type: 'fix', release: 'patch'}, + {type: 'perf', release: 'patch'}, + {type: 'refactor', release: 'patch'}, + {type: 'revert', release: 'patch'}, + {type: 'style', release: 'patch'}, + {type: 'test', release: 'patch'}, +]; diff --git a/release.config.js b/release.config.js new file mode 100644 index 00000000..6af7aa8f --- /dev/null +++ b/release.config.js @@ -0,0 +1,106 @@ +module.exports = { + branch: 'master', + plugins: [ + ['@semantic-release/commit-analyzer', { + preset: 'angular', + releaseRules: './release-rules.js', + }], + '@semantic-release/release-notes-generator', + ['@semantic-release/changelog', { + changelogFile: 'CHANGELOG.md', + changelogTitle: '# Changelog', + }], + ['@semantic-release/exec', { + prepareCmd: 'sh ./pre-commit_semantic-release.sh ${nextRelease.version}', + }], + ['@semantic-release/git', { + assets: ['*.md', 'docs/*.rst', 'FORMULA'], + }], + '@semantic-release/github', + ], + generateNotes: { + preset: 'angular', + writerOpts: { + // Required due to upstream bug preventing all types being displayed. + // Bug: https://github.com/conventional-changelog/conventional-changelog/issues/317 + // Fix: https://github.com/conventional-changelog/conventional-changelog/pull/410 + transform: (commit, context) => { + const issues = [] + + commit.notes.forEach(note => { + note.title = `BREAKING CHANGES` + }) + + // NOTE: Any changes here must be reflected in `CONTRIBUTING.md`. + if (commit.type === `feat`) { + commit.type = `Features` + } else if (commit.type === `fix`) { + commit.type = `Bug Fixes` + } else if (commit.type === `perf`) { + commit.type = `Performance Improvements` + } else if (commit.type === `revert`) { + commit.type = `Reverts` + } else if (commit.type === `docs`) { + commit.type = `Documentation` + } else if (commit.type === `style`) { + commit.type = `Styles` + } else if (commit.type === `refactor`) { + commit.type = `Code Refactoring` + } else if (commit.type === `test`) { + commit.type = `Tests` + } else if (commit.type === `build`) { + commit.type = `Build System` + // } else if (commit.type === `chore`) { + // commit.type = `Maintenance` + } else if (commit.type === `ci`) { + commit.type = `Continuous Integration` + } else { + return + } + + if (commit.scope === `*`) { + commit.scope = `` + } + + if (typeof commit.hash === `string`) { + commit.shortHash = commit.hash.substring(0, 7) + } + + if (typeof commit.subject === `string`) { + let url = context.repository + ? `${context.host}/${context.owner}/${context.repository}` + : context.repoUrl + if (url) { + url = `${url}/issues/` + // Issue URLs. + commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => { + issues.push(issue) + return `[#${issue}](${url}${issue})` + }) + } + if (context.host) { + // User URLs. + commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => { + if (username.includes('/')) { + return `@${username}` + } + + return `[@${username}](${context.host}/${username})` + }) + } + } + + // remove references that already appear in the subject + commit.references = commit.references.filter(reference => { + if (issues.indexOf(reference.issue) === -1) { + return true + } + + return false + }) + + return commit + }, + }, + }, +}; diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index f6682435..00000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -py==1.4.31 -pytest==3.0.3 -six==1.10.0 -testinfra==1.4.2 diff --git a/test/integration/default/README.md b/test/integration/default/README.md new file mode 100644 index 00000000..37cf963c --- /dev/null +++ b/test/integration/default/README.md @@ -0,0 +1,50 @@ +# InSpec Profile: `default` + +This shows the implementation of the `default` InSpec [profile](https://github.com/inspec/inspec/blob/master/docs/profiles.md). + +## Verify a profile + +InSpec ships with built-in features to verify a profile structure. + +```bash +$ inspec check default +Summary +------- +Location: default +Profile: profile +Controls: 4 +Timestamp: 2019-06-24T23:09:01+00:00 +Valid: true + +Errors +------ + +Warnings +-------- +``` + +## Execute a profile + +To run all **supported** controls on a local machine use `inspec exec /path/to/profile`. + +```bash +$ inspec exec default +.. + +Finished in 0.0025 seconds (files took 0.12449 seconds to load) +8 examples, 0 failures +``` + +## Execute a specific control from a profile + +To run one control from the profile use `inspec exec /path/to/profile --controls name`. + +```bash +$ inspec exec default --controls package +. + +Finished in 0.0025 seconds (files took 0.12449 seconds to load) +1 examples, 0 failures +``` + +See an [example control here](https://github.com/inspec/inspec/blob/master/examples/profile/controls/example.rb). diff --git a/test/integration/default/controls/config.rb b/test/integration/default/controls/config.rb new file mode 100644 index 00000000..dfd4d22d --- /dev/null +++ b/test/integration/default/controls/config.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +control 'Docker configuration' do + title 'should match desired lines' + + describe file('/etc/default/docker') do + it { should be_file } + its('owner') { should eq 'root' } + its('group') { should eq 'root' } + its('mode') { should cmp '0644' } + its('content') { should include 'DOCKER_OPTS="-s btrfs --dns 8.8.8.8"' } + its('content') { should include 'export http_proxy="http://172.17.42.1:3128"' } + end +end diff --git a/test/integration/default/controls/package.rb b/test/integration/default/controls/package.rb new file mode 100644 index 00000000..974981e4 --- /dev/null +++ b/test/integration/default/controls/package.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +control 'Docker package' do + title 'should be installed' + + package_name = + case platform[:family] + when 'debian' + 'docker-ce' + # Catch remaining `linux` platforms to identify by `name` at the end + when 'linux' + case platform[:name] + when 'arch' + 'docker' + end + end + + describe package(package_name) do + it { should be_installed } + end +end diff --git a/test/integration/default/controls/service.rb b/test/integration/default/controls/service.rb new file mode 100644 index 00000000..d5a83784 --- /dev/null +++ b/test/integration/default/controls/service.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +control 'Docker service' do + title 'should be running and enabled' + + describe service('docker') do + it { should be_installed } + it { should be_enabled } + it { should be_running } + end +end diff --git a/test/integration/default/inspec.yml b/test/integration/default/inspec.yml new file mode 100644 index 00000000..477b1fcd --- /dev/null +++ b/test/integration/default/inspec.yml @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# vim: ft=yaml +--- +name: default +title: docker formula +maintainer: SaltStack Formulas +license: Apache-2.0 +summary: Verify that the docker formula is setup and configured correctly +supports: + - platform-name: debian + - platform-name: ubuntu + - platform-name: centos + - platform-name: fedora + - platform-name: opensuse + - platform-name: suse + - platform-name: freebsd + - platform-name: amazon + - platform-name: arch diff --git a/test/integration/default/testinfra/test_docker.py b/test/integration/default/testinfra/test_docker.py deleted file mode 100644 index 30c5e7f4..00000000 --- a/test/integration/default/testinfra/test_docker.py +++ /dev/null @@ -1,12 +0,0 @@ -import testinfra - - -def test_package_is_installed(Package): - docker = Package('docker-ce') - assert docker.is_installed - assert docker.version.startswith('18.') - -def test_service_is_running_and_enabled(Service): - docker = Service('docker') - assert docker.is_running - assert docker.is_enabled diff --git a/test/integration/version-1.13.1/testinfra/test_docker.py b/test/integration/version-1.13.1/testinfra/test_docker.py deleted file mode 100644 index a3359998..00000000 --- a/test/integration/version-1.13.1/testinfra/test_docker.py +++ /dev/null @@ -1,11 +0,0 @@ -import testinfra - -def test_package_is_installed(Package): - docker = Package('docker-engine') - assert docker.is_installed - assert docker.version.startswith('1.13.1') - -def test_service_is_running_and_enabled(Service): - docker = Service('docker') - assert docker.is_running - assert docker.is_enabled diff --git a/test/integration/version-1.6.2/testinfra/test_docker.py b/test/integration/version-1.6.2/testinfra/test_docker.py deleted file mode 100644 index 44be269b..00000000 --- a/test/integration/version-1.6.2/testinfra/test_docker.py +++ /dev/null @@ -1,11 +0,0 @@ -import testinfra - -def test_package_is_installed(Package): - docker = Package('docker.io') - assert docker.is_installed - assert docker.version.startswith('1.6.2') - -def test_service_is_running_and_enabled(Service): - docker = Service('docker') - assert docker.is_running - assert docker.is_enabled diff --git a/test/integration/version-18/testinfra/test_docker.py b/test/integration/version-18/testinfra/test_docker.py deleted file mode 100644 index 14ede607..00000000 --- a/test/integration/version-18/testinfra/test_docker.py +++ /dev/null @@ -1,11 +0,0 @@ -import testinfra - -def test_package_is_installed(Package): - docker = Package('docker-engine') - assert docker.is_installed - assert docker.version.startswith('18.') - -def test_service_is_running_and_enabled(Service): - docker = Service('docker') - assert docker.is_running - assert docker.is_enabled