mrlesmithjr / packer-builder

Packer Builder - Making Packer Building More Consumable
MIT License
11 stars 3 forks source link

Rework configuration logic. #4

Open bunchc opened 5 years ago

bunchc commented 5 years ago

At the moment configuration logic is spread between different modules and distro.yml. I propose the following:

An example of additional build specific details stored in distros.yml

---
Alpine:
  builders:
    - qemu
    - virtualbox-iso
    - vmware-iso
  cpus: 1
  disk_adapter_type: scsi
  disk_size: 36864
  memory: 1024
  password: P@55w0rd
  username: root
  vagrant_box: true
  versions:
    3.8:
      iso_checksum: 20d20e0658b6cc361832cfb49367f0a4c33570ef1521f2e394e9164d2a9bd9df
      iso_checksum_type: sha256
      iso_url: http://dl-cdn.alpinelinux.org/alpine/v3.8/releases/x86_64/alpine-virt-3.8.4-x86_64.iso
    3.9:
      iso_checksum: 75a784aa16ab6311dbf597bdec86259183ba5e74633e7e9201300d848d457216
      iso_checksum_type: sha256
      iso_url: http://dl-cdn.alpinelinux.org/alpine/v3.9/releases/x86_64/alpine-virt-3.9.2-x86_64.iso
  provisioners:
    shell:
      type: shell
      scripts:
        - base.sh
        - virtualbox.sh
        - vmware.sh
        - cleanup.sh
        - vagrant.sh
        - zerodisk.sh
  post-processors:
    ovftool:
      type: shell-local
      inline: "ovftool lol//{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}/{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.vmx lol//{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}/{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.ovf"
      only:
        - vmware-iso
    vagrant:
      type: vagrant
      compression_level: "{{ user `compression_level` }}"
      keep_input_artifact: True
      output: "{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.box"
    manifest:
      type: manifest
      strip_path: True

If extended to allow for "include: "conf/build.d/*"style functionality this will allow for more granular control of thedistro.yml`

bunchc commented 5 years ago

This should simplify some of the error checking, and help reduce weird configuration situations. I also feel there should be some manner of global override facility for these values in distros.yml. This could reduce the amount of repetitive info stored for each distro. Something like this:

---
Alpine:
  versions:
    3.8:
      iso_checksum: 20d20e0658b6cc361832cfb49367f0a4c33570ef1521f2e394e9164d2a9bd9df
      iso_checksum_type: sha256
      iso_url: http://dl-cdn.alpinelinux.org/alpine/v3.8/releases/x86_64/alpine-virt-3.8.4-x86_64.iso
    3.9:
      iso_checksum: 75a784aa16ab6311dbf597bdec86259183ba5e74633e7e9201300d848d457216
      iso_checksum_type: sha256
      iso_url: http://dl-cdn.alpinelinux.org/alpine/v3.9/releases/x86_64/alpine-virt-3.9.2-x86_64.iso
FreeNAS:
  vagrant_box: false
  versions:
    11.2:
      iso_checksum: 3fb19c9304072bdf915d7c275e35ebc0a38d4b741e16f36a8f7af76413242092
      iso_checksum_type: sha256
      iso_url: https://download.freenas.org/11.2/STABLE/U3/x64/FreeNAS-11.2-U3.iso
  provisioners:
    shell:
      type: shell
      environment_vars:
        - "SSH_USER={{ user `username` }}"
        - "SSH_PASS={{ user `password` }}"
      scripts:
        - freenas.sh

Defaults:
  cpus: 1
  disk_adapter_type: scsi
  disk_size: 36864
  memory: 1024
  password: P@55w0rd
  username: root
  vagrant_box: true
  builders:
    - vmware-iso
    - virtualbox-iso
    - qemu
  provisioners:
    shell:
      type: shell
      scripts:
        - base.sh
        - virtualbox.sh
        - vmware.sh
        - cleanup.sh
        - vagrant.sh
        - zerodisk.sh
  post-processors:
    ovftool:
      type: shell-local
      inline: "ovftool lol//{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}/{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.vmx lol//{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}/{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.ovf"
      only:
        - vmware-iso
    vagrant:
      type: vagrant
      compression_level: "{{ user `compression_level` }}"
      keep_input_artifact: True
      output: "{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.box"
    manifest:
      type: manifest
      strip_path: True
bunchc commented 5 years ago

Another thought that includes the include section:

---
Defaults:
  cpus: 1
  disk_adapter_type: scsi
  disk_size: 36864
  memory: 1024
  password: P@55w0rd
  username: root
  vagrant_box: true
  builders:
    - vmware-iso
    - virtualbox-iso
    - qemu
  provisioners:
    shell:
      type: shell
      scripts:
        - base.sh
        - virtualbox.sh
        - vmware.sh
        - cleanup.sh
        - vagrant.sh
        - zerodisk.sh
  post-processors:
    ovftool:
      type: shell-local
      inline: "ovftool lol//{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}/{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.vmx lol//{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}/{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.ovf"
      only:
        - vmware-iso
    vagrant:
      type: vagrant
      compression_level: "{{ user `compression_level` }}"
      keep_input_artifact: True
      output: "{{ user `vm_name` }}-{{ build_type }}-{{ timestamp }}.box"
    manifest:
      type: manifest
      strip_path: True
Include:
  conf:
    - /one/off/path/ubuntu.yml
    - https://gist.githubusercontent.com/path/to/gist/centos7-stig.yml
    - build.d/*

Each of these, will clean out config details from, and allow template.py to become a bit more generic.

mrlesmithjr commented 5 years ago

I really like the direction of this. This would definitely simplify and standardize things.

mrlesmithjr commented 4 years ago

Should this be part of the first release?

mrlesmithjr commented 4 years ago

Rework configuration logic