container-image-from-frecklet

Example:

# Create a Docker image called 'java-docker' from an Ubuntu base image that has Java installed.
- container-image-from-frecklet:
    frecklet_name: java-lang-installed
    image_name: java-docker
    source_image: ubuntu:18.10

Description

If 'install_packer' is set to 'true' and Packer is not already present, install Packer into '$HOME/.local/bin'. Note that this might not work if you are on a non Linux/amd64 platform. In that case it's better to use the 'packer-installed' frecklet manually, before-hand and set this to 'false'.

Create a Docker or LXD image from a base-image and a frecklet.

Create a temporary working directory, then create two files to control the packer process:

  • packer-template.json: packer config file containing the call to the 'frecklecute' provisioner
  • source-frecklet.frecklet: the 'wrapper' frecklet to execute

Then execute Packer via:

packer build packer-template.json

If no 'image_name' is provided, the name of the frecklet is used. If no 'source_image' is provided, a base Ubuntu 18.04 image is used ('ubuntu:18.04' for Docker, 'images:ubuntu/18.04' for LXD).

Variables

Name Type Default Description

frecklet_name

string --

The name of the frecklet. Required

freckles_extra_args

string --

Extra base args for the freckles run.

frecklet_vars

dict --

The frecklet vars.

image_name

string --

The image name.

image_type

string docker

The container image type.

install_packer

boolean False

Install Packer into '$HOME/.local/bin', if not already available.

source_image

string --

The name of the source/parent image.

Examples

Example 1

Create a Docker image called 'java-docker' from an Ubuntu base image that has Java installed.

Code
- container-image-from-frecklet:
    frecklet_name: java-lang-installed
    image_name: java-docker
    source_image: ubuntu:18.10

Example 2

Create an LXD image called 'java-lxd' from a Ubuntu base image that has Java installed. Install Packer on host machine if necessary.

Code
- container-image-from-frecklet:
    frecklet_name: java-lang-installed
    image_name: java-lxd
    source_image: images:ubuntu/18.10
    install_packer: true
    image_type: lxd

Example 3

Create an LXD image called 'java-lang-installed' from an Ubuntu 18.04 base image.

Code
- container-image-from-frecklet:
    frecklet_name: java-lang-installed
    image_type: lxd

Code

doc:
  short_help: Use Hashicorp Packer to create a container image from a frecklet.
  help: |
    If 'install_packer' is set to 'true' and Packer is not already present, install Packer into '$HOME/.local/bin'. Note that this might not work if you are on a non Linux/amd64 platform. In that case it's better to use the 'packer-installed' frecklet manually, before-hand and set this to 'false'.

    Create a Docker or LXD image from a base-image and a frecklet.

    Create a temporary working directory, then create two files to control the packer process:

      - packer-template.json: packer config file containing the call to the 'frecklecute' provisioner
      - source-frecklet.frecklet: the 'wrapper' frecklet to execute

    Then execute Packer via:

        packer build packer-template.json

    If no 'image_name' is provided, the name of the *frecklet* is used. If no 'source_image' is provided,
    a base Ubuntu 18.04 image is used ('ubuntu:18.04' for Docker, 'images:ubuntu/18.04' for LXD).

  examples:
  - title: Create a Docker image called 'java-docker' from an Ubuntu base image that
      has Java installed.
    vars:
      frecklet_name: java-lang-installed
      image_name: java-docker
      source_image: ubuntu:18.10
  - title: Create an LXD image called 'java-lxd' from a Ubuntu base image that has
      Java installed. Install Packer on host machine if necessary.
    vars:
      frecklet_name: java-lang-installed
      image_name: java-lxd
      source_image: images:ubuntu/18.10
      install_packer: true
      image_type: lxd
  - title: Create an LXD image called 'java-lang-installed' from an Ubuntu 18.04 base
      image.
    vars:
      frecklet_name: java-lang-installed
      image_type: lxd


args:
  _import: frecklet-file
  image_name:
    doc:
      short_help: The image name.
    type: string
    required: false
  image_type:
    doc:
      short_help: The container image type.
    type: string
    required: true
    default: docker
    allowed:
    - docker
    - lxd
  source_image:
    doc:
      short_help: The name of the source/parent image.
    type: string
    required: false
  freckles_extra_args:
    doc:
      short_help: Extra base args for the freckles run.
    type: string
    required: false
  install_packer:
    doc:
      short_help: Install Packer into '$HOME/.local/bin', if not already available.
    type: boolean
    required: false
    default: false
    cli:
      param_decls:
      - --install-packer

