Add docker-compose installation

This commit is contained in:
moanos [he/him] 2023-11-10 14:47:57 +01:00
parent d11bfc25dd
commit 5f94ee8409
4 changed files with 71 additions and 14 deletions

View File

@ -1,13 +1,13 @@
# Static Site Host - Ansible playbook
This is an [Ansible](https://www.ansible.com/) playbook which allows you to set up a server to serve static sites that will be deployed via CI.
This is an [Ansible](https://www.ansible.com/) playbook which allows you to set up a server to serve static sites via [Static Web Server](https://github.com/static-web-server/static-web-server). Everything will be ready for your site to be deployed using your CI.
## Getting started
Create an file listing the repository host in `inventory/hosts`. You snouldn't put every domain that you intend to use as static site in there, only one domain per server.
Create an file listing the repository host in `inventory/hosts`. You shouldn't put every domain that you intend to use as static site in there, only one domain per server.
```
[stitic_site_servers]
[static_site_servers]
static.example.org
```

View File

@ -2,18 +2,15 @@
# static_site_server sets up
static_site_server_enabled: true
static_site_server_identifier: static_site_server
static_container_network: "static"
static_site_user: 'static_site'
static_site_group: 'static_site'
sws_version: 2
# The hostname at which static_site_server is served.
static_site_server_hostname: ''
sws_container_image: "{{ sws_container_image_registry_prefix }}joseluisq/static-web-server:{{ sws_container_image_tag }}"
sws_container_image_registry_prefix: docker.io/
sws_container_image_tag: "{{ sws_version }}"
static_site_server_auth_users: []
traefik_docker_network: traefik
# The path at which static_site_server is served.
# This value must either be `/` or not end with a slash (e.g. `/static_site_server`).
static_site_server_path_prefix: /
static_site_server_base_path: "/static_sites"

View File

@ -1,8 +1,37 @@
---
- name: Ensure Static Sits are setup
- name: Ensure static network is created in Docker
community.docker.docker_network:
name: "{{ static_container_network }}"
driver: bridge
- name: Ensure SWS path exists
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
mode: 0700
with_items:
- {path: "{{ static_site_server_base_path }}", when: true}
- name: Ensure docker-compose file is installed
ansible.builtin.template:
src: "{{ role_path }}/templates/docer-compose.yml.j2"
dest: "{{ static_site_server_base_path }}/docker-compose.yml"
mode: 0640
- name: Ensure SWS container image is pulled
community.docker.docker_image:
name: "{{ gotosocial_container_image }}"
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
- name: Ensure Static Sites are setup
ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_site.yml"
with_items: "{{ static_sites }}"
loop_control:
loop_var: site
no_log: true
- name: Ensure SSW is pulled
community.docker.docker_image:
name: "{{ sws_container_image }}"
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"

View File

@ -0,0 +1,31 @@
version: "3.3"
services:
{% for site in static_sites %}
{{ site.domain }}:
image: {{ sws_container_image }}
container_name: "{{ site.domain }}"
environment:
# Note: those envs are customizable but also optional
- SERVER_PORT=8080
- SERVER_ROOT=/public
- SERVER_LOG_LEVEL=info
volumes:
- {{ static_site_server_base_path }}/{{ site.user }}/public:/public
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.routers.{{ site.user }}.rule=Host(`{{ site.host }}`)"
- "traefik.http.routers.{{ site.user }}.service=present"
- "traefik.http.routers.{{ site.user }}.entrypoints=web-secure"
- "traefik.http.routers.{{ site.user }}.tls=true"
- "traefik.http.routers.{{ site.user }}.tls.certResolver=default"
- "traefik.http.services.{{ site.user }}.loadbalancer.server.port=8080"
networks:
- traefik
{% endfor %}
networks:
traefik:
name: "{{ traefik_docker_network }}"
external: true