Add initial templates for docker-compose services (gitea, nextcloud, traefik)
This commit is contained in:
33
roles/nextcloud/tasks/main.yml
Normal file
33
roles/nextcloud/tasks/main.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
# https://stackoverflow.com/questions/41667864/can-the-templates-module-handle-multiple-templates-directories
|
||||
|
||||
- name: Ensure service directory exists
|
||||
file:
|
||||
path: "{{ current_svc_path }}"
|
||||
state: directory
|
||||
mode: "500"
|
||||
|
||||
- name: Ensure directory structure exists
|
||||
file:
|
||||
path: "{{ current_svc_path }}/{{ item.path }}"
|
||||
state: directory
|
||||
mode: "500"
|
||||
with_community.general.filetree: "{{ templates_source }}"
|
||||
when: item.state == "directory"
|
||||
|
||||
|
||||
- name: Include app config variables
|
||||
include_vars:
|
||||
file: "{{ role_path }}/vars/app_config.yml"
|
||||
|
||||
- name: Generate {{ current_svc_name }} deployment from templates
|
||||
template:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ current_svc_path }}/{{ item.path | regex_replace('\\.j2$', '') }}"
|
||||
mode: "400"
|
||||
with_community.general.filetree: "{{ templates_source }}"
|
||||
when: item.state == "file"
|
||||
|
||||
- name: Deploy docker-compose for {{ current_svc_name }}
|
||||
community.docker.docker_compose:
|
||||
project_src: "{{ current_svc_path }}"
|
||||
state: present
|
||||
3
roles/nextcloud/templates/.env.db.j2
Normal file
3
roles/nextcloud/templates/.env.db.j2
Normal file
@@ -0,0 +1,3 @@
|
||||
POSTGRES_USER=nextcloud
|
||||
POSTGRES_DB=nextcloud
|
||||
POSTGRES_PASSWORD="{{ db_password }}"
|
||||
18
roles/nextcloud/templates/.env.nextcloud.j2
Normal file
18
roles/nextcloud/templates/.env.nextcloud.j2
Normal file
@@ -0,0 +1,18 @@
|
||||
POSTGRES_DB=nextcloud
|
||||
POSTGRES_USER=nextcloud
|
||||
POSTGRES_PASSWORD="{{ db_password }}"
|
||||
POSTGRES_HOST=db
|
||||
|
||||
NEXTCLOUD_TRUSTED_DOMAINS=nc.cazzzer.com
|
||||
|
||||
REDIS_HOST=redis
|
||||
REDIS_HOST_PASSWORD="{{ redis_password }}"
|
||||
|
||||
SMTP_HOST=smtp.sendgrid.net
|
||||
SMTP_SECURE=tls
|
||||
SMTP_PORT=587
|
||||
SMTP_AUTHTYPE=LOGIN
|
||||
SMTP_NAME=apikey
|
||||
SMTP_PASSWORD="{{ sendgrid_api_key }}"
|
||||
MAIL_FROM_ADDRESS=nc
|
||||
MAIL_DOMAIN=cazzzer.com
|
||||
1
roles/nextcloud/templates/.env.redis.j2
Normal file
1
roles/nextcloud/templates/.env.redis.j2
Normal file
@@ -0,0 +1 @@
|
||||
REDIS_PASSWORD="{{ redis_password }}"
|
||||
98
roles/nextcloud/templates/docker-compose.yml.j2
Normal file
98
roles/nextcloud/templates/docker-compose.yml.j2
Normal file
@@ -0,0 +1,98 @@
|
||||
version: "3.9"
|
||||
|
||||
networks:
|
||||
default:
|
||||
traefik_traefik:
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
nextcloud:
|
||||
nextcloud_config:
|
||||
nextcloud_data:
|
||||
db:
|
||||
|
||||
services:
|
||||
app:
|
||||
image: nextcloud:24-fpm-alpine
|
||||
container_name: nextcloud_app
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- db
|
||||
- redis
|
||||
env_file:
|
||||
- .env.nextcloud
|
||||
networks:
|
||||
- default
|
||||
volumes:
|
||||
- nextcloud:/var/www/html
|
||||
- nextcloud_config:/var/www/html/config
|
||||
- nextcloud_data:/var/www/html/data
|
||||
|
||||
cron:
|
||||
image: nextcloud:24-fpm-alpine
|
||||
container_name: nextcloud_cron
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- app
|
||||
entrypoint: /cron.sh
|
||||
networks:
|
||||
- default
|
||||
volumes_from:
|
||||
- app
|
||||
|
||||
notify_push:
|
||||
image: nextcloud:24-fpm-alpine
|
||||
container_name: nextcloud_notify_push
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- app
|
||||
entrypoint:
|
||||
- /var/www/html/custom_apps/notify_push/bin/x86_64/notify_push
|
||||
- /var/www/html/config/config.php
|
||||
networks:
|
||||
- default
|
||||
volumes_from:
|
||||
- app
|
||||
|
||||
db:
|
||||
image: postgres:13-alpine
|
||||
container_name: nextcloud_db
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .env.db
|
||||
networks:
|
||||
- default
|
||||
volumes:
|
||||
- db:/var/lib/postgresql/data
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: nextcloud_redis
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .env.redis
|
||||
networks:
|
||||
- default
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- redis-server --requirepass $$REDIS_PASSWORD
|
||||
|
||||
web:
|
||||
image: nginx:1.23-alpine
|
||||
container_name: nextcloud_web
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
- traefik.http.routers.nextcloud.rule=Host(`nc.lab.cazzzer.com`)
|
||||
restart: unless-stopped
|
||||
links:
|
||||
- app
|
||||
ports:
|
||||
- "8012:80"
|
||||
networks:
|
||||
- traefik_traefik
|
||||
- default
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/nginx.conf
|
||||
volumes_from:
|
||||
- app
|
||||
182
roles/nextcloud/templates/nginx.conf.j2
Normal file
182
roles/nextcloud/templates/nginx.conf.j2
Normal file
@@ -0,0 +1,182 @@
|
||||
# https://github.com/nextcloud/docker/blob/master/.examples/docker-compose/with-nginx-proxy/postgres/fpm/web/nginx.conf
|
||||
|
||||
worker_processes auto;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
# Prevent nginx HTTP Server Detection
|
||||
server_tokens off;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
upstream php-handler {
|
||||
server app:9000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
# HSTS settings
|
||||
# WARNING: Only add the preload option once you read about
|
||||
# the consequences in https://hstspreload.org/. This option
|
||||
# will add the domain to a hardcoded list that is shipped
|
||||
# in all major browsers and getting removed from this list
|
||||
# could take several months.
|
||||
#add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
|
||||
|
||||
# set max upload size
|
||||
client_max_body_size 512M;
|
||||
fastcgi_buffers 64 4K;
|
||||
|
||||
# Enable gzip but do not remove ETag headers
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_comp_level 4;
|
||||
gzip_min_length 256;
|
||||
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
|
||||
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
|
||||
|
||||
# Pagespeed is not supported by Nextcloud, so if your server is built
|
||||
# with the `ngx_pagespeed` module, uncomment this line to disable it.
|
||||
#pagespeed off;
|
||||
|
||||
# HTTP response headers borrowed from Nextcloud `.htaccess`
|
||||
add_header Referrer-Policy "no-referrer" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-Download-Options "noopen" always;
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Permitted-Cross-Domain-Policies "none" always;
|
||||
add_header X-Robots-Tag "none" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# Remove X-Powered-By, which is an information leak
|
||||
fastcgi_hide_header X-Powered-By;
|
||||
|
||||
# Path to the root of your installation
|
||||
root /var/www/html;
|
||||
|
||||
# Specify how to handle directories -- specifying `/index.php$request_uri`
|
||||
# here as the fallback means that Nginx always exhibits the desired behaviour
|
||||
# when a client requests a path that corresponds to a directory that exists
|
||||
# on the server. In particular, if that directory contains an index.php file,
|
||||
# that file is correctly served; if it doesn't, then the request is passed to
|
||||
# the front-end controller. This consistent behaviour means that we don't need
|
||||
# to specify custom rules for certain paths (e.g. images and other assets,
|
||||
# `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
|
||||
# `try_files $uri $uri/ /index.php$request_uri`
|
||||
# always provides the desired behaviour.
|
||||
index index.php index.html /index.php$request_uri;
|
||||
|
||||
# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
|
||||
location = / {
|
||||
if ( $http_user_agent ~ ^DavClnt ) {
|
||||
return 302 /remote.php/webdav/$is_args$args;
|
||||
}
|
||||
}
|
||||
|
||||
location = /robots.txt {
|
||||
allow all;
|
||||
log_not_found off;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# Make a regex exception for `/.well-known` so that clients can still
|
||||
# access it despite the existence of the regex rule
|
||||
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
|
||||
# for `/.well-known`.
|
||||
location ^~ /.well-known {
|
||||
# The rules in this block are an adaptation of the rules
|
||||
# in `.htaccess` that concern `/.well-known`.
|
||||
|
||||
location = /.well-known/carddav { return 301 /remote.php/dav/; }
|
||||
location = /.well-known/caldav { return 301 /remote.php/dav/; }
|
||||
|
||||
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
|
||||
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
|
||||
|
||||
# Let Nextcloud's API for `/.well-known` URIs handle all other
|
||||
# requests by passing them to the front-end controller.
|
||||
return 301 /index.php$request_uri;
|
||||
}
|
||||
|
||||
# Rules borrowed from `.htaccess` to hide certain paths from clients
|
||||
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
|
||||
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
|
||||
|
||||
# Ensure this block, which passes PHP files to the PHP process, is above the blocks
|
||||
# which handle static assets (as seen below). If this block is not declared first,
|
||||
# then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
|
||||
# to the URI, resulting in a HTTP 500 error response.
|
||||
location ~ \.php(?:$|/) {
|
||||
# Required for legacy support
|
||||
rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
|
||||
|
||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||
set $path_info $fastcgi_path_info;
|
||||
|
||||
try_files $fastcgi_script_name =404;
|
||||
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $path_info;
|
||||
#fastcgi_param HTTPS on;
|
||||
|
||||
fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
|
||||
fastcgi_param front_controller_active true; # Enable pretty urls
|
||||
fastcgi_pass php-handler;
|
||||
|
||||
fastcgi_intercept_errors on;
|
||||
fastcgi_request_buffering off;
|
||||
}
|
||||
|
||||
location ~ \.(?:css|js|svg|gif)$ {
|
||||
try_files $uri /index.php$request_uri;
|
||||
expires 6M; # Cache-Control policy borrowed from `.htaccess`
|
||||
access_log off; # Optional: Don't log access to assets
|
||||
}
|
||||
|
||||
location ~ \.woff2?$ {
|
||||
try_files $uri /index.php$request_uri;
|
||||
expires 7d; # Cache-Control policy borrowed from `.htaccess`
|
||||
access_log off; # Optional: Don't log access to assets
|
||||
}
|
||||
|
||||
# Rule borrowed from `.htaccess`
|
||||
location /remote {
|
||||
return 301 /remote.php$request_uri;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php$request_uri;
|
||||
}
|
||||
|
||||
location ^~ /push/ {
|
||||
proxy_pass http://notify_push:7867/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
roles/nextcloud/vars/app_config.yml
Normal file
14
roles/nextcloud/vars/app_config.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
$ANSIBLE_VAULT;1.2;AES256;alpina
|
||||
65313636646233613364363933616361346639653939346337303832646339316632383966666237
|
||||
3766396134383434613534373937663162393134306536300a626139373732393037346630333838
|
||||
63663439353238643532316231623866396434303034313130386635623363353263626362376334
|
||||
3933346434633662320a386432373465646432343338666561366161646335636232353133393933
|
||||
65313364666564353039626238383033343765323730316633356139326666623135326131353864
|
||||
32386237643538636538356261393164633137636235346564393930346539623731386633336339
|
||||
31303466653936343166366164383134306232613236663735623834393963306331376435616365
|
||||
31313866383730393063353335626164303632636331303830636530656131636139376633623439
|
||||
63663639323964623231343066373538633336353561646230363363643762393634643435306164
|
||||
31366364326237636365336363343264343562353337303235633034383635373934376334353336
|
||||
61373065386639643064303431623162373665363937353832313561386134613834613935653964
|
||||
64656339316165313936333736643030356366663162316462636662326134396539356262666536
|
||||
64336133393937396330353234316563356337623733326264363333373536633833
|
||||
6
roles/nextcloud/vars/main.yml
Normal file
6
roles/nextcloud/vars/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
# vars file for roles/nextcloud/
|
||||
current_svc_name: nextcloud
|
||||
current_svc_path: "{{ my_svc_path }}/{{ current_svc_name }}"
|
||||
|
||||
templates_source: "{{ role_path }}/templates"
|
||||
Reference in New Issue
Block a user