Skip to content

Commit

Permalink
Update README, deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Mar 29, 2021
1 parent 3958a44 commit 9200e53
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 59 deletions.
16 changes: 4 additions & 12 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,13 @@ This list is not comprehensive, and only lists new features and major changes,
but not every minor bugfix. The goatcounter.com service generally runs the
latest master.

Changes since rc1
2021-03-29 v2.0.0
-----------------
- MFA login was broken 🤦
- Make sure GoatCounter works even when the `tzdata` package isn't available.
- Revamped integration documentation; what started as a single short page grew
in to a rather long chaotic page so clean that up a bit.

2021-03-20 v2.0.0-rc1
---------------------

The version is bumped to 2.0 because this contains a number of incompatible
changes: several CLI commands got changed, and it includes some large database
migrations – running them is a bit more complex than the standard migrations.

Because this includes so many changes I'll do a Release Candidate first. Please
report issues if you have any problems! Barring unexpected large issues I'll do
a 2.0 release next week or so.

An overview of **incompatible** changes:

- There are some rather large changes to the database layout for better
Expand Down Expand Up @@ -175,6 +164,9 @@ An overview of **incompatible** changes:

- Many other minor changes and improvements.

- For changes since RC1 see:
https://github.com/zgoat/goatcounter/compare/v2.0.0-rc1...v2.0.0


2020-11-10, v1.4.2
------------------
Expand Down
58 changes: 31 additions & 27 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ GoatCounter should run on any platform supported by Go, but there are no
binaries for them (yet); you'll have to build from source if you want to run it
on e.g. FreeBSD or macOS.

Note this README is for the latest master; use the [`release-1.4`][r-1.4] branch
for the 1.4 README.
Note this README is for the latest master; use the [`release-2.0`][r-2.0] branch
for the 2.0 README.

Generally speaking only the latest release is supported, although critical fixes
(security, data loss, etc.) may get backported to previous releases.

[releases]: https://github.com/zgoat/goatcounter/releases
[r-1.4]: https://github.com/zgoat/goatcounter/tree/release-1.4
[r-2.0]: https://github.com/zgoat/goatcounter/tree/release-2.0

### Deploy scripts and such

Expand Down Expand Up @@ -136,9 +136,12 @@ Generally speaking only the latest release is supported, although critical fixes

### Building from source

You need Go 1.16 or newer and a C compiler (for SQLite). If you compile it with
`CGO_ENABLED=0` you don't need a C compiler but can only use PostgreSQL.

Compile from source with:

$ git clone -b release-1.4 https://github.com/zgoat/goatcounter.git
$ git clone -b release-2.0 https://github.com/zgoat/goatcounter.git
$ cd goatcounter
$ go build -ldflags="-X zgo.at/goatcounter.Version=$(git log -n1 --format='%h_%cI')" ./cmd/goatcounter

Expand All @@ -156,14 +159,21 @@ To build a fully statically linked binary:
-ldflags="-X zgo.at/goatcounter.Version=$(git log -n1 --format='%h_%cI') -extldflags=-static" \
./cmd/goatcounter

You need Go 1.16 or newer and a C compiler (for SQLite). If you compile it with
`CGO_ENABLED=0 go build` you don't need a C compiler, but can only use PostgreSQL.

It's recommended to use the latest release as in the above command. The master
branch should be reasonably stable but no guarantees, and sometimes I don't
write detailed release/upgrade notes until the actual release so you may run in
to surprises.

You can compile goatcounter without cgo if you're planning to use PostgreSQL and
don't use SQLite:

$ CGO_ENABLED=0 go build \
-ldflags="-X zgo.at/goatcounter.Version=$(git log -n1 --format='%h_%cI')" \
./cmd/goatcounter

Functionally it doesn't matter too much, but builds will be a bit easier and
faster as it won't require a C compiler.

### Running

You can start a server with:
Expand All @@ -174,6 +184,11 @@ The default is to use an SQLite database at `./db/goatcounter.sqlite3`, which
will be created if it doesn't exist yet. See the `-db` flag and `goatcounter
help db` to customize this.

Both SQLite and PostgreSQL are supported. SQLite should work well for most
smaller sites, but PostgreSQL gives better performance. There are [some
benchmarks over here][bench] to give some indication of what performance to
expect from SQLite and PostgreSQL.

GoatCounter will listen on port `*:80` and `*:443` by default. You don't need
to run it as root and can grant the appropriate permissions on Linux with:

Expand All @@ -190,6 +205,8 @@ This will ask for a password for your new account; you can also add a password
on the commandline with `-password`. You must also pass the `-db` flag here if
you use something other than the default.

[bench]: https://github.com/zgoat/goatcounter/blob/master/docs/benchmark.markdown

### Updating

You may need to run the database migrations when updating. Use `goatcounter
Expand All @@ -205,30 +222,17 @@ Use `goatcounter migrate pending` to get a list of pending migrations, or