frecklets:
- packer-installed:
    frecklet::skip: '{{:: install_packer | negate ::}}'
- path-is-absent:
    path: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name) ::}}'
- folder-exists:
    path: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name) ::}}'
    mode: '0700'
- frecklet-file:
    path: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name) ::}}/source-frecklet.frecklet'
    frecklet_name: '{{:: frecklet_name ::}}'
    frecklet_vars: '{{:: frecklet_vars ::}}'
- docker-frecklet-packer-template-file:
    frecklet::skip: "{{:: image_type | false_if_equal('docker') ::}}"
    path: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name) ::}}/packer-template.json'
    image_name: '{{:: image_name | default(frecklet_name) ::}}'
    frecklet_path: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name)
      ::}}/source-frecklet.frecklet'
    source_image: "{{:: source_image | default('ubuntu:18.04') ::}}"
    freckles_extra_args: '{{:: freckles_extra_args ::}}'
- lxd-container-absent:
    frecklet::skip: "{{:: image_type | false_if_equal('lxd') ::}}"
    name: 'packer-{{:: image_name | default(frecklet_name) ::}}'
- lxd-frecklet-packer-template-file:
    frecklet::skip: "{{:: image_type | false_if_equal('lxd') ::}}"
    path: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name) ::}}/packer-template.json'
    image_name: '{{:: image_name | default(frecklet_name) ::}}'
    frecklet_path: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name)
      ::}}/source-frecklet.frecklet'
    source_image: "{{:: source_image | default('images/ubuntu/18.04') ::}}"
    freckles_extra_args: '{{:: freckles_extra_args ::}}'
- execute-command:
    command: packer build packer-template.json
    chdir: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name) ::}}/'
- path-is-absent:
    path: '/tmp/_frecklet_packer_build/{{:: image_name | default(frecklet_name) ::}}'
- lxd-container-absent:
    frecklet::skip: "{{:: image_type | false_if_equal('lxd') ::}}"
    name: 'packer-{{:: image_name | default(frecklet_name) ::}}'
frecklecute container-image-from-frecklet --help

Usage: frecklecute container-image-from-frecklet [OPTIONS]

  If 'install_packer' is set to 'true' and Packer is not already present,
  install Packer into '$HOME/.local/bin'. Note that this might not work if
  you are on a non Linux/amd64 platform. In that case it's better to use the
  'packer-installed' frecklet manually, before-hand and set this to 'false'.

  Create a Docker or LXD image from a base-image and a frecklet.

  Create a temporary working directory, then create two files to control the
  packer process:

    - packer-template.json: packer config file containing the call to the
    'frecklecute' provisioner   - source-frecklet.frecklet: the 'wrapper'
    frecklet to execute

  Then execute Packer via:

      packer build packer-template.json

  If no 'image_name' is provided, the name of the *frecklet* is used. If no
  'source_image' is provided, a base Ubuntu 18.04 image is used
  ('ubuntu:18.04' for Docker, 'images:ubuntu/18.04' for LXD).

Options:
  --frecklet-name FRECKLET_NAME   The name of the frecklet.  [required]
  --freckles-extra-args FRECKLES_EXTRA_ARGS
                                  Extra base args for the freckles run.
  --frecklet-vars FRECKLET_VARS   The frecklet vars.
  --image-name IMAGE_NAME         The image name.
  --image-type IMAGE_TYPE         The container image type.
  --install-packer                Install Packer into '$HOME/.local/bin', if
                                  not already available.
  --source-image SOURCE_IMAGE     The name of the source/parent image.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.container_image_from_frecklet.ContainerImageFromFrecklet
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class ContainerImageFromFrecklet(AutoPycklet):
    """If 'install_packer' is set to 'true' and Packer is not already present, install Packer into '$HOME/.local/bin'. Note that this might not work if you are on a non Linux/amd64 platform. In that case it's better to use the 'packer-installed' frecklet manually, before-hand and set this to 'false'.

     Create a Docker or LXD image from a base-image and a frecklet.

     Create a temporary working directory, then create two files to control the packer process:

       - packer-template.json: packer config file containing the call to the 'frecklecute' provisioner
       - source-frecklet.frecklet: the 'wrapper' frecklet to execute

     Then execute Packer via:

         packer build packer-template.json

     If no 'image_name' is provided, the name of the *frecklet* is used. If no 'source_image' is provided,
     a base Ubuntu 18.04 image is used ('ubuntu:18.04' for Docker, 'images:ubuntu/18.04' for LXD).

       Args:
         freckles_extra_args: Extra base args for the freckles run.
         frecklet_name: The name of the frecklet.
         frecklet_vars: The frecklet vars.
         image_name: The image name.
         image_type: The container image type.
         install_packer: Install Packer into '$HOME/.local/bin', if not already available.
         source_image: The name of the source/parent image.

    """

    FRECKLET_ID = "container-image-from-frecklet"

    freckles_extra_args: str = None
    frecklet_name: str = None
    frecklet_vars: Dict = None
    image_name: str = None
    image_type: str = None
    install_packer: bool = None
    source_image: str = None


    def __post_init__(self):
        super(ContainerImageFromFrecklet, self).__init__(var_names=["freckles_extra_args", "frecklet_name", "frecklet_vars", "image_name", "image_type", "install_packer", "source_image"])


