Refactor LXC image expiration
Right now we write output of `date -d @{{ timestamp }} to the expiry file, and then attempt to comapre with timestamp. However, output of `date -d` is datetime and not timestamp, so these 2 things can not be properly compared. So image cache was valid forever. Change-Id: I42f5b43f09d3c530813dd7fd334eafce7a5eaf39
This commit is contained in:
parent
caebffe51e
commit
a51291f87d
@ -203,6 +203,10 @@ lxc_hosts_container_build_command: "{{ _lxc_hosts_container_build_command | defa
|
||||
# Local path to cached image
|
||||
lxc_image_cache_path: "/var/lib/machines/{{ lxc_container_base_name }}"
|
||||
|
||||
# Expiration timeout for the cached image
|
||||
# Should be in format supported by the to_time_unit filter
|
||||
lxc_image_cache_expiration: "1year"
|
||||
|
||||
# Set this option to true to pull a new cached image.
|
||||
lxc_image_cache_refresh: false
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Implemented variable ``lxc_image_cache_expiration`` that controlls for how
|
||||
long cached LXC image will be valid. Default value is `1year`. Variable
|
||||
format should be compatible with community.general.to_time_unit filter.
|
||||
fixes:
|
||||
- |
|
||||
LXC image cache expiration mechanism has being fixed. Previously LXC images were
|
||||
valid forever.
|
@ -16,7 +16,7 @@
|
||||
- name: Set LXC cache fact(s)
|
||||
set_fact:
|
||||
cache_path_fact: "{{ lxc_container_cache_path }}/{{ lxc_cache_map.distro }}/{{ lxc_cache_map.release }}/{{ lxc_cache_map.arch }}/{{ lxc_cache_default_variant }}"
|
||||
cache_time: "{{ ansible_facts['date_time']['epoch'] }}"
|
||||
cache_time: "{{ now().timestamp() }}"
|
||||
|
||||
- name: Retrieve the expiry object
|
||||
slurp:
|
||||
@ -32,7 +32,7 @@
|
||||
set_fact:
|
||||
lxc_image_cache_refresh: true
|
||||
when:
|
||||
cache_time >= (expiry.content|default('MQo=') | b64decode)
|
||||
cache_time | int >= (expiry.content | default('MQo=') | b64decode | int)
|
||||
tags:
|
||||
- always
|
||||
|
||||
|
@ -48,21 +48,14 @@
|
||||
- expiry
|
||||
- templates
|
||||
|
||||
- name: Set cache expiry
|
||||
shell: "date -d @{{ (cache_time | int) + 31536000 }}"
|
||||
changed_when: false
|
||||
register: _cache_expiry
|
||||
tags:
|
||||
- skip_ansible_lint
|
||||
|
||||
- name: Set expiry
|
||||
copy:
|
||||
content: "{{ _cache_expiry.stdout }}"
|
||||
content: "{{ cache_time | int + lxc_image_cache_expiration | community.general.to_seconds | int }}"
|
||||
dest: "{{ cache_path_fact }}/expiry"
|
||||
|
||||
- name: Set build ID
|
||||
copy:
|
||||
content: "{{ cache_time }}"
|
||||
content: "{{ cache_time | int }}"
|
||||
dest: "{{ cache_path_fact }}/build_id"
|
||||
|
||||
- name: Create base container to use for {{ lxc_container_backing_store }}-backed containers
|
||||
|
Loading…
x
Reference in New Issue
Block a user