Skip to content

Commit fdeaf53

Browse files
committed
init
1 parent fd6640c commit fdeaf53

27 files changed

+2298
-0
lines changed

.github/workflows/build.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build and Publish Docker Images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Log in to GitHub Container Registry
20+
uses: docker/login-action@v1
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Build and Push Backend Docker Image
27+
uses: docker/build-push-action@v2
28+
with:
29+
context: .
30+
file: ./Dockerfile
31+
push: true
32+
tags: ghcr.io/gttp-cli/website:backend
33+
34+
- name: Build and Push Frontend Docker Image
35+
uses: docker/build-push-action@v2
36+
with:
37+
context: ./web
38+
file: ./web/Dockerfile
39+
push: true
40+
tags: ghcr.io/gttp-cli/website:frontend

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# IDE Files
2+
.idea
3+
.vscode
4+
5+
# Backend Data
6+
pb_data

Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Make Go Builder
2+
FROM golang:alpine as go-builder
3+
WORKDIR /app
4+
COPY ./go.mod .
5+
COPY ./go.sum .
6+
RUN go mod download
7+
COPY ./cmd ./cmd
8+
#COPY ./internal ./internal
9+
COPY ./migrations ./migrations
10+
#COPY ./pkg ./pkg
11+
ENV CGO_ENABLED=0
12+
RUN go build -o server ./cmd/server/main.go
13+
14+
# Make final image
15+
FROM alpine
16+
ENV NODE_ENV production
17+
WORKDIR /app
18+
COPY --from=go-builder /app/server ./server
19+
ENTRYPOINT ["./server", "serve", "--http=0.0.0.0:80"]
20+
21+
EXPOSE 80

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
backend:
2+
@go run ./cmd/server serve
3+
4+
setup:
5+
@echo Installing Go dependencies...
6+
@cd ./cmd/server && go get
7+
@echo Installing Node dependencies...
8+
@cd ./web && pnpm install
9+
10+
frontend:
11+
@cd ./web && npm run dev
12+
13+
full:
14+
@docker compose build && docker compose up
15+
16+
down:
17+
@docker compose down
18+
19+
publish:
20+
@docker compose build && docker compose push gttp-backend && docker compose push gttp-frontend

cmd/server/main.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"log/slog"
5+
"os"
6+
7+
"github.com/pocketbase/pocketbase/apis"
8+
"github.com/pocketbase/pocketbase/plugins/migratecmd"
9+
"github.com/pterm/pterm"
10+
slogecho "github.com/samber/slog-echo"
11+
12+
"github.com/labstack/echo/v5/middleware"
13+
"github.com/pocketbase/pocketbase"
14+
"github.com/pocketbase/pocketbase/core"
15+
)
16+
17+
func main() {
18+
debug := true
19+
if os.Getenv("PROD") == "true" {
20+
debug = false
21+
}
22+
23+
// Create logger
24+
var logger *slog.Logger
25+
26+
if debug {
27+
logger = slog.New(pterm.NewSlogHandler(pterm.DefaultLogger.WithLevel(pterm.LogLevelDebug)))
28+
} else {
29+
logger = slog.New(slog.NewTextHandler(os.Stderr, nil))
30+
}
31+
32+
logger.Debug("debug mode enabled")
33+
34+
logger.Info("starting gttp.dev")
35+
app := pocketbase.New()
36+
37+
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
38+
// Register middlewares
39+
e.Router.Use(middleware.CORS())
40+
e.Router.Use(middleware.Recover())
41+
e.Router.Use(apis.ActivityLogger(app))
42+
43+
if !debug {
44+
e.Router.Use(slogecho.NewWithConfig(logger, slogecho.Config{
45+
WithRequestHeader: true,
46+
WithRequestBody: true,
47+
}))
48+
}
49+
50+
return nil
51+
})
52+
53+
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
54+
Automigrate: true,
55+
})
56+
57+
if err := app.Start(); err != nil {
58+
logger.Error(err.Error())
59+
}
60+
}

compose.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3"
2+
3+
services:
4+
gttp-backend:
5+
image: ghcr.io/gttp-cli/website:backend
6+
build: .
7+
volumes:
8+
- ./pb_data:/app/pb_data
9+
- ./migrations:/app/migrations
10+
ports:
11+
- "8080:80"
12+
gttp-frontend:
13+
image: ghcr.io/gttp-cli/website:frontend
14+
build: ./web
15+
ports:
16+
- "4175:80"

