Enhancement: Add Docker Hub image (#965)

* Enhancement: Add Docker Hub image

* Push to ghcr.io

* Add all `org.opencontainers.image.xxx` labels using `--label` instead of `LABEL`

* Change `php-fpm` to listen on `:9000` to expose prometheus metrics via `php-fpm_exporter`

* Include `yarn.lock` to speed up builds

* Reorder

* Use correct sha for pr

* Add logging before overriding values in config

* Add `DEBUG=true` env var for verbose `entrypoint.sh` logs

* Print php exception when snappymail fails to generate data directory and config file on the very first time

* Log snappymail version

* Fix COPY statement

* Add .dockerignore

* Add `USER` and `ENTRYPOINT`

* Update `.dockerignore`

* Add docker image test

* Push only if image test succeeds

* Log when startup is successful

* Use plain `docker build` in `build_and_test.sh`

* Fix test output
This commit is contained in:
leo 2023-11-20 14:01:26 +00:00 committed by GitHub
parent 6552a93989
commit 24dbff999e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 5201 additions and 229 deletions

123
examples/README.md Normal file
View file

@ -0,0 +1,123 @@
# Examples
Here are some [`docker-compose`] examples.
## `docker-compose.simple.yml`
This runs `snappymail`, using [SQLite](https://www.sqlite.org/index.html) as the database.
Start the stack:
```sh
docker-compose -f docker-compose.simple.yml up
```
Get the Admin Panel password:
```sh
docker exec -it $( docker-compose -f docker-compose.simple.yml ps -q snappymail ) cat /var/lib/snappymail/_data_/_default_/admin_password.txt
```
Now, login to [http://localhost:8888/?admin](http://localhost:8888/?admin) with user `admin` and the admin password.
## `docker-compose.mysql.yml`
This runs `snappymail`, using [MariaDB](https://mariadb.org/) (a fork of [MYSQL](https://www.mysql.com/)) as the database.
Start `snappymail` and `mysql`:
```sh
docker-compose -f docker-compose.mysql.yml up
```
Get the Admin Panel password:
```sh
docker exec -it $( docker-compose -f docker-compose.mysql.yml ps -q snappymail ) cat /var/lib/snappymail/_data_/_default_/admin_password.txt
```
Now, login to [http://localhost:8888/?admin](http://localhost:8888/?admin) with user `admin` and the admin password.
To setup MySQL as the DB, in Admin Panel, click `Contacts`, check `Enable contacts` and , and under `Storage (PDO)` choose the following:
- Type: `MySQL`
- Data Source Name (DSN): `host=mysql;port=3306;dbname=snappymail`
- User `snappymail`
- Password `snappymail`
Click the `Test` button. If it turns green, MySQL is ready to be used for contacts.
To setup Redis for caching, in Admin Panel, click `Config`, update the following configuration options:
- `cache > enable`: yes
- `cache > fast_cache_driver`: `redis`
- `labs > fast_cache_redis_host`: `redis`
- `labs > fast_cache_redis_port`: `6379`
Redis caching is now enabled.
## `docker-compose.postgres.yml`
This runs `snappymail`, using [PostgreSQL](https://hub.docker.com/_/postgres) as the database.
Start `snappymail` and `postgres`:
```sh
docker-compose -f docker-compose.postgres.yml up
```
Get the Admin Panel password:
```sh
docker exec -it $( docker-compose -f docker-compose.postgres.yml ps -q snappymail ) cat /var/lib/snappymail/_data_/_default_/admin_password.txt
```
Now, login to [http://localhost:8888/?admin](http://localhost:8888/?admin) with user `admin` and the admin password.
To use PostgreSQL as the DB, in Admin Panel, click `Contacts`, check `Enable contacts` and , and under `Storage (PDO)` choose the following:
- Type: `PostgresSQL`
- Data Source Name (DSN): `host=postgres;port=5432;dbname=snappymail`
- User `snappymail`
- Password `snappymail`
Click the `Test` button. If it turns green, PostgreSQL is ready to be used for contacts.
To setup Redis for caching, in Admin Panel, click `Config`, update the following configuration options:
- `cache > enable`: yes
- `cache > fast_cache_driver`: `redis`
- `labs > fast_cache_redis_host`: `redis`
- `labs > fast_cache_redis_port`: `6379`
Redis caching is now enabled.
## `docker-compose.traefik.yml`
This runs `snappymail`, using [SQLite](https://www.sqlite.org/index.html) as the database, with `traefik` as the TLS reverse proxy and loadbalancer.
In this example, it is assumed the domain name is `snappymail.example.com`. It is assumed you have an [OVHcloud](https://www.ovh.com/auth/) account to obtain LetsEncrypt TLS certs via `ACME` using DNS challenge for the domain `snappymail.example.com`. If you are using another DNS provider, see [here](https://doc.traefik.io/traefik/https/acme/#providers).
To begin, edit the `OVH_*` environment variables in [`docker-compose.traefik.yml`](docker-compose.traefik.yml) accordingly:
```sh
nano docker-compose.traefik.yml
```
Start `snappymail` and `traefik`:
```sh
docker-compose -f docker-compose.traefik.yml up
```
`traefik` should now begin requesting a TLS cert for `snappymail.example.com`. The process may take a few minutes. If all goes well, https://snappymail.example.com should now be ready.
> You may still visit https://snappymail.example.com while waiting for `traefik` to be issued a TLS certificate. `traefik` simply serves a self-signed TLS cert.
Get the Admin Panel password:
```sh
docker exec -it $( docker-compose -f docker-compose.traefik.yml ps -q snappymail ) cat /var/lib/snappymail/_data_/_default_/admin_password.txt
```
Now, login to [https://snappymail.example.com/?admin](https://snappymail.example.com/?admin) with user `admin` and the admin password.

View file

@ -0,0 +1,57 @@
version: '2'
services:
snappymail:
image: leojonathanoh/snappymail:pr-1
ports:
- 8888:8888
environment:
- DEBUG=true
volumes:
- snappymail:/var/lib/snappymail
networks:
- default
- db-network
- redis-network
restart: unless-stopped
# This provides prometheus metrics for snappymail's php-fpm
php-fpm-exporter:
image: hipages/php-fpm_exporter:2.2.0
ports:
- 9253:9253
environment:
- PHP_FPM_SCRAPE_URI=tcp://snappymail:9000/status
networks:
- default
mysql:
image: mariadb:10
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=snappymail
- MYSQL_PASSWORD=snappymail
- MYSQL_DATABASE=snappymail
volumes:
- mysql:/var/lib/mysql
networks:
- db-network
restart: unless-stopped
redis:
image: redis:7-alpine
networks:
- redis-network
restart: unless-stopped
networks:
default:
db-network:
internal: true
redis-network:
internal: true
volumes:
mysql:
driver: local
snappymail:
driver: local

View file

@ -0,0 +1,56 @@
version: '2'
services:
snappymail:
image: leojonathanoh/snappymail:pr-1
ports:
- 8888:8888
environment:
- DEBUG=true
volumes:
- snappymail:/var/lib/snappymail
networks:
- default
- db-network
- redis-network
restart: unless-stopped
# This provides prometheus metrics for snappymail's php-fpm
php-fpm-exporter:
image: hipages/php-fpm_exporter:2.2.0
ports:
- 9253:9253
environment:
- PHP_FPM_SCRAPE_URI=tcp://snappymail:9000/status
networks:
- default
db:
image: postgres:15-alpine
environment:
- POSTGRES_USER=snappymail
- POSTGRES_PASSWORD=snappymail
- POSTGRES_DB=snappymail
volumes:
- postgres:/var/lib/postgresql/data
networks:
- db-network
restart: unless-stopped
redis:
image: redis:7-alpine
networks:
- redis-network
restart: unless-stopped
networks:
default:
db-network:
internal: true
redis-network:
internal: true
volumes:
postgres:
driver: local
snappymail:
driver: local

View file

@ -0,0 +1,30 @@
version: '2'
services:
snappymail:
image: leojonathanoh/snappymail:pr-1
ports:
- 8888:8888
environment:
- DEBUG=true
volumes:
- snappymail:/var/lib/snappymail
networks:
- default
restart: unless-stopped
# This provides prometheus metrics for snappymail's php-fpm
php-fpm-exporter:
image: hipages/php-fpm_exporter:2.2.0
ports:
- 9253:9253
environment:
- PHP_FPM_SCRAPE_URI=tcp://snappymail:9000/status
networks:
- default
networks:
default:
volumes:
snappymail:
driver: local

View file

@ -0,0 +1,86 @@
version: '2'
services:
# The reverse proxy for our web containers
# See https://github.com/traefik/traefik/tree/v2.7/docs/content/user-guides/docker-compose for some examples for enabling HTTPS using ACME
# You will need a domain name. E.g. 'example.com'
# This example requests TLS certs via ACME via DNS challenge using OVHcloud as the DNS provider.
# For a list of supported DNS providers, see: https://doc.traefik.io/traefik/https/acme/#providers
traefik:
image: traefik:v2
environment:
- OVH_ENDPOINT=xxx
- OVH_APPLICATION_KEY=xxx
- OVH_APPLICATION_SECRET=xxx
- OVH_CONSUMER_KEY=xxx
volumes:
# Allow traefik to listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock:ro
- acme-volume:/letsencrypt
ports:
- 80:80
- 443:443
networks:
- traefik-network
restart: unless-stopped
command:
- --global.checknewversion=false
- --global.sendanonymoususage=false
# - --log.level=DEBUG
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --certificatesresolvers.myresolver.acme.dnschallenge=true
- --certificatesresolvers.myresolver.acme.dnschallenge.provider=ovh
# - --certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
- --certificatesresolvers.myresolver.acme.email=postmaster@example.com
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
# snappymail will be available at: https://snappymail.example.com
snappymail:
image: leojonathanoh/snappymail:pr-1
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik-network"
# traefik v2
# http
- "traefik.http.routers.snappymail-http.entrypoints=web"
- "traefik.http.routers.snappymail-http.rule=Host(`snappymail.example.com`)"
- "traefik.http.routers.snappymail-http.middlewares=snappymail-http-myRedirectScheme" # Redirect http to https
- "traefik.http.middlewares.snappymail-http-myRedirectScheme.redirectScheme.scheme=https" # Redirect http to https
# https
- "traefik.http.routers.snappymail.entrypoints=websecure"
- "traefik.http.routers.snappymail.tls"
- "traefik.http.routers.snappymail.rule=Host(`snappymail.example.com`)"
- "traefik.http.services.snappymail.loadbalancer.server.port=8888"
expose:
- 8888
environment:
- DEBUG=true
volumes:
- snappymail:/var/lib/snappymail
networks:
- default
- traefik-network
restart: unless-stopped
# This provides prometheus metrics for snappymail's php-fpm
php-fpm-exporter:
image: hipages/php-fpm_exporter:2.2.0
ports:
- 9253:9253
environment:
- PHP_FPM_SCRAPE_URI=tcp://snappymail:9000/status
networks:
- default
networks:
default:
traefik-network:
name: traefik-network
volumes:
acme-volume:
driver: local
snappymail:
driver: local