frecklet_class = ContainerImageFromFrecklet
# -*- coding: utf-8 -*-


#
# module path: pycklets.container_image_from_frecklet.ContainerImageFromFrecklet
#


from pyckles import AutoPycklet

class ContainerImageFromFrecklet(AutoPycklet):
    """If 'install_packer' is set to 'true' and Packer is not already present, install Packer into '$HOME/.local/bin'. Note that this might not work if you are on a non Linux/amd64 platform. In that case it's better to use the 'packer-installed' frecklet manually, before-hand and set this to 'false'.

     Create a Docker or LXD image from a base-image and a frecklet.

     Create a temporary working directory, then create two files to control the packer process:

       - packer-template.json: packer config file containing the call to the 'frecklecute' provisioner
       - source-frecklet.frecklet: the 'wrapper' frecklet to execute

     Then execute Packer via:

         packer build packer-template.json

     If no 'image_name' is provided, the name of the *frecklet* is used. If no 'source_image' is provided,
     a base Ubuntu 18.04 image is used ('ubuntu:18.04' for Docker, 'images:ubuntu/18.04' for LXD).

       Args:
         freckles_extra_args: Extra base args for the freckles run.
         frecklet_name: The name of the frecklet.
         frecklet_vars: The frecklet vars.
         image_name: The image name.
         image_type: The container image type.
         install_packer: Install Packer into '$HOME/.local/bin', if not already available.
         source_image: The name of the source/parent image.

    """

    FRECKLET_ID = "container-image-from-frecklet"

    def __init__(self, freckles_extra_args=None, frecklet_name=None, frecklet_vars=None, image_name=None, image_type="docker", install_packer=None, source_image=None):

        super(ContainerImageFromFrecklet, self).__init__(var_names=["freckles_extra_args", "frecklet_name", "frecklet_vars", "image_name", "image_type", "install_packer", "source_image"])
        self._freckles_extra_args = freckles_extra_args
        self._frecklet_name = frecklet_name
        self._frecklet_vars = frecklet_vars
        self._image_name = image_name
        self._image_type = image_type
        self._install_packer = install_packer
        self._source_image = source_image

    @property
    def freckles_extra_args(self):
        return self._freckles_extra_args

    @freckles_extra_args.setter
    def freckles_extra_args(self, freckles_extra_args):
        self._freckles_extra_args = freckles_extra_args

    @property
    def frecklet_name(self):
        return self._frecklet_name

    @frecklet_name.setter
    def frecklet_name(self, frecklet_name):
        self._frecklet_name = frecklet_name

    @property
    def frecklet_vars(self):
        return self._frecklet_vars

    @frecklet_vars.setter
    def frecklet_vars(self, frecklet_vars):
        self._frecklet_vars = frecklet_vars

    @property
    def image_name(self):
        return self._image_name

    @image_name.setter
    def image_name(self, image_name):
        self._image_name = image_name

    @property
    def image_type(self):
        return self._image_type

    @image_type.setter
    def image_type(self, image_type):
        self._image_type = image_type

    @property
    def install_packer(self):
        return self._install_packer

    @install_packer.setter
    def install_packer(self, install_packer):
        self._install_packer = install_packer

    @property
    def source_image(self):
        return self._source_image

    @source_image.setter
    def source_image(self, source_image):
        self._source_image = source_image



frecklet_class = ContainerImageFromFrecklet