build: update deployment for Docker

This commit is contained in:
James Graham
2022-03-17 13:58:07 +00:00
parent ba6701ee67
commit 055e1080dd
9 changed files with 150 additions and 28 deletions

29
deploy/Vagrantfile vendored Normal file
View File

@@ -0,0 +1,29 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "centos/7"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
config.vm.network "forwarded_port", guest: 80, host: 8888, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 443, host: 8889, host_ip: "127.0.0.1"
# Provision VM using Ansible playbook
config.vm.provision "ansible" do |ansible|
ansible.verbose = "v"
ansible.playbook = "playbook.yml"
ansible.host_vars = {
"default" => {
"deploy_environment" => "vagrant"
}
}
end
end

85
deploy/playbook.yml Normal file
View File

@@ -0,0 +1,85 @@
---
- hosts: all
become_user: root
become_method: sudo
become: yes
pre_tasks:
- name: Check if running under Vagrant
stat:
path: /vagrant
register: vagrant_dir
vars:
project_name: mapper
project_dir: /srv/{{ project_name }}
project_src_dir: "{{ project_dir }}/src"
django_settings:
debug: 1
secret_key: debug_only_g62WlORMbo8iAcV7vKCKBQ==
tasks:
- name: Vagrant specific tasks
block:
- name: Add Docker repository
get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: '/etc/yum.repos.d/docker-ce.repo'
when: deploy_environment is defined and deploy_environment == "vagrant"
- name: Install system dependencies
ansible.builtin.yum:
name:
- git
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
state: present
# - name: Update system packages
# ansible.builtin.yum:
# name: '*'
# state: latest
- name: Clone / update from source repos
ansible.builtin.git:
repo: 'https://github.com/Southampton-RSG/breccia-mapper.git'
dest: '{{ project_src_dir }}'
version: docker
accept_hostkey: yes
- name: Copy template files
ansible.builtin.template:
src: '{{ item }}.j2'
dest: '{{ project_dir }}/{{ item }}'
mode: 0600
loop:
- Caddyfile
- docker-compose.yml
- name: Start Docker
ansible.builtin.systemd:
name: docker
state: started
enabled: yes
- name: Pull latest docker images
ansible.builtin.command:
chdir: "{{ project_dir }}"
cmd: docker compose pull {{ item }}
loop:
- caddy
- name: Build custom images
ansible.builtin.command:
chdir: "{{ project_dir }}"
cmd: docker compose build {{ item }}
loop:
- web
- name: Start containers
ansible.builtin.command:
chdir: "{{ project_dir }}"
cmd: docker compose up -d

View File

@@ -0,0 +1,15 @@
:80 :443 {
root * /srv
file_server
@proxy_paths {
not path /static/*
}
reverse_proxy @proxy_paths http://web:8000
log {
output stderr
format single_field common_log
}
}

View File

@@ -0,0 +1,35 @@
version: '3.1'
services:
web:
image: breccia-mapper
build: {{ project_src_dir }}
ports:
- 8000:8000
environment:
DEBUG: {{ django_settings.debug }}
DATABASE_URL: sqlite:////app/db.sqlite3
SECRET_KEY: {{ django_settings.secret_key }}
volumes:
- ./db.sqlite3:/app/db.sqlite3:z
- static_files:/app/static
caddy:
image: caddy:2
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:z
# Caddy serves static files collected by Django
- static_files:/srv/static:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- web
volumes:
caddy_data:
caddy_config:
static_files: