1
0

Added Dockerfile [WIP]

This commit is contained in:
Mike Schwörer 2022-12-10 18:24:39 +01:00
parent 847f4f4781
commit 74359ef6f7
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
6 changed files with 155 additions and 1 deletions

55
.docker/init.sh Normal file
View File

@ -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

7
.docker/run.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
/_docker/init.sh || exit 1
apache2-foreground

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
www/config.php

4
.gitignore vendored
View File

@ -9,4 +9,6 @@ runtime/
config.php
www/dtest.php
www/dtest.php
DOCKER_GIT_INFO

26
Dockerfile Normal file
View File

@ -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"]

63
Makefile Normal file
View File

@ -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