initial commit
This commit is contained in:
commit
f6b4c20e4a
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
4
.gitignore
vendored
Executable file
4
.gitignore
vendored
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
*~
|
||||||
|
.DS_Store
|
||||||
|
*.swp
|
||||||
|
tmp/
|
10
.gitlab-ci.yml
Normal file
10
.gitlab-ci.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
build:
|
||||||
|
image: docker:latest
|
||||||
|
services:
|
||||||
|
- docker:dind
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
|
||||||
|
- docker build --pull --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
|
||||||
|
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
|
||||||
|
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
22
Dockerfile
Normal file
22
Dockerfile
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
FROM golang:alpine as builder
|
||||||
|
|
||||||
|
RUN apk --no-cache add git
|
||||||
|
RUN go get -v -u github.com/xenolf/lego
|
||||||
|
|
||||||
|
FROM registry.gitlab.com/thallian/docker-confd-env:master
|
||||||
|
|
||||||
|
COPY --from=builder /go/bin/lego /bin/lego
|
||||||
|
|
||||||
|
ENV PGDATA /var/lib/postgresql/data
|
||||||
|
|
||||||
|
RUN apk add --no-cache postgresql postgresql-contrib ca-certificates
|
||||||
|
|
||||||
|
RUN mkdir -p /run/postgresql && mkdir -p $PGDATA
|
||||||
|
RUN chown -R postgres /run/postgresql && chown -R postgres $PGDATA
|
||||||
|
RUN chmod 775 /run/postgresql
|
||||||
|
|
||||||
|
ADD /rootfs /
|
||||||
|
|
||||||
|
VOLUME /var/lib/postgresql/data
|
||||||
|
|
||||||
|
EXPOSE 5432
|
29
README.md
Normal file
29
README.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
[PostgreSQL](https://www.postgresql.org/) server which provisions
|
||||||
|
tls certificates through [Let's Encrypt](https://letsencrypt.org/) with
|
||||||
|
[lego](https://github.com/xenolf/lego).
|
||||||
|
|
||||||
|
# Volumes
|
||||||
|
- `/var/lib/postgresql/data`
|
||||||
|
- `/var/lib/postgresql/.lego`: certificates directory
|
||||||
|
|
||||||
|
# Environment Variables
|
||||||
|
## POSTGRES_PASSWORD
|
||||||
|
|
||||||
|
Password for the postgre admin user.
|
||||||
|
|
||||||
|
## POSTGRES_CA
|
||||||
|
- default: "https://acme-v01.api.letsencrypt.org/directory"
|
||||||
|
|
||||||
|
Which Acme Endpoint to use.
|
||||||
|
|
||||||
|
## POSTGRES_ACME_EMAIL
|
||||||
|
Email to use in the acme account.
|
||||||
|
|
||||||
|
## POSTGRES_DOMAIN
|
||||||
|
The domain the certificate uses.
|
||||||
|
|
||||||
|
## POSTGRES_DNS_PROVIDER
|
||||||
|
One of the list here: https://github.com/xenolf/lego/tree/master/providers/dns
|
||||||
|
|
||||||
|
# Ports
|
||||||
|
- 5432
|
19
rootfs/bin/renew-certificates
Executable file
19
rootfs/bin/renew-certificates
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/with-contenv sh
|
||||||
|
|
||||||
|
cd /var/lib/postgresql
|
||||||
|
|
||||||
|
OLD_MOD=$(stat -c %y /var/lib/postgresql/.lego/certificates/${POSTGRES_DOMAIN}.crt)
|
||||||
|
|
||||||
|
lego \
|
||||||
|
--accept-tos \
|
||||||
|
--server="${POSTGRES_CA}" \
|
||||||
|
--email="${POSTGRES_ACME_EMAIL}" \
|
||||||
|
--domains="${POSTGRES_DOMAIN}" \
|
||||||
|
--dns="${POSTGRES_DNS_PROVIDER}" \
|
||||||
|
renew --days 30
|
||||||
|
|
||||||
|
NEW_MOD=$(stat -c %y /var/lib/postgresql/.lego/certificates/${POSTGRES_DOMAIN}.crt)
|
||||||
|
|
||||||
|
if [ "${OLD_MOD}" != "${NEW_MOD}" ]; then
|
||||||
|
kill -s TERM $(head -1 ${PGDATA}/postmaster.pid)
|
||||||
|
fi
|
5
rootfs/etc/confd/conf.d/pg_hba.conf.toml
Normal file
5
rootfs/etc/confd/conf.d/pg_hba.conf.toml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[template]
|
||||||
|
src = "pg_hba.conf.tmpl"
|
||||||
|
dest = "/var/lib/postgresql/data/pg_hba.conf"
|
||||||
|
gid = 70
|
||||||
|
uid = 70
|
3
rootfs/etc/confd/templates/pg_hba.conf.tmpl
Normal file
3
rootfs/etc/confd/templates/pg_hba.conf.tmpl
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
local all all trust
|
||||||
|
hostssl all all 0.0.0.0/0 md5
|
||||||
|
host all all ::1/128 trust
|
5
rootfs/etc/cont-init.d/00-initdb
Normal file
5
rootfs/etc/cont-init.d/00-initdb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/with-contenv sh
|
||||||
|
|
||||||
|
if [ ! -f ${PGDATA}/PG_VERSION ]; then
|
||||||
|
s6-setuidgid postgres initdb --username=postgres
|
||||||
|
fi
|
11
rootfs/etc/cont-init.d/00-password
Normal file
11
rootfs/etc/cont-init.d/00-password
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/with-contenv sh
|
||||||
|
|
||||||
|
cat <<EOF > /var/lib/postgresql/data/pg_hba.conf
|
||||||
|
local all all trust
|
||||||
|
EOF
|
||||||
|
|
||||||
|
s6-setuidgid postgres pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost'" -w start
|
||||||
|
|
||||||
|
s6-setuidgid postgres psql --command "ALTER USER postgres WITH PASSWORD '${POSTGRES_PASSWORD}';"
|
||||||
|
|
||||||
|
s6-setuidgid postgres pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost'" -w stop
|
30
rootfs/etc/cont-init.d/02-certificates
Normal file
30
rootfs/etc/cont-init.d/02-certificates
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/with-contenv sh
|
||||||
|
|
||||||
|
cd /var/lib/postgresql
|
||||||
|
|
||||||
|
SAN_DOMAINS=""
|
||||||
|
|
||||||
|
export IFS=";"
|
||||||
|
for SAN in ${POSTGRES_SAN}
|
||||||
|
do
|
||||||
|
SAN_DOMAINS="${SAN_DOMAINS} --domains=\"${SAN}\""
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -f /var/lib/postgresql/.lego/certificates/${POSTGRES_DOMAIN}.crt ]; then
|
||||||
|
chown -R postgres /var/lib/postgresql/.lego
|
||||||
|
s6-setuidgid postgres lego \
|
||||||
|
--accept-tos \
|
||||||
|
--server="${POSTGRES_CA}" \
|
||||||
|
--email="${POSTGRES_ACME_EMAIL}" \
|
||||||
|
--domains="${POSTGRES_DOMAIN}" ${SAN_DOMAINS} \
|
||||||
|
--dns="${POSTGRES_DNS_PROVIDER}" \
|
||||||
|
run
|
||||||
|
else
|
||||||
|
s6-setuidgid postgres lego \
|
||||||
|
--accept-tos \
|
||||||
|
--server="${POSTGRES_CA}" \
|
||||||
|
--email="${POSTGRES_ACME_EMAIL}" \
|
||||||
|
--domains="${POSTGRES_DOMAIN}" \
|
||||||
|
--dns="${POSTGRES_DNS_PROVIDER}" \
|
||||||
|
renew --days 30
|
||||||
|
fi
|
1
rootfs/etc/fix-attrs.d/01-pgdata
Normal file
1
rootfs/etc/fix-attrs.d/01-pgdata
Normal file
@ -0,0 +1 @@
|
|||||||
|
/var/lib/postgresql true postgres 0600 0700
|
8
rootfs/etc/services.d/postgres/run
Executable file
8
rootfs/etc/services.d/postgres/run
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/with-contenv sh
|
||||||
|
|
||||||
|
s6-setuidgid postgres postgres \
|
||||||
|
-D $PGDATA \
|
||||||
|
-c listen_addresses='*' \
|
||||||
|
-c ssl=on \
|
||||||
|
-c ssl_cert_file="/var/lib/postgresql/.lego/certificates/${POSTGRES_DOMAIN}.crt" \
|
||||||
|
-c ssl_key_file="/var/lib/postgresql/.lego/certificates/${POSTGRES_DOMAIN}.key"
|
1
rootfs/var/spool/cron/crontab/postgres
Normal file
1
rootfs/var/spool/cron/crontab/postgres
Normal file
@ -0,0 +1 @@
|
|||||||
|
0 3 * * * /bin/renew-certificates
|
Loading…
Reference in New Issue
Block a user