diff --git a/.gitignore b/.gitignore index 52497f6..9eda19a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ Volumes/* *.yml.*backup* *.yml.*Backup* *.yml.*BACKUP* +*.yml.*bkp* # Ignore logs logs @@ -16,15 +17,9 @@ Config/ReverseProxy/config/hosts/* Config/ReverseProxy/config/load.conf.d/* Config/ReverseProxy/config/mail.conf.d/* -# Ignore downloaded mail server files. -Config/MailServer/setup.sh - # Ignore any private key information. private.key -# Ignore secrets for Invidious. -Config/Invidious/*.env - # Ignore DNS config files, contain private settings. Config/DNS/config/* @@ -33,3 +28,6 @@ disabled # Ignore any .env files which are not explicitly committed to the project. *.env + +# 2024-01-23 Ignore true docker-compose files and only show example from now on. +docker-compose.yml diff --git a/Config/DNS/docker-compose.yml b/Config/DNS/docker-compose.standard.yml similarity index 100% rename from Config/DNS/docker-compose.yml rename to Config/DNS/docker-compose.standard.yml diff --git a/Config/DynamicDNS/update_dns.sh b/Config/DynamicDNS/update_dns.sh index f4d51f1..383518a 100755 --- a/Config/DynamicDNS/update_dns.sh +++ b/Config/DynamicDNS/update_dns.sh @@ -67,23 +67,17 @@ fi while getopts ":46dtvh" opt; do case $opt in - 4) - v4="Y" + 4) v4="Y" ;; - 6) - v6="Y" + 6) v6="Y" ;; - d | t) - dry_run="Y" + d | t) dry_run="Y" ;; - v) - set -x + v) set -x ;; - h) - usage 0 + h) usage 0 ;; - *) - echo "ERROR: Parameter $opt not recognized." + *) echo "ERROR: Parameter $opt not recognized." usage 1 ;; esac diff --git a/Config/Hyperling.com/Dockerfile b/Config/Hyperling.com/Dockerfile index b7bab54..e97c51b 100644 --- a/Config/Hyperling.com/Dockerfile +++ b/Config/Hyperling.com/Dockerfile @@ -8,8 +8,15 @@ FROM debian:testing # Install Dependencies RUN apt update && apt install -y sudo php-fpm nodejs npm +# Copy Static Content +RUN rm -rfv files +COPY ./files files +RUN rm -rfv files/README* + # Run Website CMD rm -rfv www && \ git clone https://github.com/Hyperling/www www && \ + rm -rfv www/files && \ + mv files www/ && \ cd www && \ ./run.sh diff --git a/Config/Hyperling.com/docker-compose.micro.yml b/Config/Hyperling.com/docker-compose.micro.yml new file mode 100644 index 0000000..29a5e98 --- /dev/null +++ b/Config/Hyperling.com/docker-compose.micro.yml @@ -0,0 +1,18 @@ +# 2022-10-29 +# Hyperling.com configuration. + +version: '2' + +services: + app: + container_name: website-app + build: ./ + restart: always + ports: + - 8317:8080 + deploy: + mode: global + resources: + limits: + cpus: '0.10' + memory: 32M diff --git a/Config/Hyperling.com/docker-compose.yml b/Config/Hyperling.com/docker-compose.standard.yml similarity index 100% rename from Config/Hyperling.com/docker-compose.yml rename to Config/Hyperling.com/docker-compose.standard.yml diff --git a/Config/Hyperling.com/files/README.md b/Config/Hyperling.com/files/README.md new file mode 100644 index 0000000..d06aae4 --- /dev/null +++ b/Config/Hyperling.com/files/README.md @@ -0,0 +1,5 @@ +# Hyperling.com - files/ + +This is copied to the container's www/files/ folder for hosting static content. + +TBD: Make this a volume, rather than copying with `Dockerfile`. diff --git a/Config/Nextcloud/docker-compose.micro.yml b/Config/Nextcloud/docker-compose.micro.yml new file mode 100644 index 0000000..ef92d92 --- /dev/null +++ b/Config/Nextcloud/docker-compose.micro.yml @@ -0,0 +1,103 @@ +# Nextcloud configuration. +# This is a revised version of the original work here: +# https://hub.docker.com/_/nextcloud + +# Changelog: +# 2023-07-16 +# Change from mariadb:10.5 to 10.6. +# 2023-08-20 +# Add Redis. (https://markontech.com/docker/setup-nextcloud-with-redis-using-docker/) +# 2023-08-21 +# Got NC to work with OO after specifying the Advanced parameters! +# 2023-08-26 +# Try combining OnlyOffice to here again. It has been on its own since +# 2023-07-25 but isn't being used for anything else. OO is slow to respond +# and upgrades can no longer be done separately but this keeps it all easier +# to maintain and may allow the internal address to be based on container +# name instead of the docker hosts's IP. +# 2024-01-23 +# Experimenting with how small a Nextcloud installation can survive. + +version: '3' + +services: + + ## MariaDB ## + nc-db: + container_name: nc-db + image: mariadb:10.6 + restart: always + command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW + volumes: + - ../../Volumes/Nextcloud/mariadb:/var/lib/mysql + environment: + - MYSQL_DATABASE=$MYSQL_DATABASE + - MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD + - MYSQL_USER=$MYSQL_USER + - MYSQL_PASSWORD=$MYSQL_PASSWORD + deploy: + mode: global + resources: + limits: + cpus: '0.20' + memory: 64M + + ## Redis ## + nc-redis: + container_name: nc-redis + image: redis + restart: always + command: redis-server --requirepass $REDIS_HOST_PASSWORD + deploy: + mode: global + resources: + limits: + cpus: '0.10' + memory: 32M + + ### OnlyOffice ## + ##nc-oo: + ## container_name: nc-oo + ## image: onlyoffice/documentserver + ## restart: always + ## ports: + ## - 8081:80 + ## environment: + ## - JWT_SECRET=$JWT_SECRET + ## deploy: + ## mode: global + ## resources: + ## limits: + ## cpus: '0.75' + ## memory: 1G + + ## Nextcloud ## + nc-app: + container_name: nc-app + image: nextcloud + restart: always + ports: + - 8080:80 + links: + - nc-db + - nc-redis + ## - nc-oo + volumes: + - ../../Volumes/Nextcloud/nextcloud:/var/www/html + environment: + - NEXTCLOUD_ADMIN_USER=$NEXTCLOUD_ADMIN_USER + - NEXTCLOUD_ADMIN_PASSWORD=$NEXTCLOUD_ADMIN_PASSWORD + - PHP_MEMORY_LIMIT=$PHP_MEMORY_LIMIT + - PHP_UPLOAD_LIMIT=$PHP_UPLOAD_LIMIT + - MYSQL_HOST=$MYSQL_HOST + - MYSQL_DATABASE=$MYSQL_DATABASE + - MYSQL_USER=$MYSQL_USER + - MYSQL_PASSWORD=$MYSQL_PASSWORD + - REDIS_HOST=$REDIS_HOST + - REDIS_HOST_PASSWORD=$REDIS_HOST_PASSWORD + deploy: + mode: global + resources: + limits: + cpus: '0.30' + memory: 512M diff --git a/Config/Nextcloud/docker-compose.yml b/Config/Nextcloud/docker-compose.standard.yml similarity index 100% rename from Config/Nextcloud/docker-compose.yml rename to Config/Nextcloud/docker-compose.standard.yml diff --git a/Config/Nextcloud/env.micro b/Config/Nextcloud/env.micro new file mode 100644 index 0000000..99d3556 --- /dev/null +++ b/Config/Nextcloud/env.micro @@ -0,0 +1,55 @@ +# Example environment file for Nextcloud stack, should be copied as `.env`. The +# variables here only apply to the compose file. If you need it passed to a +# container then it also needs specified in its `environment:` operator. +# +# ** All usernames and passwords need changed before running in production! ** +# +# Full guide on the Nextcloud parameters which may be supplied: +# https://github.com/docker-library/docs/blob/master/nextcloud/README.md#auto-configuration-via-environment-variables + +# +## Nextcloud ## +# + +NEXTCLOUD_ADMIN_USER=nc_admin +NEXTCLOUD_ADMIN_PASSWORD=SuperDuperSecretPassword + +PHP_MEMORY_LIMIT=512M +PHP_UPLOAD_LIMIT=512M + +# +## MariaDB ## +# +# Should load automatically the first run. Then config.php is the source of +# truth for these values. So, if something like the DB password is changed, +# updating it here will have no effect. This is only used for the install. + +MYSQL_HOST=nc-db +MYSQL_DATABASE=nextcloud +MYSQL_ROOT_PASSWORD=ChangeMe +MYSQL_USER=nc +MYSQL_PASSWORD=changeme + +# +## Redis ## +# +# Installs automagically if both of these parameters are supplied. + +REDIS_HOST=nc-redis +REDIS_HOST_PASSWORD=someredispassword + +### +#### OnlyOffice ## +### +### How Nextcloud's ONLYOFFICE Admin Settings should be set up: +### OO Address: https://FQDN-For-Reverse-Proxied-OO-Server +### OO Secret: Contents-Of-$JWT_SECRET +### OO Header: +### OO Internal Address: http://docker-server-ip:8081 ?OR http://nc-oo:8081? +### NC Internal Address: http://docker-server-ip:8080 ?OR http://nc-app:8080? +### +### Documentation which references the variable(s) below, Nextcloud link does not cover them: +### https://helpcenter.onlyoffice.com/installation/docs-configure-jwt.aspx +## +### Secret key which is used above in the Nextcloud ONLYOFFICE Administration UI. +##JWT_SECRET=abc123 diff --git a/Config/Nextcloud/env.example b/Config/Nextcloud/env.standard similarity index 100% rename from Config/Nextcloud/env.example rename to Config/Nextcloud/env.standard diff --git a/Config/PhotoPrism/docker-compose.yml b/Config/PhotoPrism/docker-compose.standard.yml similarity index 100% rename from Config/PhotoPrism/docker-compose.yml rename to Config/PhotoPrism/docker-compose.standard.yml diff --git a/Config/PhotoPrism/env.example b/Config/PhotoPrism/env.standard similarity index 100% rename from Config/PhotoPrism/env.example rename to Config/PhotoPrism/env.standard diff --git a/Config/ReverseProxy/docker-compose.micro.yml b/Config/ReverseProxy/docker-compose.micro.yml new file mode 100644 index 0000000..a9c7c28 --- /dev/null +++ b/Config/ReverseProxy/docker-compose.micro.yml @@ -0,0 +1,43 @@ +# 2022-10-05 Hyperling +# Reverse Proxy with LetsEncrypt Certbot. +# This is a revised version of these works: +# https://phoenixnap.com/kb/docker-nginx-reverse-proxy +# https://www.docker.com/blog/how-to-use-the-official-nginx-docker-image/ +# https://pentacent.medium.com/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71 + +version: '3' + +services: + + app: + container_name: rp-app + build: ./ + restart: always + ports: + - "80:80" + - "443:443" + volumes: + - ../../Volumes/ReverseProxy/letsencrypt:/etc/nginx/letsencrypt + - ../../Volumes/ReverseProxy/letsencrypt-certs:/etc/nginx/certs + command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'" + deploy: + mode: global + resources: + limits: + cpus: '0.20' + memory: 64M + + certbot: + container_name: rp-certbot + image: certbot/certbot + restart: always + volumes: + - ../../Volumes/ReverseProxy/letsencrypt:/etc/letsencrypt + - ../../Volumes/ReverseProxy/letsencrypt-certs:/etc/letsencrypt/nginx + entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; cp -rL /etc/letsencrypt/live/* /etc/letsencrypt/nginx/; sleep 12h & wait $${!}; done;'" + deploy: + mode: global + resources: + limits: + cpus: '0.10' + memory: 16M diff --git a/Config/ReverseProxy/docker-compose.yml b/Config/ReverseProxy/docker-compose.standard.yml similarity index 100% rename from Config/ReverseProxy/docker-compose.yml rename to Config/ReverseProxy/docker-compose.standard.yml diff --git a/README.md b/README.md index feb83fe..439ea7e 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # My Docker Setup Scripting my way into the Docker world. I was unable to find a good tutorial on using and managing containers so this is what made sense to me based on practice -with `docker-compose`. I am still new-ish to Docker and am likely to make -mistakes, but you're welcome to learn with me. ;) +with `docker-compose`. Also has some usages of `Dockerfile` to build some apps. ## Disclaimer -Currently the project only focuses on `apt` based operating systems. +Currently the project only focuses on `apt` based operating systems, and is +being used in production by the latest Debian release. ## Other README's -Each `./Config/PROJECT/` folder also contains its own README file with specific +Each `Config/PROJECT/` folder also contains its own README file with specific information to running that sub project. This file's job is to cover the general Docker installation. The others then contain details on their program setup. @@ -24,10 +24,10 @@ apt install git bash Clone the project. You may choose anywhere, but `/opt/Docker` is recommended. ``` -git clone https://github.com/hyperling/docker /opt/Docker +git clone https://github.com/Hyperling/Docker /opt/Docker ``` -Load the environment variables. +Load the environment variables from wherever you chose to put the project. ``` source /opt/Docker/source.env ``` @@ -37,28 +37,41 @@ Install docker to the system using the official repos. install.sh ``` -Create an area to add a new product. +Copy default configuration for usage by management script. +For example, to enable Nextcloud: +``` +cd $DOCKER_HOME/Config/Nextcloud +cp docker-compose.standard.yml docker-compose.yml +cp env.standard .env +``` + +Be sure to edit the environment file to update any passwords or preferences. +``` +vi $DOCKER_HOME/Config/Nextcloud/.env +``` + +If you have a new configuration to add, create an area for the new product. ``` create.sh PROJECT_NAME ``` Edit the project's details. ``` -vi /opt/Docker/Config/PROJECT_NAME/docker-compose.yml +vi $DOCKER_HOME/Config/PROJECT_NAME/docker-compose.yml ``` -Start all of the docker projects. +Start all of the configured docker projects. ``` -start.sh +manage.sh -u ``` -Cross your fingers and hope to profit! +Cross your fingers and hope to succeed! ## Folders ### Config Compose projects are set up here. Each folder should have a `docker-compose.yml` -file set up. +file set up unless it is for utility such as DynamicDNS, which is used in CRON. ### Volumes The data of the files go here if the Config is done correctly. I think this @@ -70,11 +83,15 @@ directory other than `/opt/Docker`, this project is location agnostic. ### bin Scripts to help make life easier. Some are pretty basic, but others do nice things like handle the container IDs. -* `install.sh` : Install dependencies on a new server with apt. -* `create.sh` : Create a new folder with the needed yml file. -* `start.sh` : Start all compose containers. -* `stop.sh` : Stop all compose containers. -* `get_logs.sh` : Create log files rather than using the `docker log` command or +- `create.sh` + - Create a new folder with the needed yml file. +- `get_logs.sh` + - Create log files rather than using the `docker log` command or searching in /var/whatever. -* `uninstall.sh` : If something goes wrong and you'd like to start from scratch - without provisioning a new server then this should do the job. +- `install.sh` + - Install dependencies on a new server with apt. +- `manage.sh` + - Start, stop, update, rebuild, etc all compose containers. +- `uninstall.sh` + - If something goes wrong and you'd like to start from scratch without + provisioning a new server then this should do the job. diff --git a/bin/manage.sh b/bin/manage.sh index 12675da..ffa73cf 100755 --- a/bin/manage.sh +++ b/bin/manage.sh @@ -144,9 +144,9 @@ if [[ -n $up || -n $down || -n $build || -n $pull ]]; then pwd # Ensure .env files exist so that all compose variables are populated. - if [[ -e ./env.example && ! -e ./.env ]]; then - echo "WARNING: .env file was not found, copying example as placeholder." - cp -v env.example .env + if [[ -e ./env.standard && ! -e ./.env ]]; then + echo "WARNING: .env file was not found, copying standard as placeholder." + cp -v env.standard .env fi # Ensure all configuration files have been created.