If you are using GitLab outside of the ILL, then you will need to use HTTPS and not SSH for clone/push/pull operations. If you are using the VPN, then SSH will work normally.

...
 
Commits (7)
version 0.3.0
-------------
* CHANGED merged parameters templates into environment
version 0.2.1
-------------
* CHANGED the -v option can now be used without -t
......
......@@ -27,7 +27,9 @@ class PackerTemplate:
self._packages_base_dir = packages_base_dir
self._templates_base_dir = templates_base_dir
self._parameters = yaml_node.get("parameters", {})
environment_file = os.path.join(self._templates_base_dir,self._name,"environment.yml")
self._read_environment_file(environment_file)
self._environment.update(os.environ)
# Fetch the 'packer' node
packer_node = yaml_node.get("packer", {})
......@@ -55,6 +57,25 @@ class PackerTemplate:
self._load_packages(packages)
def _read_environment_file(self, environment_file):
"""Read YAML environemnt file and populate os.environ
Parameters
----------
environment_file: str
Path to the environment file.
"""
if not os.path.exists(environment_file):
return
self._environment = {}
with open(environment_file, "r") as fin:
env = yaml.safe_load(fin)
for k,v in env.get("environment",{}).items():
self._environment[k] = str(v)
def _update_builder(self, builder: Dict[str,str]):
"""Update some fields of a builder.
......@@ -115,15 +136,6 @@ class PackerTemplate:
return self._name
@property
def parameters(self) -> dict:
"""Returns the parameters of this :class:`PackerTemplate`.
This dictionary will be applied to Jinja 2 templates when creating the manifest json file.
"""
return self._parameters
@property
def postprocessors(self) -> list:
"""Returns the postprocessors of this :class:`PackerTemplate`.
......@@ -258,8 +270,7 @@ class PackerTemplate:
# Render the jinja2 templates with the parameters dictionary provided in the template file and the available environment variables
jinja_template = jinja2.Template(repr(node))
s = jinja_template.render(parameters=self._parameters, environment=os.environ)
s = jinja_template.render(environment=self._environment)
# Dump to the output file
with open(output_file, "w") as fout:
json.dump(yaml.safe_load(s), fout, **kwargs)
......
......@@ -20,7 +20,7 @@ __status__ : str = "Prototype"
__url__ : str = "https://code.ill.fr/panosc/data-analysis-services/packme"
__version__ : str = "0.2.1"
__version__ : str = "0.3.0"
__long_description_content_type__ : str ="text/markdown"
......
......@@ -9,8 +9,6 @@ class PackerTemplate:
@property
def name(self) -> str: ...
@property
def parameters(self) -> dict: ...
@property
def postprocessors(self) -> list: ...
@property
def provisioners(self) -> list: ...
......
environment:
base_image: "base-ntp"
vm_name: base-autofs
build_output_directory: builds
ssh_username: root
parameters:
base_image: "base-ntp"
vm_name: base-autofs
build_output_directory: builds
ssh_username: root
packer:
description: "Template for ILL + ntp + autofs"
builders:
- name: qemu
type: qemu
vm_name: "{{ parameters.vm_name }}"
vm_name: "{{ environment.vm_name }}"
boot_command: none
iso_checksum_type: none
iso_checksum_url: none
disk_image: True
iso_url: "./builds/{{ parameters.base_image }}-qemu-base/{{ parameters.base_image }}"
ssh_username: "{{ parameters.ssh_username }}"
iso_url: "./builds/{{ environment.base_image }}-qemu-base/{{ environment.base_image }}"
ssh_username: "{{ environment.ssh_username }}"
ssh_password: "{{ environment.root_password }}"
shutdown_command: "shutdown -P now"
output_directory: "{{ parameters.build_output_directory }}/{{ parameters.vm_name }}-qemu-base"
output_directory: "{{ environment.build_output_directory }}/{{ environment.vm_name }}-qemu-base"
provisioners:
- type: shell
......
environment:
proxy: http://proxy.ill.fr:8888
no_proxy: localhost,127.0.0.1,apt.ill.fr,*.ill.eu,*.ill.fr
dns_servers: 195.83.126.2 195.83.126.11
gateway: 192.168.180.254
cpus: 2
memory: 4096
disk_size: 40000
ubuntu_mirror: http://archive.ubuntu.com/ubuntu/dists
ubuntu_codename: bionic
ubuntu_docker_image: ubuntu:18.04
preseed_file_name: preseed-base-ill.cfg
ssh_username: root
user: si-admin
user_fullname: si-admin
build_output_directory: builds
parameters:
vm_name: base-ill
proxy: http://proxy.ill.fr:8888
no_proxy: localhost,127.0.0.1,apt.ill.fr,*.ill.eu,*.ill.fr
dns_servers: 195.83.126.2 195.83.126.11
gateway: 192.168.180.254
cpus: 2
memory: 4096
disk_size: 40000
ubuntu_mirror: http://archive.ubuntu.com/ubuntu/dists
ubuntu_codename: bionic
ubuntu_docker_image: ubuntu:18.04
preseed_file_name: preseed-base-ill.cfg
ssh_username: root
user: si-admin
user_fullname: si-admin
headless: false
build_output_directory: builds
packer:
description: "Base template for ILL"
......@@ -25,47 +6,46 @@ packer:
builders:
- name: qemu
type: qemu
vm_name: "{{ parameters.vm_name }}"
format: qcow2
iso_checksum_type: sha256
iso_checksum_url: "{{ parameters.ubuntu_mirror }}/{{ parameters.ubuntu_codename }}-updates/main/installer-amd64/current/images/SHA256SUMS"
iso_url: "{{ parameters.ubuntu_mirror }}/{{ parameters.ubuntu_codename }}-updates/main/installer-amd64/current/images/netboot/mini.iso"
ssh_username: "{{ parameters.ssh_username }}"
iso_checksum_url: "{{ environment.ubuntu_mirror }}/{{ environment.ubuntu_codename }}-updates/main/installer-amd64/current/images/SHA256SUMS"
iso_url: "{{ environment.ubuntu_mirror }}/{{ environment.ubuntu_codename }}-updates/main/installer-amd64/current/images/netboot/mini.iso"
ssh_username: "{{ environment.ssh_username }}"
ssh_password: "{{ environment.root_password }}"
ssh_timeout: 60m
accelerator: kvm
headless: "{{ parameters.headless }}"
headless: "{{ environment.headless }}"
shutdown_command: "shutdown -P now"
qemuargs:
- - "-m"
- "{{ parameters.memory }}"
- "{{ environment.memory }}"
- - "-smp"
- "{{ parameters.cpus }}"
- "{{ environment.cpus }}"
boot_wait: 5s
boot_command:
- "<tab> "
- "preseed/url=http://{% raw %}{{ .HTTPIP }}:{{ .HTTPPort }}{% endraw %}/{{ parameters.preseed_file_name }} "
- "preseed/url=http://{% raw %}{{ .HTTPIP }}:{{ .HTTPPort }}{% endraw %}/{{ environment.preseed_file_name }} "
- "auto-install/enable=true "
- "net.ifnames=0 "
- "netcfg/get_hostname={{ parameters.vm_name }} "
- "netcfg/get_gateway={{ parameters.gateway}} "
- "netcfg/get_nameservers={{ parameters.dns_servers }} "
- "netcfg/hostname={{ parameters.vm_name }} "
- "mirror/http/proxy={{ parameters.proxy}} "
- "passwd/user-fullname={{ parameters.user }} "
- "passwd/username={{ parameters.user_fullname }} "
- "netcfg/get_hostname={{ environment.vm_name }} "
- "netcfg/get_gateway={{ environment.gateway}} "
- "netcfg/get_nameservers={{ environment.dns_servers }} "
- "netcfg/hostname={{ environment.vm_name }} "
- "mirror/http/proxy={{ environment.proxy}} "
- "passwd/user-fullname={{ environment.user }} "
- "passwd/username={{ environment.user_fullname }} "
- "passwd/user-password= {{ environment.user_password }} "
- "passwd/user-password-again= {{ environment.user_password }} "
- "passwd/root-password={{ environment.root_password }} "
- "passwd/root-password-again={{ environment.root_password }} "
- "no_proxy={% raw %}{{ .HTTPIP }}{% endraw %},{{ parameters.no_proxy }} "
- "no_proxy={% raw %}{{ .HTTPIP }}{% endraw %},{{ environment.no_proxy }} "
- "<enter>"
disk_size: "{{ parameters.disk_size }}"
disk_size: "{{ environment.disk_size }}"
http_directory: "http"
provisioners:
- type: file
source: "system/etc/apt/sources.list_{{ parameters.ubuntu_codename }}"
source: "system/etc/apt/sources.list_{{ environment.ubuntu_codename }}"
destination: "/etc/apt/sources.list"
- type: file
......
environment:
base_image: base-ill
vm_name: ill-ntp
build_output_directory: builds
ssh_username: root
parameters:
base_image: base-ill
vm_name: ill-ntp
build_output_directory: builds
ssh_username: root
packer:
description: "Template for ILL + ntp"
......@@ -13,16 +7,16 @@ packer:
builders:
- name: qemu
type: qemu
vm_name: "{{ parameters.vm_name }}"
vm_name: "{{ environment.vm_name }}"
boot_command: none
iso_checksum_type: none
iso_checksum_url: none
disk_image: True
iso_url: "./builds/{{ parameters.base_image }}-qemu-base/{{ parameters.base_image }}"
ssh_username: "{{ parameters.ssh_username }}"
iso_url: "./builds/{{ environment.base_image }}-qemu-base/{{ environment.base_image }}"
ssh_username: "{{ environment.ssh_username }}"
ssh_password: "{{ environment.root_password }}"
shutdown_command: "shutdown -P now"
output_directory: "{{ parameters.build_output_directory }}/{{ parameters.vm_name }}-qemu-base"
output_directory: "{{ environment.build_output_directory }}/{{ environment.vm_name }}-qemu-base"
provisioners:
- type: shell
......