Inital Commit

This commit is contained in:
2023-07-07 06:38:14 +05:30
commit 0203e73cd1
21 changed files with 394 additions and 0 deletions

2
docker/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
app/package.json
app/pyproject.toml

23
docker/app/Dockerfile Normal file
View File

@ -0,0 +1,23 @@
FROM python:3.11
LABEL maintainer="Amritanshu <docker@tanshu.com>"
ADD https://git.tanshu.com/api/v1/repos/tanshu/gru/tags /tags.json
RUN git clone --single-branch --depth 1 --branch latest https://git.tanshu.com/tanshu/gru.git /app
# Install Poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | POETRY_HOME=/opt/poetry python && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false
WORKDIR /app
# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=false
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"
ENV PYTHONPATH=/app
EXPOSE 80
VOLUME /data
CMD ["poetry", "run", "python", "-m", "gru"]

3
docker/files/.env Normal file
View File

@ -0,0 +1,3 @@
HOST=0.0.0.0
PORT=80
FILE_PATH=/data/readings.csv

View File

@ -0,0 +1,13 @@
server {
listen 80;
server_name {{ http_host }};
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost:{{ host_port }};
}
}

75
docker/playbook.yml Executable file
View File

@ -0,0 +1,75 @@
#################################################
# DO Community Playbooks: Docker
#################################################
---
- hosts: gru
become: true
vars_files:
- "vars/gru.yml"
tasks:
- name: Copy dockerfile
synchronize:
src: app
dest: "/tmp/{{ host_directory }}"
- name: Build gru image
docker_image:
name: brewman:latest
build:
path: "/tmp/{{ host_directory }}/"
dockerfile: "/tmp/{{ host_directory }}/Dockerfile"
pull: yes
state: present
source: build
- name: Ensure Host Directory exists
file:
path: "/var/lib/{{ host_directory }}"
state: directory
- name: Upload the .env file
template:
src: "{{ env_file }}"
dest: "/var/lib/{{ host_directory }}/.env"
- name: Create gru container
docker_container:
name: "{{ host_directory }}"
image: gru:latest
state: started
restart_policy: "unless-stopped"
env_file: "/var/lib/{{ host_directory }}/.env"
published_ports:
- "127.0.0.1:{{ host_port }}:80"
volumes:
- "/var/lib/{{ host_directory }}:/data"
- 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

6
docker/vars/gru.yml Normal file
View File

@ -0,0 +1,6 @@
---
http_host: "sensors.tanshu.com"
http_conf: "sensors.tanshu.com.conf"
host_port: "8745"
host_directory: "sensors"
env_file: "files/.env"