From 5b8d77c839454f8a6e8e100ff0d9915962b878e6 Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Thu, 31 Jul 2025 11:14:47 +0000 Subject: [PATCH] Added caddy docker --- caddy-menu/files/Caddyfile.j2 | 29 ++++++++++++++++++++++ caddy-menu/playbook.yml | 33 +++++++++++++++++++++++++ caddy-menu/readme.md | 46 +++++++++++++++++++++++++++++++++++ caddy-menu/vars/default.yml | 7 ++++++ caddy/playbook.yml | 44 +++++++++++++++++++++++++++++++++ caddy/readme.md | 46 +++++++++++++++++++++++++++++++++++ caddy/vars/default.yml | 5 ++++ 7 files changed, 210 insertions(+) create mode 100644 caddy-menu/files/Caddyfile.j2 create mode 100755 caddy-menu/playbook.yml create mode 100644 caddy-menu/readme.md create mode 100644 caddy-menu/vars/default.yml create mode 100755 caddy/playbook.yml create mode 100644 caddy/readme.md create mode 100644 caddy/vars/default.yml diff --git a/caddy-menu/files/Caddyfile.j2 b/caddy-menu/files/Caddyfile.j2 new file mode 100644 index 0000000..0e91bcd --- /dev/null +++ b/caddy-menu/files/Caddyfile.j2 @@ -0,0 +1,29 @@ +{ + auto_https off + servers { + trusted_proxies static private_ranges + } +} + +:80 { + handle /bar/* { + root * /srv/bar + try_files {path} index.html + file_server + } + handle /food* { + root * /srv/food + try_files {path} /index.html + file_server + } + handle /delivery/* { + root * /srv/deliver + try_files {path} index.html + file_server + } + handle /qr/* { + root * /srv/qr + try_files {path} index.html + file_server + } +} \ No newline at end of file diff --git a/caddy-menu/playbook.yml b/caddy-menu/playbook.yml new file mode 100755 index 0000000..be6d9e6 --- /dev/null +++ b/caddy-menu/playbook.yml @@ -0,0 +1,33 @@ +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: + - name: Pull Caddy image + docker_image: + name: "{{ caddy_image }}" + source: pull + force_source: yes + + - name: Ensure Host Directory exist + file: + path: "{{ host_directory }}" + state: directory + mode: 0755 + + - name: Upload the Caddyfile file + template: + src: "files/Caddyfile.j2" + dest: "{{ host_directory }}/Caddyfile" + + - name: Create caddy container + docker_container: + name: "{{ caddy_name }}" + image: "{{ caddy_image }}" + state: started + restart_policy: unless-stopped + volumes: + - "{{ host_directory }}/Caddyfile:/etc/caddy/Caddyfile:ro" + - "{{ host_directory }}:/srv" diff --git a/caddy-menu/readme.md b/caddy-menu/readme.md new file mode 100644 index 0000000..f6d7ecc --- /dev/null +++ b/caddy-menu/readme.md @@ -0,0 +1,46 @@ +# Docker on Ubuntu 18.04 + +This playbook will install Docker an Ubuntu 18.04 machine, as explained in the guide on +[How to Use Ansible to Install and Set Up Docker on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04). +A number of containers will be created with the options specified in the `vars/default.yml` variable file. + +## Settings + +- `create_containers`: number of containers to create. +- `default_container_name`: default name for new containers. +- `default_container_image`: default image for new containers. +- `default_container_command`: default command to run on new containers. + + +## Running this Playbook + +Quick Steps: + +### 1. Obtain the playbook +```shell +git clone https://github.com/do-community/ansible-playbooks.git +cd ansible-playbooks/docker_ubuntu1804 +``` + +### 2. Customize Options + +```shell +nano vars/default.yml +``` + +```yml +#vars/default.yml +--- +create_containers: 4 +default_container_name: docker +default_container_image: ubuntu +default_container_command: sleep 1d +``` + +### 3. Run the Playbook + +```command +ansible-playbook -l [target] -i [inventory file] -u [remote user] playbook.yml +``` + +For more information on how to run this Ansible setup, please check this guide: [How to Use Ansible to Install and Set Up Docker on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04). \ No newline at end of file diff --git a/caddy-menu/vars/default.yml b/caddy-menu/vars/default.yml new file mode 100644 index 0000000..a7e9ab9 --- /dev/null +++ b/caddy-menu/vars/default.yml @@ -0,0 +1,7 @@ +--- +title: hopsngrains.com +host: "menu.{{ title }}" +caddy_name: "caddy-{{ host }}" +caddy_image: caddy:alpine + +host_directory: "/var/lib/{{ host }}" diff --git a/caddy/playbook.yml b/caddy/playbook.yml new file mode 100755 index 0000000..03e298e --- /dev/null +++ b/caddy/playbook.yml @@ -0,0 +1,44 @@ +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: + - name: Pull Caddy image + docker_image: + name: "{{ caddy_image }}" + source: pull + force_source: yes + + - name: Ensure Caddy Directories exist + file: + path: "/var/lib/{{ host_directory }}/{{ item }}" + state: directory + mode: 0755 + loop: + - conf + - site + - data + - config + + - name: Ensure Caddyfile exists + file: + path: "/var/lib/{{ host_directory }}/conf/Caddyfile" + state: touch + mode: 0644 + + - name: Create caddy container + docker_container: + name: "{{ caddy_name }}" + image: "{{ caddy_image }}" + state: started + restart_policy: unless-stopped + ports: + - "80:80" + - "443:443" + volumes: + - "/var/lib/{{ host_directory }}/conf:/etc/caddy" + - "/var/lib/{{ host_directory }}/site:/srv" + - "/var/lib/{{ host_directory }}/data:/data" + - "/var/lib/{{ host_directory }}/config:/config" diff --git a/caddy/readme.md b/caddy/readme.md new file mode 100644 index 0000000..f6d7ecc --- /dev/null +++ b/caddy/readme.md @@ -0,0 +1,46 @@ +# Docker on Ubuntu 18.04 + +This playbook will install Docker an Ubuntu 18.04 machine, as explained in the guide on +[How to Use Ansible to Install and Set Up Docker on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04). +A number of containers will be created with the options specified in the `vars/default.yml` variable file. + +## Settings + +- `create_containers`: number of containers to create. +- `default_container_name`: default name for new containers. +- `default_container_image`: default image for new containers. +- `default_container_command`: default command to run on new containers. + + +## Running this Playbook + +Quick Steps: + +### 1. Obtain the playbook +```shell +git clone https://github.com/do-community/ansible-playbooks.git +cd ansible-playbooks/docker_ubuntu1804 +``` + +### 2. Customize Options + +```shell +nano vars/default.yml +``` + +```yml +#vars/default.yml +--- +create_containers: 4 +default_container_name: docker +default_container_image: ubuntu +default_container_command: sleep 1d +``` + +### 3. Run the Playbook + +```command +ansible-playbook -l [target] -i [inventory file] -u [remote user] playbook.yml +``` + +For more information on how to run this Ansible setup, please check this guide: [How to Use Ansible to Install and Set Up Docker on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04). \ No newline at end of file diff --git a/caddy/vars/default.yml b/caddy/vars/default.yml new file mode 100644 index 0000000..7fab30f --- /dev/null +++ b/caddy/vars/default.yml @@ -0,0 +1,5 @@ +--- +caddy_name: caddy +caddy_image: caddy:alpine + +host_directory: caddy