initial commit

This commit is contained in:
Von Random 2024-10-03 02:33:53 +03:00
commit 9fd6496f59
10 changed files with 182 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
venv/

9
LICENSE Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2024 von
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

41
README.md Normal file
View file

@ -0,0 +1,41 @@
# iconserver-deploy
A playbook to deploy and manage [iconserver](https://github.com/mat/besticon).
Includes two roles:
* docker
* iconserver
## Docker
Supported operating systems:
* CentOS Stream 9, RHEL 9 and clones
* Ubuntu 24
* Debian 12
Earlier versions and other debian-based distributions may not be compatible.
(Please check [docker documentation](https://docs.docker.com/engine/install/).)
## Iconserver
The service is deployed via docker-compose config. Two services are deployed:
* [iconserver](https://hub.docker.com/r/matthiasluedtke/iconserver)
* [nginx](https://hub.docker.com/_/nginx)
The service is deployed to be available via https using a self-signed certificate.
Nginx configuration template can be edited in the role.
## Deployment
The project deployment has been developed and tested with `ansible-core 2.17.4`.
If you run an earlier version your mileage may vary, but it should be compatible.
To deploy the configuration the target servers have to be able to reach docker
repos and docker hub via internet.
Ansible config and inventory files are included. Update `inventory.yml` to match
your setup.
After that deploying the service is as simple as running:
```bash
ansible-playbook deploy.yml
```
(Add necessary options, like `-u` or `-K` etc.)

2
ansible.cfg Normal file
View file

@ -0,0 +1,2 @@
[defaults]
inventory=inventory.ini

8
deploy.yml Normal file
View file

@ -0,0 +1,8 @@
---
- name: Deploy docker and iconserver
become: true
hosts: iconserver
gather_facts: true
roles:
- docker
- iconserver

4
inventory.ini Normal file
View file

@ -0,0 +1,4 @@
[iconserver]
redhat ansible_host=172.20.0.9
debian ansible_host=172.20.0.12
ubuntu ansible_host=172.20.0.24

View file

@ -0,0 +1,40 @@
---
# official docker site recommends using a yum-config-manager command,
# but in real environment we'd probably have a custom repo anyways,
# so I'm using the yum_repository module instead
- name: Set up repo for yum
when: ansible_os_family == "RedHat"
ansible.builtin.yum_repository:
name: docker-ce-stable
description: Docker CE Stable - $basearch
baseurl: https://download.docker.com/linux/centos/$releasever/$basearch/stable
gpgkey: https://download.docker.com/linux/centos/gpg
gpgcheck: true
- name: Set up repo for apt
when: ansible_os_family == "Debian"
block:
- name: Set up repo for apt (key)
ansible.builtin.get_url:
url: https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg
dest: /etc/apt/keyrings/docker.asc
- name: Set up repo for apt (repo itself)
ansible.builtin.apt_repository:
repo: deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }} stable
- name: Install packages
ansible.builtin.package:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
- name: Enable docker service
ansible.builtin.systemd_service:
name: docker
state: started
enabled: true

View file

@ -0,0 +1,39 @@
---
- name: Install dependencies
ansible.builtin.package:
name: python3-cryptography
state: present
- name: Create directories
loop:
- /containers/compose/iconserver
- /containers/data/nginx/conf.d
ansible.builtin.file:
path: "{{ item }}"
state: directory
recurse: true
- name: Install files from templates
loop:
- containers/compose/iconserver/compose.yml
- containers/data/nginx/conf.d/iconserver.conf
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "/{{ item }}"
# I would assume it does not matter how we get the self signed cert to the host
# so it's nicer (and safer) to generate one for each of the hosts.
# Another option is to pre-generate it and store it in ansible-vault.
- name: Create openssl key
community.crypto.openssl_privatekey:
path: /containers/data/nginx/conf.d/iconserver.key
- name: Create openssl self-signed cert
community.crypto.x509_certificate:
path: /containers/data/nginx/conf.d/iconserver.crt
privatekey_path: /containers/data/nginx/conf.d/iconserver.key
provider: selfsigned
- name: Deploy software via docker-compose
community.docker.docker_compose_v2:
project_src: /containers/compose/iconserver

View file

@ -0,0 +1,27 @@
networks:
default:
driver: bridge
ipam:
config:
- subnet: 172.31.0.0/24
gateway: 172.31.0.1
services:
iconserver:
image: matthiasluedtke/iconserver:latest
container_name: iconserver
restart: unless-stopped
networks:
default:
ipv4_address: 172.31.0.2
nginx:
image: nginx:stable-alpine
container_name: nginx
volumes:
- /containers/data/nginx/conf.d:/etc/nginx/conf.d:ro
ports:
- "443:443"
networks:
default:
ipv4_address: 172.31.0.3

View file

@ -0,0 +1,11 @@
server {
listen 443 ssl http2 default;
server_name _;
ssl_certificate /etc/nginx/conf.d/iconserver.crt;
ssl_certificate_key /etc/nginx/conf.d/iconserver.key;
location / {
proxy_pass http://172.31.0.2:8080;
}
}