dockerfile

pdk
Manage Dockerfile

levinine

levinine

7,428 downloads

1,028 latest version

5.0 quality score

Version information

  • 2.0.0 (latest)
  • 1.6.0
  • 1.5.1
  • 1.5.0
  • 1.4.1
  • 1.4.0
  • 1.3.1
  • 1.3.0
  • 1.2.1
  • 1.2.0
  • 1.1.0
  • 1.0.0
released Jun 20th 2020
This version is compatible with:
  • Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2016.4.x
  • Puppet >= 4.10.0 < 7.0.0
  • RedHat
    ,
    CentOS
    ,
    OracleLinux
    ,
    Scientific
    ,
    SLES
    ,
    Debian
    ,
    Ubuntu
    ,
    Solaris
    ,
    Windows
    ,
    AIX
    ,
    OSX

Start using this module

Documentation

levinine/dockerfile — version 2.0.0 Jun 20th 2020

Dockerfile

Table of Contents

  1. Description
  2. Setup
  3. Usage
  4. Reference
  5. Development
  6. Contributors

Description

The Puppet dockerfile module manage content of dockerfile, exposing instructions as key/values while supporting multistage builds. All dockerfile instructions are supported:

  • ADD
  • ARG
  • CMD
  • COPY
  • ENTRYPOINT
  • ENV
  • EXPOSE
  • FROM
  • HEALTHCHECK
  • LABEL
  • ONBUILD
  • RUN
  • SHELL
  • STOPSIGNAL
  • USER
  • VOLUME
  • WORKDIR

Setup

To install Dockerfile module use puppet module install command:

puppet module install levinine-dockerfile

Usage

Config

In order to provide configuration for dockerfile use the dockerfile::config defined type in the manifest file:

dockerfile::config { 'Dockerfile': 
  ensure => 'present',
  home   => '/var/lib/jenkins/Docker-Build',
  type   => 'multistage',
  conf   => {},
}

Config types

Multistage

Multistage config type Hiera example:

dockerfile::configs:
  Multistage:
    type: multistage
    home: /var/lib/jenkins/Docker-Build
    conf:
      Header:
        comment:
          - Starting comment 1
          - Starting comment 2
      Stage1:
        ensure: present
        comment: Build some docker image
        arg:
          BUILD_NUM: latest
          SOMEARG1: ''
          SOMEARG2: 5
        from:
          platform: linux/amd64
          image: centos:7.6.1810
          as: TEST
        env:
          NUM: $BUILD_NUM
          SOMEENV: test
        label:
          'com.levi9.cluster': cluster
          'com.levi9.role': role
        expose: 80/tcp
        copy:
          from: 0
          source:
            - /tmp with space
            - /test
          destination: /home
        add:
          chown: '0:0'
          source: /tmp
          destination: /home
        volume: test
        cmd:
          - /bin/sh
          - -c
          - top
        entrypoint:
          - /bin/sh
          - -c
          - top
        user: '0:0'
        run:
          - apt-get update
          - apt-get clean
        workdir: /tmp
        stopsignal: signal
        shell:
          - powershell
          - noprofile
        order: '10'
      Stage2:
        ensure: present
        from:
          image: centos:7.6.1810
        env:
          NUM: $BUILD_NUM
          SOMEENV: test
        label:
          'com.levi9.cluster': cluster
          'com.levi9.role': role
        expose: 80/tcp
        copy:
          from: 0
          chown: '0:0'
          source:
            - /tmp
            - /test
          destination: /home
        add:
          chown: '0:0'
          source: /tmp
          destination: /home
        volume: test
        cmd:
          - /bin/sh
          - -c
          - top
        entrypoint:
          - /bin/sh
          - -c
          - top
        user: '0:0'
        run:
          - apt-get update
          - apt-get clean
        workdir: /tmp
        stopsignal: signal
        shell:
          - powershell
          - noprofile
        healthcheck:
          interval: 30s
          timeout: 30s
          start-period: 0s
          retries: 3
          cmd: curl http://localhost
        order: '20'

Multiple COPY/RUN instructions Hiera example:

dockerfile::configs:
  Multistage:
    type: multistage
    home: /var/lib/jenkins/Docker-Build
    conf:
      Stage1:
        from:
          image: centos:7.6.1810
          as: TEST
      Copy1:
        comment: Copy some files
        copy:
          from: TEST
          source:
            - /tmp1
          destination: /home
      Run1:
        ensure: absent
        run:
          - apt-get update
          - apt-get clean
      Copy2:
        onbuild: true
        copy:
          source:
            - /tmp2
          destination: /home
      Stage2:
        comment: Expose some ports
        expose:
          - 80/tcp
          - 8080/tcp

Plain

Plain config type Hiera example:

dockerfile::configs:
  Plain:
    type: plain
    home: /var/lib/jenkins/Docker-Build2
    conf: |
      FROM ubuntu:18.04 as BUILD

      ARG BUILD_NUM="latest"
      ENV PUPPET_AGENT_VERSION="5.5.10" CERTNAME=$BUILD_NUM CODENAME="bionic"

      LABEL BUILD=intermediate

      RUN apt-get update && \
          apt-get install --no-install-recommends -y lsb-release wget ca-certificates && \
          wget https://apt.puppetlabs.com/puppet5-release-"$CODENAME".deb && \
          dpkg -i puppet5-release-"$CODENAME".deb && \
          rm puppet5-release-"$CODENAME".deb && \
          apt-get update && \
          apt-get install --no-install-recommends -y puppet-agent="$PUPPET_AGENT_VERSION"-1"$CODENAME" && \
          apt-get remove --purge -y wget && \
          apt-get autoremove -y && \
          apt-get clean && \
          mkdir -p /etc/puppetlabs/facter/facts.d/ && \
          rm -rf /var/lib/apt/lists/*

      RUN apt-get update && \
          /opt/puppetlabs/bin/puppet agent --verbose --onetime --no-daemonize --summarize && \
          apt-get autoremove -y && \
          apt-get clean && \
          rm -rf /var/lib/apt/lists/*

      FROM ubuntu:18.04

      COPY --from=BUILD /tmp/mydir/myfile .

Reference

See Reference.

Limitations

This module depends on Puppetlabs Concat module, it should be working on all operating systems supported by this module.

Development

Use Report Issues link to report any issues.

Contributors

  • Mladen Pavlik
  • Dragan Nastic
  • Karolj Kocmaros
  • Marko Stojanovic