Skip to content

Commit

Permalink
Merge pull request #151 from netmanagers/master
Browse files Browse the repository at this point in the history
Add repo state and possibility to specify package name
  • Loading branch information
aboe76 authored Jul 23, 2018
2 parents 58dacb5 + 65023b6 commit 0827056
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 120 deletions.
45 changes: 23 additions & 22 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,53 @@ provisioner:
base:
'*':
- docker
pillars:
top.sls:
base:
'*':
- docker

platforms:
- name: ubuntu-16.04
- name: ubuntu-18.04
driver_config:
image: ubuntu:16.04
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 && DEBIAN_FRONTEND=noninteractive apt-get install -y locales
- sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen || true
- dpkg-reconfigure --frontend=noninteractive locales || true
- update-locale LANG=en_US.UTF-8 || true
- 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
- name: version-1.13.1
provisioner:
pillars:
top.sls:
base:
'*':
- docker
docker.sls:
docker:
version: '1.13.1*'
excludes:
- debian-jessie

- name: version-1.6.2
use_upstream_repo: true
- name: version-1.13.1
provisioner:
pillars:
top.sls:
base:
'*':
- docker
docker.sls:
docker:
version: '1.6.2*'
version: '1.13.1*'
use_old_repo: true
excludes:
- ubuntu-16.04
- ubuntu-18.04

verifier:
name: shell
Expand Down
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ services:
before_install:
- bundle install

script: bundle exec kitchen verify

env:
matrix:
- INSTANCE: default-ubuntu-1804
- INSTANCE: default-debian-jessie
- INSTANCE: default-debian-stretch
- INSTANCE: version-1131-debian-jessie
- INSTANCE: version-1131-debian-stretch

script:
- bundle exec kitchen verify ${INSTANCE}
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ In the example pillar above:
- Upstart files are created for each container, so ``service <container_name> stop|start|status`` should just work
- ``service <container_name> stop`` will wipeout the container completely (ie ``docker stop <container_name> + docker rm <container_name>``)

``docker.repo``
---------------

Configures the upstream docker's repo (true, by default).


``docker.compose``
------------------
Expand Down
15 changes: 10 additions & 5 deletions docker/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ docker:
configfile: /etc/default/docker
config: []

use_upstream_repo: True
use_old_repo: False

# Repo parameters are set in docker/osfamilymap.yaml

pkg:
version:
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

pip:
pkgname: python-pip
upgrade: False

use_upstream_repo: True
compose_version:

containers:
Expand All @@ -25,9 +33,6 @@ docker:
force_running: False

kernel:

pkg:
fromrepo: ''

pkgs: []

