diff --git a/.docker/init.sh b/.docker/init.sh new file mode 100644 index 0000000..0998a0e --- /dev/null +++ b/.docker/init.sh @@ -0,0 +1,55 @@ + +echo "" > /var/log/msmtp + +{ + + printf "%s\n%s\n%s\n" "set ask askcc append dot save crt" \ + "ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To" \ + "set mta=/usr/bin/msmtp" + +} > /etc/mail.rc + +{ + echo '[mail function]' + echo 'sendmail_path = "/usr/bin/msmtp -t"' +} > /usr/local/etc/php/conf.d/99-mail.ini + +if [ "${SMTP}" == "1" ]; then + + [ -z "${SMTP_HOST}" ] && { echo "Missing ENV: 'SMTP_HOST'"; exit 1; } + [ -z "${SMTP_AUTH}" ] && { echo "Missing ENV: 'SMTP_AUTH'"; exit 1; } + [ -z "${SMTP_USER}" ] && { echo "Missing ENV: 'SMTP_USER'"; exit 1; } + [ -z "${SMTP_PASSWORD}" ] && { echo "Missing ENV: 'SMTP_PASSWORD'"; exit 1; } + [ -z "${SMTP_PORT}" ] && { echo "Missing ENV: 'SMTP_PORT'"; exit 1; } + [ -z "${SMTP_TLS}" ] && { echo "Missing ENV: 'SMTP_TLS'"; exit 1; } + [ -z "${SMTP_STARTTLS}" ] && { echo "Missing ENV: 'SMTP_STARTTLS'"; exit 1; } + [ -z "${SMTP_FROM}" ] && { echo "Missing ENV: 'SMTP_FROM'"; exit 1; } + + { + printf "account default\n" + printf "\n" + printf "logfile /dev/stdout\n" + printf "\n" + printf "host %s\n" "${SMTP_HOST}" # e.g. smtp.fastmail.com + printf "auth %s\n" "${SMTP_AUTH}" # e.g. on + printf "user %s\n" "${SMTP_USER}" # e.g. business@blackforestbytes.de + printf "password %s\n" "${SMTP_PASSWORD}" # e.g. ********* + printf "port %s\n" "${SMTP_PORT}" # e.g. 465 + printf "tls %s\n" "${SMTP_TLS}" # e.g. on + printf "tls_starttls %s\n" "${SMTP_STARTTLS}" # e.g. off + printf "from %s\n" "${SMTP_FROM}" # e.g. server-msmtp@blackforestbytes.com + printf "\n" + printf "# vim:filetype=msmtp\n" + + } > /etc/msmtprc + +elif [ "${SMTP}" == "0" ]; then + + printf "account default\n" > /etc/msmtprc + +else + + echo "Missing/Invalid ENV: 'SMTP'"; + exit 1; + +fi diff --git a/.docker/run.sh b/.docker/run.sh new file mode 100755 index 0000000..7d02da0 --- /dev/null +++ b/.docker/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +/_docker/init.sh || exit 1 + + +apache2-foreground + diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7ae5a7c --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +www/config.php \ No newline at end of file diff --git a/.gitignore b/.gitignore index 54562f9..d1bf34e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ runtime/ config.php -www/dtest.php \ No newline at end of file +www/dtest.php + +DOCKER_GIT_INFO \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dfca6ac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM php:8.0-apache +WORKDIR /var/www/html + +COPY ./www /var/www/html + +RUN apt-get update && \ + apt-get install -y git curl procps zip msmtp bsd-mailx && \ + apt-get install -y magick && \ + rm -rf /var/lib/apt/lists/* + +COPY .docker /_docker + +RUN rm /var/www/html/Makefile && \ + rm /var/www/html/Dockerfile && \ + rm -rf /var/www/html/.git && \ + rm -rf /var/www/html/.idea && \ + rm -rf /var/www/html/.docker + +# MapVolumes for: /var/www/html/config.php +# MapVolumes for: /var/www/html/dynamic/egg +# MapVolumes for: /var/www/html/dynamic/logs + +EXPOSE 80 + +CMD ["/_docker/run.sh"] + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..562aaaf --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +DOCKER_REPO="registry.blackforestbytes.com" + +DOCKER_NAME=mikescher/website-mscom + +NAMESPACE=$(shell git rev-parse --abbrev-ref HEAD) + +HASH=$(shell git rev-parse HEAD) + +run: + php -S localhost:8000 -t . + +build-docker: + [ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO + git rev-parse --abbrev-ref HEAD >> DOCKER_GIT_INFO + git rev-parse HEAD >> DOCKER_GIT_INFO + git log -1 --format=%cd --date=iso >> DOCKER_GIT_INFO + git config --get remote.origin.url >> DOCKER_GIT_INFO + docker build \ + -t $(DOCKER_NAME):$(HASH) \ + -t $(DOCKER_NAME):$(NAMESPACE)-latest \ + -t $(DOCKER_NAME):latest \ + -t $(DOCKER_REPO)/$(DOCKER_NAME):$(HASH) \ + -t $(DOCKER_REPO)/$(DOCKER_NAME):$(NAMESPACE)-latest \ + -t $(DOCKER_REPO)/$(DOCKER_NAME):latest \ + . + +run-docker: build-docker + mkdir -p ".run-data" + docker run --rm \ + --init \ + --publish 8080:80 \ + --env "SMTP=0" \ + --volume "$(shell pwd)/www/config.php:/var/www/html/config.php:ro" \ + --volume "$(shell pwd)/.run-data/egg:/var/www/html/dynamic/egg" \ + --volume "$(shell pwd)/.run-data/logs:/var/www/html/dynamic/logs" \ + $(DOCKER_NAME):latest + +run-docker-live: build-docker + mkdir -p "$(shell pwd)/.run-data" + docker run --rm \ + --init \ + --publish 8080:80 \ + --volume "$(shell pwd)/www:/var/www/html/" \ + --env "SMTP=0" \ + --volume "$(shell pwd)/www/config.php:/var/www/html/config.php:ro" \ + --volume "$(shell pwd)/.run-data/egg:/var/www/html/dynamic/egg" \ + --volume "$(shell pwd)/.run-data/logs:/var/www/html/dynamic/logs" \ + $(DOCKER_NAME):latest + +inspect-docker: + docker run -ti \ + --rm \ + $(DOCKER_NAME):latest \ + bash + +push-docker: build-docker + docker image push $(DOCKER_REPO)/$(DOCKER_NAME):$(HASH) + docker image push $(DOCKER_REPO)/$(DOCKER_NAME):$(NAMESPACE)-latest + docker image push $(DOCKER_REPO)/$(DOCKER_NAME):latest + +clean: + rm -rf ".run-data" + git clean -fdx \ No newline at end of file