diff --git a/Makefile b/Makefile index ada5305..d498435 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ deploy/teardown: confirm ## deploy/migrate: run database migrations on production .PHONY: deploy/migrate deploy/migrate: confirm - ssh ${production_user}@${production_host} \ + ssh -t ${production_user}@${production_host} \ 'set -a; . /etc/party/environment; set +a; migrate -path /usr/share/party/migrations -database $$PARTY_DB_DSN up' ## deploy: pull latest, build .deb on server, and install it diff --git a/deploy/setup.sh b/deploy/setup.sh index 08974fe..fc4e058 100644 --- a/deploy/setup.sh +++ b/deploy/setup.sh @@ -5,7 +5,7 @@ MIGRATE_VERSION=v4.18.1 REPO_URL=https://git.losandesgames.com/vfs/party apt-get update -q -apt-get install -y -q git golang-go +apt-get install -y -q git golang-go build-essential wget # Install golang-migrate (not in Debian repos) if ! command -v migrate &>/dev/null; then @@ -24,6 +24,7 @@ fi echo "" echo "Setup complete. Next steps:" -echo " 1. make deploy/migrate" -echo " 2. Edit /etc/party/environment with your DB DSN and secrets" -echo " 3. systemctl restart party" +echo " 1. make deploy" +echo " 2. ssh root@ and edit /etc/party/environment with real credentials" +echo " 3. make deploy/migrate" +echo " 4. systemctl restart party" diff --git a/deploy/teardown.sh b/deploy/teardown.sh index f9af51d..57ba3ca 100644 --- a/deploy/teardown.sh +++ b/deploy/teardown.sh @@ -2,7 +2,7 @@ set -euo pipefail # Purge the installed package — removes binary, web assets, /etc/party, and the party user -if dpkg -s party &>/dev/null 2>&1; then +if dpkg -s party &>/dev/null; then dpkg --purge party fi @@ -13,7 +13,7 @@ rm -rf /srv/party rm -f /usr/local/bin/migrate # Remove Go -apt-get remove -y golang-go +apt-get remove -y golang-go build-essential wget apt-get autoremove -y echo "Teardown complete." diff --git a/go.mod b/go.mod index 1fb2cc2..bd5a41f 100644 --- a/go.mod +++ b/go.mod @@ -7,14 +7,14 @@ require ( github.com/gorilla/websocket v1.5.3 github.com/julienschmidt/httprouter v1.3.0 github.com/lib/pq v1.12.0 + github.com/sideshow/apns2 v0.25.0 github.com/wneessen/go-mail v0.7.2 golang.org/x/crypto v0.37.0 - golang.org/x/time v0.15.0 + golang.org/x/time v0.5.0 ) require ( github.com/golang-jwt/jwt/v4 v4.4.1 // indirect - github.com/sideshow/apns2 v0.25.0 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/text v0.29.0 // indirect ) diff --git a/go.sum b/go.sum index 5f2c68c..f621363 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20201120081800-1786d5ef83d4/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= @@ -11,11 +12,13 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4d github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/lib/pq v1.12.0 h1:mC1zeiNamwKBecjHarAr26c/+d8V5w/u4J0I/yASbJo= github.com/lib/pq v1.12.0/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sideshow/apns2 v0.25.0 h1:XOzanncO9MQxkb03T/2uU2KcdVjYiIf0TMLzec0FTW4= github.com/sideshow/apns2 v0.25.0/go.mod h1:7Fceu+sL0XscxrfLSkAoH6UtvKefq3Kq1n4W3ayQZqE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/wneessen/go-mail v0.7.2 h1:xxPnhZ6IZLSgxShebmZ6DPKh1b6OJcoHfzy7UjOkzS8= github.com/wneessen/go-mail v0.7.2/go.mod h1:+TkW6QP3EVkgTEqHtVmnAE/1MRhmzb8Y9/W3pweuS+k= @@ -31,10 +34,11 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= -golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= -golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/golang.org/x/time/LICENSE b/vendor/golang.org/x/time/LICENSE index 2a7cf70..6a66aea 100644 --- a/vendor/golang.org/x/time/LICENSE +++ b/vendor/golang.org/x/time/LICENSE @@ -1,4 +1,4 @@ -Copyright 2009 The Go Authors. +Copyright (c) 2009 The Go Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google LLC nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/vendor/golang.org/x/time/rate/rate.go b/vendor/golang.org/x/time/rate/rate.go index 563270c..8f6c7f4 100644 --- a/vendor/golang.org/x/time/rate/rate.go +++ b/vendor/golang.org/x/time/rate/rate.go @@ -85,7 +85,7 @@ func (lim *Limiter) Burst() int { // TokensAt returns the number of tokens available at time t. func (lim *Limiter) TokensAt(t time.Time) float64 { lim.mu.Lock() - tokens := lim.advance(t) // does not mutate lim + _, tokens := lim.advance(t) // does not mutate lim lim.mu.Unlock() return tokens } @@ -99,9 +99,8 @@ func (lim *Limiter) Tokens() float64 { // bursts of at most b tokens. func NewLimiter(r Limit, b int) *Limiter { return &Limiter{ - limit: r, - burst: b, - tokens: float64(b), + limit: r, + burst: b, } } @@ -186,7 +185,7 @@ func (r *Reservation) CancelAt(t time.Time) { return } // advance time to now - tokens := r.lim.advance(t) + t, tokens := r.lim.advance(t) // calculate new number of tokens tokens += restoreTokens if burst := float64(r.lim.burst); tokens > burst { @@ -195,7 +194,7 @@ func (r *Reservation) CancelAt(t time.Time) { // update state r.lim.last = t r.lim.tokens = tokens - if r.timeToAct.Equal(r.lim.lastEvent) { + if r.timeToAct == r.lim.lastEvent { prevEvent := r.timeToAct.Add(r.limit.durationFromTokens(float64(-r.tokens))) if !prevEvent.Before(t) { r.lim.lastEvent = prevEvent @@ -307,7 +306,7 @@ func (lim *Limiter) SetLimitAt(t time.Time, newLimit Limit) { lim.mu.Lock() defer lim.mu.Unlock() - tokens := lim.advance(t) + t, tokens := lim.advance(t) lim.last = t lim.tokens = tokens @@ -324,7 +323,7 @@ func (lim *Limiter) SetBurstAt(t time.Time, newBurst int) { lim.mu.Lock() defer lim.mu.Unlock() - tokens := lim.advance(t) + t, tokens := lim.advance(t) lim.last = t lim.tokens = tokens @@ -345,9 +344,21 @@ func (lim *Limiter) reserveN(t time.Time, n int, maxFutureReserve time.Duration) tokens: n, timeToAct: t, } + } else if lim.limit == 0 { + var ok bool + if lim.burst >= n { + ok = true + lim.burst -= n + } + return Reservation{ + ok: ok, + lim: lim, + tokens: lim.burst, + timeToAct: t, + } } - tokens := lim.advance(t) + t, tokens := lim.advance(t) // Calculate the remaining number of tokens resulting from the request. tokens -= float64(n) @@ -380,11 +391,10 @@ func (lim *Limiter) reserveN(t time.Time, n int, maxFutureReserve time.Duration) return r } -// advance calculates and returns an updated number of tokens for lim -// resulting from the passage of time. +// advance calculates and returns an updated state for lim resulting from the passage of time. // lim is not changed. // advance requires that lim.mu is held. -func (lim *Limiter) advance(t time.Time) (newTokens float64) { +func (lim *Limiter) advance(t time.Time) (newT time.Time, newTokens float64) { last := lim.last if t.Before(last) { last = t @@ -397,7 +407,7 @@ func (lim *Limiter) advance(t time.Time) (newTokens float64) { if burst := float64(lim.burst); tokens > burst { tokens = burst } - return tokens + return t, tokens } // durationFromTokens is a unit conversion function from the number of tokens to the duration @@ -406,15 +416,8 @@ func (limit Limit) durationFromTokens(tokens float64) time.Duration { if limit <= 0 { return InfDuration } - - duration := (tokens / float64(limit)) * float64(time.Second) - - // Cap the duration to the maximum representable int64 value, to avoid overflow. - if duration > float64(math.MaxInt64) { - return InfDuration - } - - return time.Duration(duration) + seconds := tokens / float64(limit) + return time.Duration(float64(time.Second) * seconds) } // tokensFromDuration is a unit conversion function from a time duration to the number of tokens diff --git a/vendor/golang.org/x/time/rate/sometimes.go b/vendor/golang.org/x/time/rate/sometimes.go index 9b83932..6ba99dd 100644 --- a/vendor/golang.org/x/time/rate/sometimes.go +++ b/vendor/golang.org/x/time/rate/sometimes.go @@ -61,9 +61,7 @@ func (s *Sometimes) Do(f func()) { (s.Every > 0 && s.count%s.Every == 0) || (s.Interval > 0 && time.Since(s.last) >= s.Interval) { f() - if s.Interval > 0 { - s.last = time.Now() - } + s.last = time.Now() } s.count++ } diff --git a/vendor/modules.txt b/vendor/modules.txt index 31884d2..ffc96da 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -57,6 +57,6 @@ golang.org/x/text/transform golang.org/x/text/unicode/bidi golang.org/x/text/unicode/norm golang.org/x/text/width -# golang.org/x/time v0.15.0 -## explicit; go 1.25.0 +# golang.org/x/time v0.5.0 +## explicit; go 1.18 golang.org/x/time/rate