Add goatcounter build

main
mat ess 2022-08-28 14:56:57 -04:00
parent 5070619286
commit 3f5e9edfbe
4 changed files with 118 additions and 0 deletions

26
goatcounter/Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM debian:bookworm-slim
WORKDIR /goatcounter
ENV GOATCOUNTER_VERSION 'v2.2.3'
ENV GOATCOUNTER_TAG 'dev'
ENV GOATCOUNTER_LISTEN '0.0.0.0:8080'
ENV GOATCOUNTER_DB 'sqlite+/data/goatcounter.sqlite3'
ENV GOATCOUNTER_SMTP ''
RUN apt-get update \
&& apt-get install -y ca-certificates ncat wget \
&& update-ca-certificates --fresh
RUN wget "https://github.com/zgoat/goatcounter/releases/download/$GOATCOUNTER_VERSION/goatcounter-$GOATCOUNTER_TAG-linux-amd64.gz" \
&& gzip -d "goatcounter-$GOATCOUNTER_TAG-linux-amd64.gz" \
&& mv "goatcounter-$GOATCOUNTER_TAG-linux-amd64" /usr/bin/goatcounter \
&& chmod +x /usr/bin/goatcounter
COPY goatcounter.sh ./
COPY entrypoint.sh /entrypoint.sh
EXPOSE 8080
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/goatcounter/goatcounter.sh"]

19
goatcounter/entrypoint.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eu
create_site ()
{
goatcounter db create site \
-vhost "$GOATCOUNTER_DOMAIN" \
-user.email "$GOATCOUNTER_EMAIL" \
-password "$GOATCOUNTER_PASSWORD" \
-db "$GOATCOUNTER_DB"
}
# silence any errors
if ! create_site; then
/bin/true
fi
exec "$@"

45
goatcounter/fly.toml Normal file
View File

@ -0,0 +1,45 @@
# fly.toml file generated for goatcounter-mat-services on 2022-08-27T22:27:36-04:00
app = "goatcounter-mat-services"
kill_signal = "SIGINT"
kill_timeout = 5
[env]
GOATCOUNTER_DOMAIN = "stats.mat.services"
GOATCOUNTER_EMAIL = "mat@mat.services"
LOG_SOURCE_HOST = "static-mat-services.internal"
LOG_SOURCE_PORT = "514"
[experimental]
allowed_public_ports = []
auto_rollback = true
[mounts]
destination = "/data"
source = "goatcounter_data"
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

28
goatcounter/goatcounter.sh Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -e
declare OPTS=""
OPTS="$OPTS -automigrate"
OPTS="$OPTS -listen $GOATCOUNTER_LISTEN"
OPTS="$OPTS -tls none"
OPTS="$OPTS -email-from $GOATCOUNTER_EMAIL"
OPTS="$OPTS -db $GOATCOUNTER_DB"
if [ -n "$GOATCOUNTER_SMTP" ]; then
OPTS="$OPTS -smtp $GOATCOUNTER_SMTP"
fi
if [ -n "$GOATCOUNTER_DEBUG" ]; then
OPTS="$OPTS -debug all"
fi
ncat -l 9090 > /data/caddy.log &
goatcounter import \
-site=$GOATCOUNTER_DOMAIN \
-follow \
-format=combined \
/data/caddy.log &
goatcounter serve $OPTS