Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from bec-galaxy/develop
Browse files Browse the repository at this point in the history
Refactoring and Bugfix
  • Loading branch information
patbec authored Nov 4, 2023
2 parents 896c33e + 7e4c7d4 commit 2510054
Show file tree
Hide file tree
Showing 25 changed files with 297 additions and 58 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
A collection to install **Docker** and configuring an **application stack**.

The following steps are supported:
- Distribute a shared `docker-compose.yml` by using the template function.
- Distribute encrypted secrets through an `.env` file.
- Distribute files and folders for a mapped volume.

* Distribute a shared `docker-compose.yml` by using the template function.
* Distribute encrypted secrets through an `.env` file.
* Distribute files and folders for a mapped volume.

[Click here to go to the documentation](https://github.com/bec-galaxy/ansible-collection-docker/tree/main/roles/docker_compose).

Expand Down
18 changes: 17 additions & 1 deletion changelogs/changelog.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
---
releases: {}
releases:
1.1.0:
changes:
minor_changes:
- Added unit test for .j2 extensions.
- Use Vagrant in a 2nd unit tests for better code coverage.
- Better log output for copied files.
breaking_changes:
- Permissions on copied files are now set recursively.
For templates community.general.filetree was used, here it worked as expected.
For files ansible.builtin.copy was used, here the problem occurred. Now filetree is used everywhere.
- Filename of the Docker repository has changed to docker.list, before that the
download name of the file was used.
bugfixes:
- Files in the shared folder are now templated with the correct subpath.
- Removing the .j2 extension only at the end of the filename.
release_date: "2023-10-03"
18 changes: 9 additions & 9 deletions docs/example_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace: bec
name: docker

version: 1.0.0
version: 1.1.0
readme: README.md
authors:
- Patrick Becker <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
requires_ansible: ">=2.9.10"
requires_ansible: ">=2.14.0"
2 changes: 1 addition & 1 deletion molecule/default/files/docker/instance/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NGINX_PORT=80
NGINX_PORT=80
10 changes: 6 additions & 4 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ dependency:
driver:
name: docker
platforms:
# - name: ubuntu-23.04
# image: ubuntu:23.04
# - name: ubuntu-22.04
# image: ubuntu:22.04
- name: ubuntu-20.04
image: ubuntu:20.04
- name: ubuntu-22.04
image: ubuntu:22.04
# - name: debian-12
# image: debian:12
- name: debian-11
image: debian:11
- name: debian-10
image: debian:10
provisioner:
name: ansible
config_options:
Expand Down
19 changes: 18 additions & 1 deletion molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
ansible.builtin.assert:
that:
- docker_compose_hash is defined
- docker_compose_hash.stdout == "nginx 7b99edc1470b82c23cbd630f2c4714c8837519f788c752f4fcca92d975a30390"
- docker_compose_hash.stdout == "nginx c6c17a5aec732e20a5801f975edce845069526c172df5ffba6cf9a773101011a"
fail_msg: "Required Docker compose files are missing or incomplete."
success_msg: "Required Docker compose files were successfully verified."

- name: Ensure templates have been copied
block:
- name: Get file stats
ansible.builtin.stat:
path: "/opt/docker/data/shared.html"
register: file_info

- name: Verify file stats
ansible.builtin.assert:
that:
- file_info is defined
- file_info.stat is defined
- file_info.stat.exists == true
- file_info.stat.isdir == false
fail_msg: "File 'shared.html' was not found."
success_msg: "File 'shared.html' has passed."
4 changes: 4 additions & 0 deletions molecule/vagrant/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
collections:
- community.docker
- community.general
27 changes: 27 additions & 0 deletions molecule/vagrant/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
- name: Converge
hosts: all
vars:
# Use one source folder for all hosts.
docker_compose_environment: "files/docker/instance"

# Use executable rights for the nginx html folder.
docker_compose_permissions: "0755"
tasks:
- name: "Include role"
ansible.builtin.include_role:
name: "bec.docker.docker_ce"

- name: "Include role"
ansible.builtin.include_role:
name: "bec.docker.docker_compose"

- name: Output information about the Docker login step
when: docker_login is defined
ansible.builtin.debug:
var: docker_login

- name: Output information about the Docker compose step
when: docker_compose is defined
ansible.builtin.debug:
var: docker_compose
1 change: 1 addition & 0 deletions molecule/vagrant/files/docker/instance/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NGINX_PORT=80
15 changes: 15 additions & 0 deletions molecule/vagrant/files/docker/instance/data/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<title>Hello World</title>
</head>

<body>
<p>Molecule test was successful.</p>
</body>

</html>
50 changes: 50 additions & 0 deletions molecule/vagrant/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
dependency:
name: galaxy
driver:
name: vagrant
platforms:
# - name: ubuntu-23.04
# box: generic/ubuntu2304
# memory: 4096
# cpus: 2
# provider_options:
# linked_clone: true
# config_options:
# ssh.keep_alive: true
- name: ubuntu-22.04
box: generic/ubuntu2204
memory: 4096
cpus: 2
provider_options:
linked_clone: true
config_options:
ssh.keep_alive: true
- name: ubuntu-20.04
box: generic/ubuntu2004
memory: 4096
cpus: 4
provider_options:
linked_clone: true
config_options:
ssh.keep_alive: true
# - name: debian-12
# box: generic/debian12
# memory: 4096
# cpus: 4
# provider_options:
# linked_clone: true
# config_options:
# ssh.keep_alive: true
- name: debian-11
box: generic/debian11
memory: 4096
cpus: 4
provider_options:
linked_clone: true
config_options:
ssh.keep_alive: true
provisioner:
name: ansible
scenario:
name: vagrant
15 changes: 15 additions & 0 deletions molecule/vagrant/templates/shared/data/.j2-test/.j2-file.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<title>Hello World</title>
</head>

<body>
<p>Ensure that the .j2 extension is removed only at the end of the path.</p>
</body>

</html>
15 changes: 15 additions & 0 deletions molecule/vagrant/templates/shared/data/shared.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<title>Hello World</title>
</head>

<body>
<p>{{ ansible_managed }}</p>
</body>

</html>
11 changes: 11 additions & 0 deletions molecule/vagrant/templates/shared/docker-compose.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: '3.9'
services:
nginx:
container_name: nginx
image: nginx:1.24.0-alpine
restart: unless-stopped
volumes:
- /opt/docker/data:/usr/share/nginx/html:ro
ports:
- 80:${NGINX_PORT}/tcp
29 changes: 29 additions & 0 deletions molecule/vagrant/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
# This step checks the following things:
#
# - Was the docker-compose templates copied?
# - Was the .env file copied? (Defines NGINX_PORT=80)
# - Was the .env file found by docker-compose and the variables inserted?
# - Was the container started correctly?
#
- name: Download nginx website index.html
ansible.builtin.get_url:
url: http://localhost/index.html
dest: /tmp/index.html
mode: "0644"
checksum: "sha256:588c119d7665f1240a6b2814ca8abab3e8ccd65b618091df55c413530eceb90c"

# Ensure that the .j2 extension is removed only at the end of the path.
#
# .j2-test/.j2-file.html.j2 -> .j2-test/.j2-file.html
#
- name: Download test website .j2-file.html
ansible.builtin.get_url:
url: http://localhost/.j2-test/.j2-file.html
dest: /tmp/.j2-file.html
mode: "0644"
checksum: "sha256:6e4798029dc7fc82ff9b6904eaa735012dc51a9a93e015a25e74478436ae9157"
3 changes: 1 addition & 2 deletions roles/docker_ce/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
galaxy_info:
author: Patrick Becker <[email protected]>
description: Install docker from the official repository.
description: Install Docker from the official repository.
license: MIT

min_ansible_version: "2.13"
Expand All @@ -10,7 +10,6 @@ galaxy_info:
- name: Debian
versions:
- bullseye
- buster
- name: Ubuntu
versions:
- jammy
Expand Down
10 changes: 4 additions & 6 deletions roles/docker_ce/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@

- name: Add Docker apt-repository
ansible.builtin.apt_repository:
repo: "deb {{ signature }} https://download.docker.com/linux/{{ distribution }} {{ release }} stable"
filename: docker
repo: "{{ lookup('ansible.builtin.template', 'docker.list.j2') }}"
state: present
update_cache: true
become: true
vars:
signature: "[arch=amd64 signed-by=/usr/share/keyrings/docker.asc]"
distribution: "{{ ansible_distribution | lower }}"
release: "{{ ansible_distribution_release | lower }}"
tags:
- docker
- setup
Expand Down Expand Up @@ -46,7 +43,7 @@
- docker
- setup

- name: Ensure python modules are installed
- name: Ensure Python modules are installed
when: not ansible_check_mode
ansible.builtin.pip:
name:
Expand All @@ -66,4 +63,5 @@
become: true
tags:
- docker
- setup
- service
1 change: 1 addition & 0 deletions roles/docker_ce/templates/docker.list.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb [arch=amd64 signed-by=/usr/share/keyrings/docker.asc] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }} stable
Loading

0 comments on commit 2510054

Please sign in to comment.