Bifrost deployed using ansible

This commit is contained in:
tanshu 2020-05-04 17:04:09 +05:30
parent fc8a7795e6
commit 02cc1dafe5
7 changed files with 164 additions and 2 deletions

9
bifrost/app/.env Normal file
View File

@ -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

14
bifrost/app/Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM python:latest
LABEL maintainer="Amritanshu <docker@tanshu.com>"
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"]

View File

@ -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 }};
}
}

69
bifrost/playbook.yml Executable file
View File

@ -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

46
bifrost/readme.md Normal file
View File

@ -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).

5
bifrost/vars/default.yml Normal file
View File

@ -0,0 +1,5 @@
---
http_host: "bifrost.tanshu.com"
http_conf: "bifrost.tanshu.com.conf"
host_port: "8123"

View File

@ -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/