99 changes: 11 additions & 88 deletions docker/init.sls
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% from "docker/map.jinja" import docker with context %}
{% if docker.kernel is defined %}
{% 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) %}
include:
- .kernel
{% endif %}
- .repo
docker package dependencies:
pkg.installed:
Expand All @@ -20,101 +22,23 @@ docker package dependencies:
{% endif %}
- unless: test "`uname`" = "Darwin"
{% set repo_state = 'absent' %}
{% if docker.use_upstream_repo %}
{% set repo_state = 'managed' %}
{% endif %}
{%- if grains['os_family']|lower == 'debian' %}
{%- if grains["oscodename"]|lower == 'jessie' %}
docker package repository:
pkgrepo.{{ repo_state }}:
- name: deb http://http.debian.net/debian jessie-backports main
{%- else %}
{%- if "version" in docker %}
{%- if (docker.version|string).startswith('1.5.') %}
{%- set use_old_repo = docker.version < '1.5.1' %}
{%- else %}
{%- set version_major = (docker.version|string).split('.')[0]|int %}
{%- set version_minor = (docker.version|string).split('.')[1]|int %}
{%- set old_repo_major = 1 %}
{%- set old_repo_minor = 5 %}
{%- set use_old_repo = (version_major < old_repo_major or (version_major == old_repo_major and version_minor < old_repo_minor)) %}
{%- endif %}
{%- endif %}
{%- if "version" in docker and use_old_repo %}
docker package repository:
pkgrepo.{{ repo_state }}:
- name: deb https://get.docker.com/ubuntu docker main
- humanname: Old Docker Package Repository
- keyid: d8576a8ba88d21e9
{%- else %}
purge old packages:
pkgrepo.absent:
- name: deb https://get.docker.com/ubuntu docker main
pkg.purged:
- pkgs:
- lxc-docker*
- docker.io*
- require_in:
- pkgrepo: docker package repository
docker package repository:
pkgrepo.{{ repo_state }}:
- name: deb https://apt.dockerproject.org/repo {{ grains["os"]|lower }}-{{ grains["oscodename"] }} main
- humanname: {{ grains["os"] }} {{ grains["oscodename"]|capitalize }} Docker Package Repository
- keyid: 58118E89F3A912897C070ADBF76221572C52609D
{%- endif %}
- keyserver: hkp://p80.pool.sks-keyservers.net:80
- file: /etc/apt/sources.list.d/docker.list
- refresh_db: True
{%- endif %}
{%- elif grains['os_family']|lower in ('redhat', 'suse',) and grains['os']|lower not in ('amazon', 'fedora', 'suse',) %}
docker package repository:
pkgrepo.{{ repo_state }}:
- name: docker
- baseurl: https://yum.dockerproject.org/repo/main/centos/$releasever/
- gpgcheck: 1
- gpgkey: https://yum.dockerproject.org/gpg
- require_in:
- pkg: docker package
- require:
- pkg: docker package dependencies
{%- endif %}
docker package:
pkg.installed:
{%- if grains["oscodename"]|lower == 'jessie' %}
- name: docker.io
- fromrepo: {{ docker.kernel.pkg.fromrepo }}
{%- elif use_old_repo is defined %}
- name: lxc-docker
{%- else %}
{%- if grains['os']|lower in ('amazon', 'fedora', 'suse',) %}
- name: docker
{%- else %}
- name: docker-engine
- name: {{ docker_pkg_name }}
- version: {{ docker_pkg_version }}
- refresh: {{ docker.refresh_repo }}
- require:
- pkg: docker package dependencies
{%- if grains['os']|lower not in ('amazon', 'fedora', 'suse',) %}
- pkgrepo: docker package repository
{%- endif %}
{%- endif %}
- 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
- allow_updates: {{ docker.pkg.allow_updates }}
{% if docker.pkg.version %}
- version: {{ docker.pkg.version }}
{% elif "version" in docker %}
- version: {{ docker.version }}
{% endif %}
{% if docker.pkg.hold %}
- hold: {{ docker.pkg.hold }}
{% endif %}
docker-config:
file.managed:
Expand All @@ -135,7 +59,6 @@ docker-service:
- sig: {{ docker.process_signature }}
{% endif %}
{% if docker.install_docker_py %}
docker-py requirements:
pkg.installed:
Expand Down
9 changes: 5 additions & 4 deletions docker/kernel.sls
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{% from "docker/map.jinja" import docker with context %}
{%- if docker.kernel is defined and grains['os_family']|lower == 'debian' %}
pkgrepo dependencies:
pkg.installed:
- name: python-apt
{% if "pkgrepo" in docker.kernel %}
{% if "pkgrepo" in docker.kernel %}
{{ grains["oscodename"] }}-backports-repo:
pkgrepo.managed:
{% for key, value in docker.kernel.pkgrepo.items() %}
Expand All @@ -13,9 +14,9 @@ pkgrepo dependencies:
- require:
- pkg: python-apt
- onlyif: dpkg --compare-versions {{ grains["kernelrelease"] }} lt 3.8
{% endif %}
{% endif %}
{% if "pkg" in docker.kernel %}
{% if "pkg" in docker.kernel %}
docker-dependencies-kernel:
pkg.installed:
{% for key, value in docker.kernel.pkg.items() %}
Expand All @@ -24,5 +25,5 @@ docker-dependencies-kernel:
- require_in:
- pkg: docker package
- onlyif: dpkg --compare-versions {{ grains["kernelrelease"] }} lt 3.8
{% endif %}
{% endif %}
4 changes: 4 additions & 0 deletions docker/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@