### PostgreSQL

Both SQLite and PostgreSQL are supported. SQLite should work well for most
smaller sites, but PostgreSQL gives some better performance:

1. Run with custom `-db` flag:

$ goatcounter serve -db 'postgresql://dbname=goatcounter'

Or use a socket:

$ goatcounter serve \
-db 'postgresql://host=/run/postgresql dbname=goatcounter sslmode=disable'

You can also use the `PG*` environment variables:

$ PGDATABASE=goatcounter DBHOST=/var/run goatcounter serve -db 'postgresql://'
To use PostgreSQL run GoatCounter with a custom `-db` flag; for example:

See `goatcounter help db` and the [pq docs][pq] for more details.
$ goatcounter serve -db 'postgresql://dbname=goatcounter'
$ goatcounter serve -db 'postgresql://host=/run/postgresql dbname=goatcounter sslmode=disable'

2. You can compile goatcounter without cgo if you don't use SQLite:
This follows the format in the `psql` CLI; you can also use the `PG*`
environment variables:

$ CGO_ENABLED=0 go build -ldflags="-X zgo.at/goatcounter.Version=$(git log -n1 --format='%h_%cI')" ./cmd/goatcounter
$ PGDATABASE=goatcounter DBHOST=/run/postgresql goatcounter serve -db 'postgresql://'

Functionally it doesn't matter too much, but builds will be a bit easier and
faster as it won't require a C compiler.
See `goatcounter help db` and the [pq docs][pq] for more details.

[pq]: https://pkg.go.dev/github.com/lib/pq#hdr-Connection_String_Parameters

Expand Down
10 changes: 6 additions & 4 deletions cmd/gcbench/gcbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ func main() {
})
zli.F(err)

first := time.Now().Add(-time.Duration(r.nDays) * 24 * time.Hour)

r.ctx = goatcounter.NewContext(r.db)
s := goatcounter.Site{
Cname: zstring.NewPtr("gcbench.localhost").P,
Plan: goatcounter.PlanBusinessPlus,
Settings: goatcounter.SiteSettings{Public: true},
// site.FirstHitAt = dates[len(dates)-1]
Cname: zstring.NewPtr("gcbench.localhost").P,
Plan: goatcounter.PlanBusinessPlus,
Settings: goatcounter.SiteSettings{Public: true},
FirstHitAt: first,
}
zli.F(s.Insert(r.ctx))
r.ctx = goatcounter.WithSite(r.ctx, &s)
Expand Down
3 changes: 3 additions & 0 deletions deploy/README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Various ways to deploy GoatCounter; see the subdirectories for details.

- alpine – Set up an Alpine Linux machine.
24 changes: 24 additions & 0 deletions deploy/alpine/README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This sets up a basic GoatCounter installation on Alpine Linux, using SQLite.

This is also available as a ["StackScript" for Linode][s]; If you don't have a
Linode account yet then [consider using my "referral URL"][r] and I'll get some
cash back from Linode :-)

It should be fine to run this more than once; and can be used to upgrade to a
newer version.

You can set the version to use with `GOATCOUNTER_VERSION`; this needs to be a
release on GitHub:

$ GOATCOUNTER_VERSION=v2.0.0 ./goatcounter-alpine.sh

You can create additional sites with:

$ cd /home/goatcounter
$ ./bin/goatcounter db create site -domain example.com -email [email protected]

Files are stored in `/home/goatcounter`; see `/var/log/goatcounter/current` for
logs; and you can configure the flags in `/etc/conf.d/goatcounter`