go.mod

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
module github.com/gttp-cli/website
2+
3+
go 1.21.3
4+
5+
require (
6+
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61
7+
github.com/pocketbase/pocketbase v0.21.1
8+
github.com/pterm/pterm v0.12.78
9+
github.com/samber/slog-echo v0.0.0-20231023153015-0592b2c624c8
10+
)
11+
12+
require (
13+
atomicgo.dev/cursor v0.2.0 // indirect
14+
atomicgo.dev/keyboard v0.2.9 // indirect
15+
atomicgo.dev/schedule v0.1.0 // indirect
16+
github.com/AlecAivazis/survey/v2 v2.3.7 // indirect
17+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
18+
github.com/aws/aws-sdk-go v1.50.2 // indirect
19+
github.com/aws/aws-sdk-go-v2 v1.24.1 // indirect
20+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect
21+
github.com/aws/aws-sdk-go-v2/config v1.26.6 // indirect
22+
github.com/aws/aws-sdk-go-v2/credentials v1.16.16 // indirect
23+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 // indirect
24+
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.15.14 // indirect
25+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect
26+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect
27+
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.3 // indirect
28+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.10 // indirect
29+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
30+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.10 // indirect
31+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.10 // indirect
32+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.10 // indirect
33+
github.com/aws/aws-sdk-go-v2/service/s3 v1.48.0 // indirect
34+
github.com/aws/aws-sdk-go-v2/service/sso v1.18.7 // indirect
35+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7 // indirect
36+
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 // indirect
37+
github.com/aws/smithy-go v1.19.0 // indirect
38+
github.com/containerd/console v1.0.3 // indirect
39+
github.com/disintegration/imaging v1.6.2 // indirect
40+
github.com/domodwyer/mailyak/v3 v3.6.2 // indirect
41+
github.com/dustin/go-humanize v1.0.1 // indirect
42+
github.com/fatih/color v1.16.0 // indirect
43+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
44+
github.com/ganigeorgiev/fexpr v0.4.0 // indirect
45+
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
46+
github.com/goccy/go-json v0.10.2 // indirect
47+
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
48+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
49+
github.com/golang/protobuf v1.5.3 // indirect
50+
github.com/google/uuid v1.6.0 // indirect
51+
github.com/google/wire v0.5.0 // indirect
52+
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
53+
github.com/gookit/color v1.5.4 // indirect
54+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
55+
github.com/jmespath/go-jmespath v0.4.0 // indirect
56+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
57+
github.com/labstack/echo/v4 v4.10.0 // indirect
58+
github.com/labstack/gommon v0.4.0 // indirect
59+
github.com/lithammer/fuzzysearch v1.1.8 // indirect
60+
github.com/mattn/go-colorable v0.1.13 // indirect
61+
github.com/mattn/go-isatty v0.0.20 // indirect
62+
github.com/mattn/go-runewidth v0.0.15 // indirect
63+
github.com/mattn/go-sqlite3 v1.14.19 // indirect
64+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
65+
github.com/pocketbase/dbx v1.10.1 // indirect
66+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
67+
github.com/rivo/uniseg v0.4.4 // indirect
68+
github.com/samber/lo v1.38.1 // indirect
69+
github.com/spf13/cast v1.6.0 // indirect
70+
github.com/spf13/cobra v1.8.0 // indirect
71+
github.com/spf13/pflag v1.0.5 // indirect
72+
github.com/valyala/bytebufferpool v1.0.0 // indirect
73+
github.com/valyala/fasttemplate v1.2.2 // indirect
74+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
75+
go.opencensus.io v0.24.0 // indirect
76+
go.opentelemetry.io/otel v1.21.0 // indirect
77+
go.opentelemetry.io/otel/trace v1.21.0 // indirect
78+
gocloud.dev v0.36.0 // indirect
79+
golang.org/x/crypto v0.18.0 // indirect
80+
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
81+
golang.org/x/image v0.15.0 // indirect
82+
golang.org/x/mod v0.14.0 // indirect
83+
golang.org/x/net v0.20.0 // indirect
84+
golang.org/x/oauth2 v0.16.0 // indirect
85+
golang.org/x/sync v0.6.0 // indirect
86+
golang.org/x/sys v0.16.0 // indirect
87+
golang.org/x/term v0.16.0 // indirect
88+
golang.org/x/text v0.14.0 // indirect
89+
golang.org/x/time v0.5.0 // indirect
90+
golang.org/x/tools v0.17.0 // indirect
91+
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
92+
google.golang.org/api v0.157.0 // indirect
93+
google.golang.org/appengine v1.6.8 // indirect
94+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
95+
google.golang.org/grpc v1.61.0 // indirect
96+
google.golang.org/protobuf v1.32.0 // indirect
97+
lukechampine.com/uint128 v1.3.0 // indirect
98+
modernc.org/cc/v3 v3.41.0 // indirect
99+
modernc.org/ccgo/v3 v3.16.15 // indirect
100+
modernc.org/libc v1.40.7 // indirect
101+
modernc.org/mathutil v1.6.0 // indirect
102+
modernc.org/memory v1.7.2 // indirect
103+
modernc.org/opt v0.1.3 // indirect
104+
modernc.org/sqlite v1.28.0 // indirect
105+
modernc.org/strutil v1.2.0 // indirect
106+
modernc.org/token v1.1.0 // indirect
107+
)

0 commit comments

Comments
 (0)