From c1d326143510039622bf51cf0c528b2859bcb37a Mon Sep 17 00:00:00 2001 From: Bas Meijer Date: Thu, 21 Mar 2024 10:56:04 +0100 Subject: [PATCH] Push the container as molecule side-effect Signed-off-by: Bas Meijer --- .yamllint | 2 ++ molecule/default/molecule.yml | 3 ++- molecule/resources/playbooks/side-effect.yml | 25 ++++++++++++++++++++ requirements.yml | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 molecule/resources/playbooks/side-effect.yml create mode 100644 requirements.yml diff --git a/.yamllint b/.yamllint index 09fae6e..63c121e 100644 --- a/.yamllint +++ b/.yamllint @@ -2,5 +2,7 @@ extends: default rules: + line-length: + max: 160 truthy: check-keys: false diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 42b62fe..a646826 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -5,7 +5,7 @@ dependency: driver: name: docker platforms: - - name: amq-alma8 + - name: base_amq image: dokken/almalinux-8 pre_build_image: true command: /sbin/init @@ -29,6 +29,7 @@ provisioner: prepare: ../resources/playbooks/prepare.yml converge: ../resources/playbooks/converge.yml verify: ../resources/playbooks/verify.yml + side_effect: ../resources/playbooks/side-effect.yml verifier: name: ansible ... diff --git a/molecule/resources/playbooks/side-effect.yml b/molecule/resources/playbooks/side-effect.yml new file mode 100644 index 0000000..712cda1 --- /dev/null +++ b/molecule/resources/playbooks/side-effect.yml @@ -0,0 +1,25 @@ +--- +# export DOCKER_REGISTRY +- name: Commit, tag, and push Docker image + hosts: localhost + gather_facts: false + connection: local + vars: + github_actions: "{{ lookup('env', 'GITHUB_ACTIONS') }}" + docker_registry: "{{ lookup('env','DOCKER_REGISTRY') }}" + image_name: "dockpack/base_amq" + image_tag: "{{ lookup('pipe', 'date +%Y%m%d%H') }}" # Generates a date hour stamp + tasks: + - name: Commit the container + ansible.builtin.command: + cmd: "docker commit base_amq {{ image_name }}:{{ image_tag }}" + changed_when: true + register: commit_output + + - name: Tag and push the Docker image + when: not github_actions | bool + community.docker.docker_image: + name: "{{ docker_registry }}{% if docker_registry | length > 1 %}/{% endif %}{{ image_name }}" + tag: "{{ image_tag }}" + push: true + source: local diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..660f775 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +--- +collections: + - name: community.docker