[s]: https://cloud.linode.com/stackscripts/659823
[r]: https://www.linode.com/?r=7acaf75737436d859e785dd5c9abe1ae99b4387e
45 changes: 29 additions & 16 deletions deploy/StackScript → deploy/alpine/goatcounter-alpine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,41 @@
# <UDF name="goatcounter_domain" label="Domain you'll be hosting GoatCounter on" example="stats.example.com" />
# <UDF name="goatcounter_email" label="Your email address" example="[email protected]" />
# <UDF name="goatcounter_password" label="Password to access GoatCounter" example="Password 1234 :-)" />
# <UDF name="goatcounter_version" label="GoatCounter version" default="v1.4.1" />
# <UDF name="goatcounter_version" label="GoatCounter version" default="v2.0.0" />
#
# This is a "StackScript" to deploy GoatCounter on a Linode VPS; it's available
# in Linode as: https://cloud.linode.com/stackscripts/659823
# This will set up an Alpine Linux machine; environment variables:
# GOATCOUNTER_DOMAIN Domain you'll be hosting GoatCounter on
# GOATCOUNTER_EMAIL Your email address
# GOATCOUNTER_PASSWORD Password to access GoatCounter
# GOATCOUNTER_VERSION GoatCounter version (default: v2.0.0).
#
# This script should also work fine outside of Linode; it does assume you're
# using Alpine Linux.
# This is available as a "StackScript" to deploy GoatCounter on a Linode VPS:
# https://cloud.linode.com/stackscripts/659823
#
# If you don't have a Linode account yet then consider using my "referral URL"
# and I'll get some cash back from Linode :-)
# https://www.linode.com/?r=7acaf75737436d859e785dd5c9abe1ae99b4387e
#
# This script's source at the GoatCounter repo is:
# https://github.com/zgoat/goatcounter/blob/master/deploy/StackScript
# https://github.com/zgoat/goatcounter/blob/master/deploy/alpine
#
# It should be fine to run this more than once; and can be used to upgrade to a
# newer version.
#
# You can create additional sites with:
# Files are stored in /home/goatcounter; see /var/log/goatcounter for logs; and
# you can configure the flags in /etc/conf.d/goatcounter.
#
# $ cd /home/goatcounter
# $ ./bin/goatcounter db create site -domain example.com -email [email protected]
# You can create additional sites with
#
# Files are stored in /home/goatcounter; see /var/log/goatcounter/current for
# logs; and you can configure the flags it starts with in /etc/conf.d/goatcounter.
# $ cd /home/goatcounter
# $ ./bin/goatcounter db create site [..]
#
# Please report any bugs, problems, or other issues on the GoatCounter issue
# tracker, or email me at [email protected]
#

# GoatCounter version to set up.
v=${GOATCOUNTER_VERSION:-v1.4.1}
v=${GOATCOUNTER_VERSION:-"v2.0.0"}


set -eu
Expand All @@ -60,7 +63,7 @@ apk add tzdata
grep -q '^goatcounter:' /etc/group || addgroup -S goatcounter
grep -q '^goatcounter:' /etc/passwd || adduser -s /sbin/nologin -DS -G goatcounter goatcounter

# Get latest version.
# Get latest version if it doesn't exist yet.
mkdir -p /home/goatcounter/bin
dst="/home/goatcounter/bin/goatcounter-$v"
if [ ! -f "$dst" ]; then
Expand All @@ -74,7 +77,7 @@ ln -sf "$dst" "/home/goatcounter/bin/goatcounter"

# Set up site; this may fail if the site already exists, which is fine.
cd /home/goatcounter
./bin/goatcounter db create site -createdb -domain "$GOATCOUNTER_DOMAIN" -email "$GOATCOUNTER_EMAIL" -password "$GOATCOUNTER_PASSWORD" ||:
./bin/goatcounter db create site -createdb -vhost "$GOATCOUNTER_DOMAIN" -user.email "$GOATCOUNTER_EMAIL" -user.password "$GOATCOUNTER_PASSWORD" ||:
chown -R goatcounter:goatcounter db

# Set up log directory.
Expand All @@ -97,6 +100,11 @@ pidfile="/run/\${RC_SVCNAME}.pid"
output_log="/var/log/\${RC_SVCNAME}/current"
error_log="/var/log/\${RC_SVCNAME}/current"
start_pre() {
# Make sure this is correct after updates etc.
setcap 'cap_net_bind_service=+ep cap_sys_chroot=+ep' "\$(readlink "\$command")"
}
depend() {
use net
use dns
Expand All @@ -105,15 +113,20 @@ depend() {
EOF

cat << EOF > /etc/conf.d/goatcounter
# These are the defaults.
# The uncommented values are the defaults.
# Listen on all addressed.
# Listen on all addresses.
#GOATCOUNTER_LISTEN=:443
# Location of SQLite3 database file or PostgreSQL connection. GoatCounter is
# started from /home/goatcounter.
#GOATCOUNTER_DB="sqlite://./db/goatcounter.sqlite3"
# If you use PostgreSQL then URI-type connector is recommended, as OpenRC can't
# deal well with spaces; for example:
#GOATCOUNTER_DB="postgresql:///run/postgresql/goatcounter?sslmode=disable"
# Other flags to add. See "goatcounter help serve".
#GOATCOUNTER_ARGS="-automigrate"
EOF
Expand Down
Loading

0 comments on commit 9200e53

Please sign in to comment.