Skip to content

Commit 2ade1c7

Browse files
committed
Merge branch 'staging'
# Conflicts: # api.go # go.mod
2 parents 94eebaa + 2bdd74b commit 2ade1c7

File tree

7 files changed

+83
-52
lines changed

7 files changed

+83
-52
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Set up Go
11-
uses: actions/setup-go@v2
11+
uses: actions/setup-go@v3
1212
with:
1313
go-version: 1.19
1414

1515
- name: Check out code into the Go module directory
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v3
1717

1818
- name: Download dependencies
1919
run: sudo apt update && sudo apt install -y build-essential libpng-dev

.github/workflows/release.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Set up Go
14-
uses: actions/setup-go@v2
14+
uses: actions/setup-go@v3
1515
with:
1616
go-version: 1.19
1717

1818
- name: Check out code into the Go module directory
19-
uses: actions/checkout@v2
19+
uses: actions/checkout@v3
2020
with:
2121
fetch-depth: 0
2222

2323
- name: Download dependencies
2424
run: sudo apt update && sudo apt install -y build-essential libpng-dev
2525

2626
- name: Run GoReleaser
27-
uses: goreleaser/goreleaser-action@v2
27+
uses: goreleaser/goreleaser-action@v3
2828
with:
2929
version: latest
3030
args: release --rm-dist
@@ -36,35 +36,37 @@ jobs:
3636
runs-on: ubuntu-latest
3737
steps:
3838
- name: Check out code into the Go module directory
39-
uses: actions/checkout@v2
39+
uses: actions/checkout@v3
4040
with:
4141
fetch-depth: 0
4242

4343
- name: Login to GitHub Container Registry
44-
uses: docker/login-action@v1
44+
uses: docker/login-action@v2
4545
with:
4646
registry: ghcr.io
4747
username: ${{ github.actor }}
4848
password: ${{ secrets.GITHUB_TOKEN }}
4949

5050
- name: Extract metadata (tags, labels) for Docker
5151
id: meta
52-
uses: docker/metadata-action@v3
52+
uses: docker/metadata-action@v4
5353
with:
5454
images: ghcr.io/${{ github.repository }}
5555

5656
- name: Set up Docker Buildx
5757
id: buildx
58-
uses: docker/setup-buildx-action@v1
58+
uses: docker/setup-buildx-action@v2
5959
with:
6060
buildkitd-flags: --debug
6161

6262
- name: Build and push Docker image
63-
uses: docker/build-push-action@v2
63+
uses: docker/build-push-action@v3
6464
with:
6565
context: .
6666
push: true
6767
tags: ${{ steps.meta.outputs.tags }}
6868
labels: ${{ steps.meta.outputs.labels }}
6969
build-args: |
7070
TARGET_ENV=${{ matrix.release }}
71+
cache-from: type=gha
72+
cache-to: type=gha,mode=max

.github/workflows/staging.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Check out code into the Go module directory
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v3
1515
with:
1616
fetch-depth: 0
1717

1818
- name: Login to GitHub Container Registry
19-
uses: docker/login-action@v1
19+
uses: docker/login-action@v2
2020
with:
2121
registry: ghcr.io
2222
username: ${{ github.actor }}
2323
password: ${{ secrets.GITHUB_TOKEN }}
2424

2525
- name: Extract metadata (tags, labels) for Docker
2626
id: meta
27-
uses: docker/metadata-action@v3
27+
uses: docker/metadata-action@v4
2828
with:
2929
images: ghcr.io/${{ github.repository }}
3030
flavor: |
@@ -34,14 +34,16 @@ jobs:
3434
3535
- name: Set up Docker Buildx
3636
id: buildx
37-
uses: docker/setup-buildx-action@v1
37+
uses: docker/setup-buildx-action@v2
3838
with:
3939
buildkitd-flags: --debug
4040

4141
- name: Build and push Docker image
42-
uses: docker/build-push-action@v2
42+
uses: docker/build-push-action@v3
4343
with:
4444
context: .
4545
push: true
4646
tags: ${{ steps.meta.outputs.tags }}
4747
labels: ${{ steps.meta.outputs.labels }}
48+
cache-from: type=gha
49+
cache-to: type=gha,mode=max

