Skip to content

Commit

Permalink
updated setup base iamge
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Jan 15, 2025
1 parent 63298d4 commit 26005fc
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .github/base/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Setting up research environment
hosts: all
become: true
gather_facts: true

vars:
bielefeld_mirror_service_exist: false
pre_tasks:
- name: Generic PRE Tasks
ansible.builtin.import_tasks: ../generic/generic_pre_tasks.yml

post_tasks:
- name: Generic POST Tasks
ansible.builtin.import_tasks: ../generic/generic_post_tasks.yml
50 changes: 50 additions & 0 deletions .github/base/packer_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"variables":{
"network":"",
"os_distro":"",
"os_version":""
},
"builders":[
{
"type":"openstack",
"image_name":"{{user `os_distro`}}{{user `os_version`}} de.NBI ({{isotime `2006-01-02`}})",
"source_image_filter":{
"filters":{
"tags":[
"{{user `base_image_build`}}"
],
"properties":{
"os_distro":"{{user `os_distro`}}",
"os_version":"{{user `os_version`}}",
"image_type": "image"

}
},
"most_recent":true
},
"networks":"{{user `network`}}",
"flavor":"de.NBI tiny",
"description": "Ubuntu is a free and open source operating system and Linux distribution based on Debian.",
"ssh_username":"ubuntu",
"ssh_clear_authorized_keys": true,
"image_tags":[
"{{user `base_image_tag`}}",
"deNBI"
],
"metadata": {
"github_hash": "{{user `github_hash`}}",
"md5_hash": "{{user `md5_hash`}}"
}
}
],
"provisioners":[
{
"type":"ansible",
"playbook_file":"../base/base.yml",
"use_proxy":false,
"extra_arguments":[
"-vv"
]
}
]
}
1 change: 1 addition & 0 deletions packer/tags.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"base_image_tag": "base_image",
"base_image_build_tag": "base_image_build",
"base_cluster_tag": "base_cluster",
"guacamole_tag": "guacamole",
"rstudio_tag": "rstudio",
Expand Down
66 changes: 63 additions & 3 deletions packer/update_base_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

- name: Set Base Image Fact
ansible.builtin.set_fact:
base_images: "{{ images.images | selectattr('tags', 'search', base_image_tag)
base_images: "{{ images.images | selectattr('tags', 'search', base_image_build)
| selectattr('os_distro', '==', os_distro)
| selectattr('os_version', '==', os_version)
| sort(attribute='created_at') }}"
Expand Down Expand Up @@ -60,12 +60,12 @@

- name: Upload image to Openstack
openstack.cloud.image:
name: "{{ name + ' de.NBI (' + date_time + ')' }}"
name: "{{ name + ' de.NBI BUILD (' + date_time + ')' }}"
state: present
filename: "{{ downloaded_filename }}"
tags:
- portalclient
- "{{ base_image_tag }}"
- "{{ base_image_build }}"
- deNBI
properties:
os_distro: "{{ os_distro }}"
Expand All @@ -80,3 +80,63 @@
path: "{{ name }}"
state: absent
when: download_result

- name: Set Update Fact to false
ansible.builtin.set_fact:
update: false

- name: Retrieve list of all images
openstack.cloud.image_info:
register: images

- name: Get Latest Master Branch Commit
ansible.builtin.command: git rev-parse --short --verify origin/master
register: github_hash
changed_when: false

- name: Get md5 Hash from resenv folder
ansible.builtin.shell: set -o pipefail && find ../base -type f -exec md5sum {} \; | md5sum
register: md5_hash
args:
executable: /bin/bash
changed_when: false
- name: Set Base BUILD Images
ansible.builtin.set_fact:
base_images: >-
{{
images.images
| selectattr('tags', 'search', base_image_build)
| selectattr('os_distro', '==', os_distro)
| selectattr('os_version', '==', os_version)
| sort(attribute='created_at')
}}
- name: Set Base Images
ansible.builtin.set_fact:
base_images: >-
{{
images.images
| selectattr('tags', 'search', base_image_tag)
| selectattr('os_distro', '==', os_distro)
| selectattr('os_version', '==', os_version)
| sort(attribute='created_at')
}}
- name: Set Update facts
ansible.builtin.set_fact:
update: true
when:
- base_image_build | length > 0
- base_images | length == 0 or (base_image_build | last).created_at > (base_images | last).created_at
or (base_images | last).github_hash | default('undefined') != github_hash.stdout
or (base_images | last).md5_hash|default ('undefined') != md5_hash.stdout)


- name: Build new Base image - {{ os_distro }} {{ os_version }}
ansible.builtin.command: packer build -var-file=tags.json -var 'os_distro={{ os_distro }}'
-var 'github_hash={{ github_hash.stdout }}' -var 'os_version={{ os_version }}'
-var 'md5_hash={{ md5_hash.stdout}}'
-var 'network={{ vars[location + '_' + upload_environment] }}'
../base/packer_base.json
when: update
changed_when: false

0 comments on commit 26005fc

Please sign in to comment.