Skip to content

Commit

Permalink
Push the container as molecule side-effect
Browse files Browse the repository at this point in the history
Signed-off-by: Bas Meijer <[email protected]>
  • Loading branch information
bbaassssiiee committed Mar 21, 2024
1 parent 4fe95ab commit eb968d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
extends: default

rules:
line-length:
max: 160
truthy:
check-keys: false
3 changes: 2 additions & 1 deletion molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
...
25 changes: 25 additions & 0 deletions molecule/resources/playbooks/side-effect.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
collections:
- name: community.docker

0 comments on commit eb968d1

Please sign in to comment.