api.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package smr
33
import (
44
"context"
55
"fmt"
6-
"net/http"
76
"os"
87
"os/signal"
98
"runtime"
9+
"syscall"
10+
"time"
1011

1112
"github.com/satisfactorymodding/smr-api/auth"
1213
"github.com/satisfactorymodding/smr-api/config"
@@ -26,9 +27,6 @@ import (
2627
"github.com/satisfactorymodding/smr-api/redis"
2728
"github.com/satisfactorymodding/smr-api/redis/jobs"
2829

29-
"syscall"
30-
"time"
31-
3230
// Load redis consumers
3331
_ "github.com/satisfactorymodding/smr-api/redis/jobs/consumers"
3432
"github.com/satisfactorymodding/smr-api/storage"
@@ -40,6 +38,8 @@ import (
4038
"github.com/99designs/gqlgen/graphql/handler/lru"
4139
"github.com/99designs/gqlgen/graphql/handler/transport"
4240
"github.com/99designs/gqlgen/graphql/playground"
41+
"github.com/felixge/fgprof"
42+
"github.com/labstack/echo-contrib/pprof"
4343
"github.com/labstack/echo/v4"
4444
"github.com/labstack/echo/v4/middleware"
4545
"github.com/rs/zerolog/log"
@@ -84,9 +84,16 @@ func Serve() {
8484

8585
migrations.RunMigrations(ctx)
8686

87-
if !viper.GetBool("production") {
87+
if viper.GetBool("profiler") {
8888
go func() {
89-
log.Err(http.ListenAndServe("0.0.0.0:6060", nil)).Msg("Debug server")
89+
debugServer := echo.New()
90+
pprof.Register(debugServer)
91+
debugServer.Any("/debug/fgprof", echo.WrapHandler(fgprof.Handler()))
92+
debugServer.HideBanner = true
93+
debugServer.HidePort = true
94+
address := ":6060"
95+
log.Info().Str("address", address).Msg("starting profiler")
96+
debugServer.Logger.Fatal(debugServer.Start(address))
9097
}()
9198
}
9299

@@ -168,11 +175,11 @@ func Serve() {
168175
MaxMemory: 100 << 20,
169176
})
170177

171-
gqlHandler.SetQueryCache(lru.New(1000))
178+
gqlHandler.SetQueryCache(lru.New(5000))
172179

173180
gqlHandler.Use(extension.Introspection{})
174181
gqlHandler.Use(extension.AutomaticPersistedQuery{
175-
Cache: lru.New(100),
182+
Cache: lru.New(5000),
176183
})
177184

178185
v2Query.Any("", echo.WrapHandler(gqlHandler))

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func initializeDefaults() {
4646
viper.SetDefault("port", "5020")
4747

4848
viper.SetDefault("production", true)
49+
viper.SetDefault("profiler", false)
4950

5051
viper.SetDefault("database.redis.host", "localhost")
5152
viper.SetDefault("database.redis.port", 6379)

go.mod

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/satisfactorymodding/smr-api
33
go 1.19
44

55
require (
6-
github.com/99designs/gqlgen v0.17.5
6+
github.com/99designs/gqlgen v0.17.16
77
github.com/Masterminds/semver/v3 v3.1.1
88
github.com/Vilsol/ue4pak v0.1.5
99
github.com/VirusTotal/vt-go v0.0.0-20220413144842-e010bf48aaee
@@ -13,11 +13,13 @@ require (
1313
github.com/cespare/xxhash v1.1.0
1414
github.com/chai2010/webp v1.1.1
1515
github.com/dgraph-io/ristretto v0.1.0
16+
github.com/felixge/fgprof v0.9.3
1617
github.com/finnbear/moderation v0.11.4
1718
github.com/go-redis/redis v6.15.9+incompatible
1819
github.com/go-redis/redis/v8 v8.11.5
1920
github.com/golang-migrate/migrate/v4 v4.15.2
2021
github.com/lab259/go-migration v1.3.1
22+
github.com/labstack/echo-contrib v0.13.0
2123
github.com/labstack/echo/v4 v4.7.2
2224
github.com/microcosm-cc/bluemonday v1.0.18
2325
github.com/mitchellh/hashstructure/v2 v2.0.2
@@ -31,7 +33,7 @@ require (
3133
github.com/spf13/viper v1.11.0
3234
github.com/swaggo/echo-swagger v1.3.2
3335
github.com/swaggo/swag v1.8.1
34-
github.com/vektah/gqlparser/v2 v2.4.2
36+
github.com/vektah/gqlparser/v2 v2.5.0
3537
github.com/vmihailenco/taskq/extra/taskqotel/v3 v3.2.8
3638
github.com/vmihailenco/taskq/v3 v3.2.8
3739
github.com/xeipuuv/gojsonschema v1.2.0
@@ -42,8 +44,8 @@ require (
4244
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.7.0
4345
go.opentelemetry.io/otel/sdk v1.7.0
4446
go.opentelemetry.io/otel/trace v1.7.0
45-
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88
46-
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
47+
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
48+
golang.org/x/net v0.0.0-20220728030405-41545e8bf201
4749
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
4850
gopkg.in/go-playground/validator.v9 v9.31.0
4951
gorm.io/driver/postgres v1.3.5
@@ -84,6 +86,7 @@ require (
8486
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
8587
github.com/golang/glog v1.0.0 // indirect
8688
github.com/golang/protobuf v1.5.2 // indirect
89+
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
8790
github.com/google/uuid v1.3.0 // indirect
8891
github.com/gorilla/css v1.0.0 // indirect
8992
github.com/gorilla/websocket v1.5.0 // indirect
@@ -110,7 +113,6 @@ require (
110113
github.com/lib/pq v1.10.2 // indirect
111114
github.com/magiconair/properties v1.8.6 // indirect
112115
github.com/mailru/easyjson v0.7.7 // indirect
113-
github.com/matryer/moq v0.2.7 // indirect
114116
github.com/mattn/go-colorable v0.1.12 // indirect
115117
github.com/mattn/go-isatty v0.0.14 // indirect
116118
github.com/pelletier/go-toml v1.9.4 // indirect
@@ -125,30 +127,31 @@ require (
125127
github.com/subosito/gotenv v1.2.0 // indirect
126128
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 // indirect
127129
github.com/thedevsaddam/gojsonq/v2 v2.5.2 // indirect
128-
github.com/urfave/cli/v2 v2.4.0 // indirect
130+
github.com/urfave/cli/v2 v2.8.1 // indirect
129131
github.com/valyala/bytebufferpool v1.0.0 // indirect
130132
github.com/valyala/fasttemplate v1.2.1 // indirect
131133
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
132134
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
133135
github.com/x448/float16 v0.8.4 // indirect
134136
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
135137
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
138+
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
136139
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.7.0 // indirect
137140
go.opentelemetry.io/proto/otlp v0.16.0 // indirect
138-
go.uber.org/atomic v1.7.0 // indirect
141+
go.uber.org/atomic v1.9.0 // indirect
139142
golang.org/x/exp v0.0.0-20210220032938-85be41e4509f // indirect
140143
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
141-
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
144+
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
142145
golang.org/x/text v0.3.7 // indirect
143-
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
146+
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
144147
golang.org/x/tools v0.1.10 // indirect
145148
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
146149
google.golang.org/appengine v1.6.7 // indirect
147150
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac // indirect
148-
google.golang.org/grpc v1.46.0 // indirect
151+
google.golang.org/grpc v1.48.0 // indirect
149152
google.golang.org/protobuf v1.28.0 // indirect
150153
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
151154
gopkg.in/ini.v1 v1.66.4 // indirect
152155
gopkg.in/yaml.v2 v2.4.0 // indirect
153-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
156+
gopkg.in/yaml.v3 v3.0.1 // indirect
154157
)

0 commit comments

Comments
 (0)