From 3f5e9edfbeea5d370f0507fa7ac77f2a6403bd9d Mon Sep 17 00:00:00 2001 From: mat ess Date: Sun, 28 Aug 2022 14:56:57 -0400 Subject: [PATCH] Add goatcounter build --- goatcounter/Dockerfile | 26 ++++++++++++++++++++++ goatcounter/entrypoint.sh | 19 ++++++++++++++++ goatcounter/fly.toml | 45 ++++++++++++++++++++++++++++++++++++++ goatcounter/goatcounter.sh | 28 ++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 goatcounter/Dockerfile create mode 100755 goatcounter/entrypoint.sh create mode 100644 goatcounter/fly.toml create mode 100755 goatcounter/goatcounter.sh diff --git a/goatcounter/Dockerfile b/goatcounter/Dockerfile new file mode 100644 index 0000000..ee7cd87 --- /dev/null +++ b/goatcounter/Dockerfile @@ -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"] \ No newline at end of file diff --git a/goatcounter/entrypoint.sh b/goatcounter/entrypoint.sh new file mode 100755 index 0000000..29b085c --- /dev/null +++ b/goatcounter/entrypoint.sh @@ -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 "$@" \ No newline at end of file diff --git a/goatcounter/fly.toml b/goatcounter/fly.toml new file mode 100644 index 0000000..ea43b5c --- /dev/null +++ b/goatcounter/fly.toml @@ -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" diff --git a/goatcounter/goatcounter.sh b/goatcounter/goatcounter.sh new file mode 100755 index 0000000..7d686ed --- /dev/null +++ b/goatcounter/goatcounter.sh @@ -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 \ No newline at end of file