From 02cc1dafe599f7ceeba7ad79669568aa83970ccc Mon Sep 17 00:00:00 2001 From: tanshu Date: Mon, 4 May 2020 17:04:09 +0530 Subject: [PATCH] Bifrost deployed using ansible --- bifrost/app/.env | 9 +++++ bifrost/app/Dockerfile | 14 ++++++++ bifrost/files/nginx.conf.j2 | 19 ++++++++++ bifrost/playbook.yml | 69 +++++++++++++++++++++++++++++++++++++ bifrost/readme.md | 46 +++++++++++++++++++++++++ bifrost/vars/default.yml | 5 +++ bitwarden/playbook.yml | 4 +-- 7 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 bifrost/app/.env create mode 100644 bifrost/app/Dockerfile create mode 100644 bifrost/files/nginx.conf.j2 create mode 100755 bifrost/playbook.yml create mode 100644 bifrost/readme.md create mode 100644 bifrost/vars/default.yml diff --git a/bifrost/app/.env b/bifrost/app/.env new file mode 100644 index 0000000..0edd87d --- /dev/null +++ b/bifrost/app/.env @@ -0,0 +1,9 @@ +API_URL_BASE=https://api.digitalocean.com/v2 +API_TOKEN=daf49849af95f3a06e5e235d8ae8a56c25cf35c0c5ab4b88baa559aac45d8bb5 +HTPASSWD=/app/.htpasswd +HOST=0.0.0.0 +PORT=80 +LOG_LEVEL=info +DEBUG=true + +MODULE_NAME=bifrost.main diff --git a/bifrost/app/Dockerfile b/bifrost/app/Dockerfile new file mode 100644 index 0000000..6994c1b --- /dev/null +++ b/bifrost/app/Dockerfile @@ -0,0 +1,14 @@ +FROM python:latest + +LABEL maintainer="Amritanshu " + +RUN git clone https://git.tanshu.com/tanshu/bifrost.git /app && pip install --no-cache-dir --requirement /app/requirements.txt && pip install /app + +COPY ./.env /app +WORKDIR /app/ + +ENV PYTHONPATH=/app + +EXPOSE 80 + +CMD ["python", "-m", "bifrost"] diff --git a/bifrost/files/nginx.conf.j2 b/bifrost/files/nginx.conf.j2 new file mode 100644 index 0000000..686f755 --- /dev/null +++ b/bifrost/files/nginx.conf.j2 @@ -0,0 +1,19 @@ +server { + + listen 80; + server_name {{ http_host }}; + + # set max upload size + client_max_body_size 10G; + + location / { + + proxy_set_header Host $host:$server_port; + proxy_set_header X-Scheme $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always; + proxy_pass http://localhost:{{ host_port }}; + } + +} + diff --git a/bifrost/playbook.yml b/bifrost/playbook.yml new file mode 100755 index 0000000..84794d8 --- /dev/null +++ b/bifrost/playbook.yml @@ -0,0 +1,69 @@ +################################################# +# DO Community Playbooks: Docker +################################################# +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: + - name: Copy dockerfile + synchronize: src=app dest=/tmp + + - name: Build bifrost image + docker_image: + name: bifrost:latest + build: + path: /tmp/app/ + dockerfile: /tmp/app/Dockerfile + pull: yes + state: present + source: build + + - name: ensure that .htpasswd file exists + copy: + content: "" + dest: /var/lib/bifrost/.htpasswd + force: no + + - name: Create bifrost container + docker_container: + name: bifrost + image: bifrost:latest + state: started + restart_policy: "unless-stopped" + env_file: /tmp/app/.env + published_ports: + - "127.0.0.1:{{ host_port }}:80" + volumes: + - /var/lib/bifrost/.htpasswd:/app/.htpasswd:ro + + + - 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/bifrost/readme.md b/bifrost/readme.md new file mode 100644 index 0000000..f6d7ecc --- /dev/null +++ b/bifrost/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/bifrost/vars/default.yml b/bifrost/vars/default.yml new file mode 100644 index 0000000..b70293d --- /dev/null +++ b/bifrost/vars/default.yml @@ -0,0 +1,5 @@ +--- +http_host: "bifrost.tanshu.com" +http_conf: "bifrost.tanshu.com.conf" +host_port: "8123" + diff --git a/bitwarden/playbook.yml b/bitwarden/playbook.yml index da8be16..5c126bb 100755 --- a/bitwarden/playbook.yml +++ b/bitwarden/playbook.yml @@ -23,8 +23,8 @@ DATABASE_URL: "{{ db_url }}" links: "postgres:db" published_ports: - - 8080:80 - - 3012:3012 + - 127.0.0.1:8080:80 + - 127.0.0.1:3012:3012 volumes: - /var/lib/bitwarden/data:/data/