Skip to content

Commit

Permalink
Push the container as molecule side-effect
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaassssiiee committed Mar 21, 2024
1 parent 4fe95ab commit ee9b3a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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
...
34 changes: 34 additions & 0 deletions molecule/resources/playbooks/side-effect.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# export DOCKER_REGISTRY
# export DOCKER_USERNAME
# export DOCKER_PASSWORD
- name: Commit, tag, and push Docker image
hosts: localhost
gather_facts: false
connection: local
vars:
docker_registry: "{{ lookup('env','DOCKER_REGISTRY') }}"
docker_username: "{{ lookup('env','DOCKER_USERNAME') }}"
docker_password: "{{ lookup('env','DOCKER_PASSWORD') }}"
image_name: "dockpack/{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
image_tag: "{{ lookup('pipe', 'date +%Y%m%d%H') }}" # Generates a datetime stamp
tasks:
- name: Commit the container
ansible.builtin.command:
cmd: "docker commit {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }} {{ image_name }}:{{ image_tag }}"
register: commit_output

- name: Log in to Docker registry

Check failure on line 21 in molecule/resources/playbooks/side-effect.yml

View workflow job for this annotation

GitHub Actions / lint

syntax-check[specific]

couldn't resolve module/action 'community.general.docker_login'. This often indicates a misspelling, missing collection, or incorrect module path.
community.general.docker_login:
username: "{{ docker_username }}"
password: "{{ docker_password }}"
registry_url: "{{ docker_registry | default(omit) }}"
ignore_errors: true

- name: Tag and push the Docker image
community.general.docker_image:
name: "{{ docker_registry }}{% if docker_registry | length > 1 %}/{% endif %}{{ image_name }}"
tag: "{{ image_tag }}"
push: true
source: local

0 comments on commit ee9b3a7

Please sign in to comment.