From 77d5fa8eda9ad29b3bbe65b1ff611662c00e8d7d Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Mon, 2 Jan 2023 12:23:09 +0530 Subject: [PATCH] Added: Tandoor for recipes --- tandoor/files/.env | 7 ++++ tandoor/files/nginx.conf.j2 | 13 +++++++ tandoor/playbook.yml | 73 +++++++++++++++++++++++++++++++++++++ tandoor/readme.md | 45 +++++++++++++++++++++++ tandoor/vars/default.yml | 9 +++++ 5 files changed, 147 insertions(+) create mode 100644 tandoor/files/.env create mode 100644 tandoor/files/nginx.conf.j2 create mode 100755 tandoor/playbook.yml create mode 100644 tandoor/readme.md create mode 100644 tandoor/vars/default.yml diff --git a/tandoor/files/.env b/tandoor/files/.env new file mode 100644 index 0000000..911722c --- /dev/null +++ b/tandoor/files/.env @@ -0,0 +1,7 @@ +SECRET_KEY=7ukvcoUnuyhPK6Nds3KbwG+3zeYuJGTDyi0ohFJqMwgjrdwBxn% +DB_ENGINE=django.db.backends.postgresql +POSTGRES_HOST=db +POSTGRES_PORT=5432 +POSTGRES_USER=postgres +POSTGRES_PASSWORD=123456 +POSTGRES_DB=tandoor diff --git a/tandoor/files/nginx.conf.j2 b/tandoor/files/nginx.conf.j2 new file mode 100644 index 0000000..2e6be92 --- /dev/null +++ b/tandoor/files/nginx.conf.j2 @@ -0,0 +1,13 @@ +server { + + listen 80; + server_name {{ http_host }}; + + location / { + proxy_pass http://localhost:8880; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/tandoor/playbook.yml b/tandoor/playbook.yml new file mode 100755 index 0000000..84e4fe6 --- /dev/null +++ b/tandoor/playbook.yml @@ -0,0 +1,73 @@ +################################################# +# DO Community Playbooks: Docker +################################################# +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: + - name: Pull Tandoor.dev image + docker_image: + name: "{{ image_name }}" + source: pull + state: present + force_source: yes + + - name: Ensure Host Directory exists + file: + path: "/var/lib/{{ host_directory }}" + state: directory + group: www-data + owner: www-data + mode: 0655 + + - name: Upload the .env file + template: + src: "files/.env" + dest: "/var/lib/{{ host_directory }}/.env" + + - name: Create Tandoor.dev container + docker_container: + name: "{{ container_name }}" + image: "{{ image_name }}" + state: started + restart_policy: "unless-stopped" + env_file: "/var/lib/{{ host_directory }}/.env" + links: + - "postgres:db" + published_ports: + - "127.0.0.1:8880:8080" + volumes: + - "/var/lib/{{ host_directory }}/staticfiles:/opt/recipes/staticfiles" + - "/var/lib/{{ host_directory }}/mediafiles:/opt/recipes/mediafiles" + - "/var/lib/{{ host_directory }}/externalfiles:/opt/recipes/externalfiles" + + - name: Check if Nginx conf file exists + stat: path="/etc/nginx/sites-available/{{ http_conf }}" + register: status + + - name: No need to reload Nginx + debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }} + + - name: Set Nginx conf file + when: status.stat.exists == false + template: + src: "files/nginx.conf.j2" + dest: "/etc/nginx/sites-available/{{ http_conf }}" + + - name: Enable new site + when: status.stat.exists == false + file: + src: "/etc/nginx/sites-available/{{ http_conf }}" + dest: "/etc/nginx/sites-enabled/{{ http_conf }}" + state: link + notify: Reload Nginx + + handlers: + - name: Reload Nginx + service: + name: nginx + state: reloaded + diff --git a/tandoor/readme.md b/tandoor/readme.md new file mode 100644 index 0000000..2be90cb --- /dev/null +++ b/tandoor/readme.md @@ -0,0 +1,45 @@ +# Gitea on Ubuntu + +This playbook will install Gitea on an Ubuntu 19.10 machine. +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). diff --git a/tandoor/vars/default.yml b/tandoor/vars/default.yml new file mode 100644 index 0000000..3493f55 --- /dev/null +++ b/tandoor/vars/default.yml @@ -0,0 +1,9 @@ +--- +http_host: "recipes.tanshu.com" +http_conf: "recipes.tanshu.com.conf" +http_url: "https://recipes.tanshu.com" + +container_name: tandoor +image_name: vabene1111/recipes:latest + +host_directory: tandoor