Skip to content

Commit

Permalink
feat: host outline with Docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed Jul 26, 2024
1 parent 8d4e09b commit 3c2844f
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 222 deletions.
1 change: 1 addition & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ stdout_callback = yaml
roles_path = roles/

vars_plugins = ./plugins/vars
error_on_undefined_vars = True
1 change: 1 addition & 0 deletions ansible/group_vars/production/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ secret_outline:
s3_secret_access_key: "{{ vault_secret_outline.s3_secret_access_key }}"
s3_bucket: "outline-wiki-prod"
mailgun_password: "{{ vault_secret_outline.mailgun_password }}"
postgresql_password: "{{ vault_secret_outline.postgresql_password }}"

secret_koala_manual:
password: "{{ vault_secret_koala_manual.password }}"
Expand Down
1 change: 1 addition & 0 deletions ansible/group_vars/staging/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ secret_outline:
s3_secret_access_key: "{{ vault_secret_outline.s3_secret_access_key }}"
s3_bucket: "outline-wiki-staging"
mailgun_password: "{{ vault_secret_outline.mailgun_password }}"
postgresql_password: "{{ vault_secret_outline.postgresql_password }}"

secret_koala_manual:
password: "{{ vault_secret_koala_manual.password }}"
Expand Down
31 changes: 15 additions & 16 deletions ansible/roles/docker/tasks/compose-up.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
---
# NOTE These tasks expect the 'project_source' variable to be set

- name: "Check if Docker daemon is active"
shell: "systemctl is-active docker"
register: "docker_status"
ignore_errors: "yes" # Will give a non-zero error code if not active
- name: "Gather service facts"
ansible.builtin.service_facts:

- name: "Assert Docker daemon is running"
assert:
that:
- "docker_status.rc == 0"
fail_msg: "Docker daemon is not running"
success_msg: "Docker daemon is running"
- name: "Assert that Docker daemon is active, but do not start it"
ansible.builtin.assert:
that: "ansible_facts.services['docker'].state == 'running'"

- name: "Tear down existing services"
community.docker.docker_compose_v2:
Expand All @@ -32,19 +27,23 @@
project_src: "{{ project_source }}"
register: "output"

# - name: Show results
# ansible.builtin.debug:
# var: output

- name: "Assert that all services properly started"
ansible.builtin.assert:
that: "not output.changed"

# Remember what services are included in the compose file, for later
# Remember what services are included in the compose file, for later
- name: "Extract service names from output"
set_fact:
ansible.builtin.set_fact:
docker_compose_service_names: "{{ output.containers | map(attribute='Name') | list }}"

# - name: Show docker results
# ansible.builtin.debug:
# var: output

# - name: Show parsed services
# ansible.builtin.debug:
# var: docker_compose_service_names

- name: "Stop all services"
community.docker.docker_compose_v2:
project_src: "{{ project_source }}"
Expand Down
26 changes: 0 additions & 26 deletions ansible/roles/outline/handlers/main.yml

This file was deleted.

69 changes: 26 additions & 43 deletions ansible/roles/outline/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,58 @@
---
- name: "create outline user"
- name: "Create outline user"
ansible.builtin.user:
name: "outline"
state: "present"
shell: "/bin/false"
system: true
home: "/var/www/outline"
move_home: true
system: true
shell: "/sbin/nologin"
password: "!"

- name: "create outline directory"
- name: "Create outline directory"
ansible.builtin.file:
path: "/var/www/outline/outline"
path: "{{ outline_project_source }}"
state: "directory"
owner: "outline"
group: "outline"

- name: "do database setup"
- name: "Do database setup"
become_user: "postgres"
become: true
block:
- name: "ensure Postgres role exists"
- name: "Ensure Postgres role exists"
community.postgresql.postgresql_user:
name: "outline"
password: "{{ secret_outline.postgresql_password }}" # Sadly seems required to make authentication over localhost work, for peer authentication fails somehow
state: "present"

- name: "ensure database exists"
- name: "Ensure database exists"
community.postgresql.postgresql_db:
name: "outline"
owner: "outline"
state: "present"

- name: "ensure config directory exists"
ansible.builtin.file:
path: "/etc/outline"
state: "directory"

- name: "create environment file"
- name: "Create outline 'docker-compose.yml' file"
ansible.builtin.template:
src: "outline.env.j2"
dest: "/etc/outline/outline.env"
owner: "root"
src: "docker-compose.yml.j2"
dest: "{{ outline_project_source }}/docker-compose.yml"
owner: "outline"
group: "outline"
mode: "0600"
notify: "restart outline"

- name: "clone repo and do Yarn stuff"
become_user: "outline"
become: true
ansible.builtin.git:
repo: "https://github.com/svsticky/Sticky-Compendium.git"
dest: "/var/www/outline/outline"
version: "main"
notify:
- "yarn install"
- "yarn build"
- "restart outline"

- name: "install Systemd service"
- name: "Create outline 'docker.env' file"
ansible.builtin.template:
src: "outline.service.j2"
dest: "/etc/systemd/system/outline.service"
owner: "root"
mode: "0644"
notify: "restart outline"
src: "docker.env.j2"
dest: "{{ outline_project_source }}/docker.env"
owner: "outline"
group: "outline"
mode: "0600"

- name: "ensure outline service is started and enabled"
ansible.builtin.systemd:
name: "outline.service"
state: "started"
enabled: true
- name: "Docker compose"
ansible.builtin.include_tasks: "../docker/tasks/compose-up.yml"
vars:
project_source: "{{ outline_project_source }}"

- name: "install nginx config"
- name: "Install nginx config"
ansible.builtin.template:
src: "outline.conf.j2"
dest: "/etc/nginx/sites-enabled/outline.conf"
Expand Down
71 changes: 71 additions & 0 deletions ansible/roles/outline/templates/docker-compose.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
services:

outline:
image: outlinewiki/outline:0.78.0
env_file: ./docker.env
# ports:
# - "4568:3000"
network_mode: host # TODO replace this
volumes:
- storage-data:/var/lib/outline/data
# depends_on:
# - postgres
# - redis

# redis:
# image: redis
# env_file: ./docker.env
# ports:
# - "6379:6379"
# volumes:
# - ./redis.conf:/redis.conf
# command: ["redis-server", "/redis.conf"]
# healthcheck:
# test: ["CMD", "redis-cli", "ping"]
# interval: 10s
# timeout: 30s
# retries: 3

# postgres:
# image: postgres
# env_file: ./docker.env
# ports:
# - "5432:5432"
# volumes:
# - database-data:/var/lib/postgresql/data
# healthcheck:
# test: ["CMD", "pg_isready", "-d", "outline", "-U", "user"]
# interval: 30s
# timeout: 20s
# retries: 3
# environment:
# POSTGRES_USER: 'user'
# POSTGRES_PASSWORD: 'pass'
# POSTGRES_DB: 'outline'

# https-portal:
# image: steveltn/https-portal
# env_file: ./docker.env
# ports:
# - '80:80'
# - '443:443'
# links:
# - outline
# restart: always
# volumes:
# - https-portal-data:/var/lib/https-portal
# healthcheck:
# test: ["CMD", "service", "nginx", "status"]
# interval: 30s
# timeout: 20s
# retries: 3
# environment:
# DOMAINS: 'docs.mycompany.com -> http://outline:3000'
# STAGE: 'production'
# WEBSOCKET: 'true'
# CLIENT_MAX_BODY_SIZE: '0'

volumes:
# https-portal-data:
storage-data:
# database-data:
Loading

0 comments on commit 3c2844f

Please sign in to comment.