# 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 %}

{% set pkg = salt['pillar.get']('docker-pkg:lookup', default={}, merge=True) %}
{% do defaults.docker.update(pkg) %}

{% set osfamily = salt['grains.filter_by'](osfamilymap, grain='os_family') or {} %}
{% do defaults.docker.update(osfamily) %}

{% set oscode = salt['grains.filter_by'](codemap, grain='oscodename') or {} %}
{% do defaults.docker.update(oscode) %}

Expand Down
12 changes: 12 additions & 0 deletions docker/osfamilymap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Debian:
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 }}
file: /etc/apt/sources.list.d/docker.list
RedHat:
repo:
url_base: https://download.docker.com/linux/{{ grains['os'] |lower }}/{{ grains['osmajorrelease'] }}/$basearch/stable/
key_url: https://download.docker.com/linux/{{ grains['os'] |lower }}/gpg
version: {{ grains['oscodename'] |lower }}
file: /etc/yum.repos.d/docker-ce.repo
52 changes: 52 additions & 0 deletions docker/repo.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% from "docker/map.jinja" import docker with context %}
{% set repo_state = 'absent' %}
{% if docker.use_upstream_repo or docker.use_old_repo %}
{% set repo_state = 'managed' %}
{% endif %}
{% set humanname_old = 'Old ' if docker.use_old_repo else '' %}
{%- if grains['os']|lower in ('debian', 'ubuntu',) %}
{% set url = 'https://apt.dockerproject.org/repo ' ~ grains["os"]|lower ~ '-' ~ grains["oscodename"] ~ ' main' if docker.use_old_repo else docker.repo.url_base ~ ' ' ~ docker.repo.version ~ ' stable' %}
docker package repository:
pkgrepo.{{ repo_state }}:
- humanname: {{ grains["os"] }} {{ grains["oscodename"]|capitalize }} {{ humanname_old }}Docker Package Repository
- name: deb {{ url }}
- file: {{ docker.repo.file }}
{% if docker.use_old_repo %}
- keyserver: keyserver.ubuntu.com
- keyid: 58118E89F3A912897C070ADBF76221572C52609D
{% else %}
- key_url: {{ docker.repo.key_url }}
{% endif %}
- refresh_db: True
- require_in:
- pkg: docker package
- require:
- pkg: docker package dependencies
{%- elif grains['os']|lower in ('centos', 'fedora') %}
{% set url = 'https://yum.dockerproject.org/repo/main/centos/$releasever/' if docker.use_old_repo else docker.repo.url_base %}
docker package repository:
pkgrepo.{{ repo_state }}:
- name: docker-ce-stable
- humanname: {{ grains['os'] }} {{ grains["oscodename"]|capitalize }} {{ humanname_old }}Docker Package Repository
- baseurl: {{ url }}
- enabled: 1
- gpgcheck: 1
{% if docker.use_old_repo %}
- gpgkey: https://yum.dockerproject.org/gpg
{% else %}
- gpgkey: {{ docker.repo.key_url }}
{% endif %}
- require_in:
- pkg: docker package
- require:
- pkg: docker package dependencies
{%- else %}
docker package repository: {}
{%- endif %}
6 changes: 6 additions & 0 deletions test/integration/default/testinfra/test_docker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import testinfra


def test_package_is_installed(Package):
docker = Package('docker-ce')
assert docker.is_installed
assert docker.version.startswith('18.06.0')

def test_service_is_running_and_enabled(Service):
docker = Service('docker')
assert docker.is_running
Expand Down

0 comments on commit 0827056

Please sign in to comment.