Skip to content

Commit 6f29d9c

Browse files
committed
Merge pull request #5 from axzilla/setup-auth
feat(auth): add basic auth system
2 parents 7474426 + a5dbc95 commit 6f29d9c

File tree

43 files changed

+1192
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1192
-77
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GO_ENV=dev
2+
JWT_SECRET=secret

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*_templ.go
22
*_templ.txt
3+
/data
34
.DS_Store
45
bin
56
node_modules

Dockerfile.app

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ RUN apk add --no-cache gcc musl-dev
1616

1717
# Build the application
1818
RUN CGO_ENABLED=1 GOOS=linux go build -o main ./cmd/app/main.go
19+
RUN CGO_ENABLED=1 GOOS=linux go build -o cli ./cmd/cli/main.go
1920

2021
# Deploy-Stage
2122
FROM alpine:3.20.2
@@ -25,10 +26,11 @@ WORKDIR /app
2526
RUN apk add --no-cache ca-certificates
2627

2728
# Set environment variable for runtime
28-
ENV GO_ENV=production
29+
ENV GO_ENV=prod
2930

3031
# Copy the binary from the build stage
3132
COPY --from=build /app/main .
33+
COPY --from=build /app/cli .
3234

3335
# Expose the port your application runs on
3436
EXPOSE 8090

Dockerfile.web

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ WORKDIR /app
2525
RUN apk add --no-cache ca-certificates
2626

2727
# Set environment variable for runtime
28-
ENV GO_ENV=production
28+
ENV GO_ENV=prod
2929

3030
# Copy the binary from the build stage
3131
COPY --from=build /app/main .

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ This is a pre-alpha release focused on core installation functionality. The plat
2121

2222
- Linux server (tested on Ubuntu 24.04)
2323
- Docker
24+
25+
## Reset Password
26+
27+
1. Login into your VPS
28+
2. `docker exec -it deeploy sh`
29+
3. `./cli reset-password -email=user@example.com -password=newpassword`

cmd/app/main.go

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,28 @@ package main
33
import (
44
"fmt"
55
"net/http"
6-
"os"
76

8-
"github.com/a-h/templ"
9-
"github.com/axzilla/deeploy/internal/app/ui/pages"
10-
"github.com/axzilla/deeploy/internal/web/assets"
7+
"github.com/axzilla/deeploy/internal/app/db"
8+
"github.com/axzilla/deeploy/internal/app/deeploy"
9+
"github.com/axzilla/deeploy/internal/app/routes"
1110
"github.com/axzilla/deeploy/internal/web/config"
1211
)
1312

1413
func main() {
1514
config.LoadConfig()
16-
mux := http.NewServeMux()
17-
SetupAssetsRoutes(mux)
18-
mux.Handle("GET /", templ.Handler(pages.Dashboard()))
19-
fmt.Println("Server is running on http://localhost:8090")
20-
http.ListenAndServe(":8090", mux)
21-
}
2215

23-
func SetupAssetsRoutes(mux *http.ServeMux) {
24-
var isDevelopment = os.Getenv("GO_ENV") != "production"
16+
db, err := db.Init()
17+
if err != nil {
18+
fmt.Printf("DB Error: %s", err)
19+
}
2520

26-
assetHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
27-
if isDevelopment {
28-
w.Header().Set("Cache-Control", "no-store")
29-
}
30-
31-
var fs http.Handler
32-
if isDevelopment {
33-
fs = http.FileServer(http.Dir("./internal/app/assets"))
34-
} else {
35-
fs = http.FileServer(http.FS(assets.Assets))
36-
}
21+
mux := http.NewServeMux()
22+
app := deeploy.New(mux, db)
3723

38-
fs.ServeHTTP(w, r)
39-
})
24+
routes.Base(app)
25+
routes.Assets(app)
26+
routes.User(app)
4027

41-
mux.Handle("GET /assets/", http.StripPrefix("/assets/", assetHandler))
28+
fmt.Println("Server is running on http://localhost:8090")
29+
http.ListenAndServe(":8090", mux)
4230
}

cmd/cli/main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/axzilla/deeploy/internal/cli"
8+
)
9+
10+
func main() {
11+
if len(os.Args) < 2 {
12+
fmt.Println("Usage: cli <command> [flags]")
13+
os.Exit(1)
14+
}
15+
16+
// Use first arg as command
17+
command := os.Args[1]
18+
19+
// Shift args for 1 to make flag.Parse() execute correct
20+
os.Args = os.Args[1:]
21+
22+
switch command {
23+
case "reset-password":
24+
cli.ResetPassword()
25+
default:
26+
fmt.Printf("Unknown command: %s\n", command)
27+
os.Exit(1)
28+
}
29+
}

cmd/web/main.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,16 @@ func main() {
3131
}
3232

3333
func SetupAssetsRoutes(mux *http.ServeMux) {
34-
var isDevelopment = os.Getenv("GO_ENV") != "production"
35-
34+
var isDev = os.Getenv("GO_ENV") != "prod"
3635
assetHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
37-
if isDevelopment {
38-
w.Header().Set("Cache-Control", "no-store")
39-
}
40-
4136
var fs http.Handler
42-
if isDevelopment {
43-
fs = http.FileServer(http.Dir("./internal/web/assets"))
37+
if isDev {
38+
w.Header().Set("Cache-Control", "no-store")
39+
fs = http.FileServer(http.Dir("./internal/app/assets"))
4440
} else {
4541
fs = http.FileServer(http.FS(assets.Assets))
4642
}
47-
4843
fs.ServeHTTP(w, r)
4944
})
50-
5145
mux.Handle("GET /assets/", http.StripPrefix("/assets/", assetHandler))
5246
}

go.mod

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,31 @@ module github.com/axzilla/deeploy
33
go 1.23.3
44

55
require (
6-
github.com/a-h/templ v0.2.793
7-
github.com/axzilla/templui v0.28.0
6+
github.com/a-h/templ v0.3.819
7+
github.com/axzilla/templui v0.28.2-0.20250103002306-d95bdc6ff601
8+
github.com/golang-jwt/jwt/v4 v4.4.2
9+
github.com/golang-migrate/migrate/v4 v4.18.1
10+
github.com/google/uuid v1.6.0
811
github.com/joho/godotenv v1.5.1
12+
golang.org/x/crypto v0.27.0
13+
modernc.org/sqlite v1.34.4
914
)
1015

11-
require github.com/Oudwins/tailwind-merge-go v0.2.0 // indirect
16+
require (
17+
github.com/Oudwins/tailwind-merge-go v0.2.0 // indirect
18+
github.com/dustin/go-humanize v1.0.1 // indirect
19+
github.com/hashicorp/errwrap v1.1.0 // indirect
20+
github.com/hashicorp/go-multierror v1.1.1 // indirect
21+
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
22+
github.com/mattn/go-isatty v0.0.20 // indirect
23+
github.com/ncruces/go-strftime v0.1.9 // indirect
24+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
25+
go.uber.org/atomic v1.7.0 // indirect
26+
golang.org/x/sys v0.28.0 // indirect
27+
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
28+
modernc.org/libc v1.55.3 // indirect
29+
modernc.org/mathutil v1.6.0 // indirect
30+
modernc.org/memory v1.8.0 // indirect
31+
modernc.org/strutil v1.2.0 // indirect
32+
modernc.org/token v1.1.0 // indirect
33+
)

go.sum

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,85 @@
11
github.com/Oudwins/tailwind-merge-go v0.2.0 h1:rtVHgYmLwwae4P+K6//ceRuUdyz3Bny6fo4664fOEmo=
22
github.com/Oudwins/tailwind-merge-go v0.2.0/go.mod h1:kkZodgOPvZQ8f7SIrlWkG/w1g9JTbtnptnePIh3V72U=
3-
github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY=
4-
github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
5-
github.com/axzilla/templui v0.28.0 h1:SMcwmLvXEkfa0+NNMdJlzwyEuhonzNDqPubaO9TcG18=
6-
github.com/axzilla/templui v0.28.0/go.mod h1:PcNr8hOXnpVGdGsSPpXbkbtrLUlx5/Ok8Jv4TGKhN9A=
3+
github.com/a-h/templ v0.3.819 h1:KDJ5jTFN15FyJnmSmo2gNirIqt7hfvBD2VXVDTySckM=
4+
github.com/a-h/templ v0.3.819/go.mod h1:iDJKJktpttVKdWoTkRNNLcllRI+BlpopJc+8au3gOUo=
5+
github.com/axzilla/templui v0.28.2-0.20250103002306-d95bdc6ff601 h1:MY6TdlIceYssCQc+ZgxrI/3scCIsbtcBZIT/YYbP59g=
6+
github.com/axzilla/templui v0.28.2-0.20250103002306-d95bdc6ff601/go.mod h1:+SHKXqJhxnlyTnaer2BppwdNPZB9GLVYTD+ifZaqrIY=
7+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
78
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
89
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10+
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
11+
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
12+
github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs=
13+
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
14+
github.com/golang-migrate/migrate/v4 v4.18.1 h1:JML/k+t4tpHCpQTCAD62Nu43NUFzHY4CV3uAuvHGC+Y=
15+
github.com/golang-migrate/migrate/v4 v4.18.1/go.mod h1:HAX6m3sQgcdO81tdjn5exv20+3Kb13cmGli1hrD6hks=
916
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1017
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
18+
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo=
19+
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
20+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
21+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
22+
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
23+
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
24+
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
25+
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
26+
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
27+
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
28+
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
1129
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
1230
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
31+
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
32+
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
33+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
34+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
35+
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
36+
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
1337
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1438
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
39+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
40+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
41+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
42+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
1543
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
1644
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
45+
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
46+
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
47+
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
48+
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
49+
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
50+
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
51+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
52+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
53+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
54+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
55+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
56+
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
57+
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
1758
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
1859
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
60+
modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ=
61+
modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ=
62+
modernc.org/ccgo/v4 v4.19.2 h1:lwQZgvboKD0jBwdaeVCTouxhxAyN6iawF3STraAal8Y=
63+
modernc.org/ccgo/v4 v4.19.2/go.mod h1:ysS3mxiMV38XGRTTcgo0DQTeTmAO4oCmJl1nX9VFI3s=
64+
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
65+
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
66+
modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw=
67+
modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU=
68+
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
69+
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
70+
modernc.org/libc v1.55.3 h1:AzcW1mhlPNrRtjS5sS+eW2ISCgSOLLNyFzRh/V3Qj/U=
71+
modernc.org/libc v1.55.3/go.mod h1:qFXepLhz+JjFThQ4kzwzOjA/y/artDeg+pcYnY+Q83w=
72+
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
73+
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
74+
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
75+
modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU=
76+
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
77+
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
78+
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
79+
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
80+
modernc.org/sqlite v1.34.4 h1:sjdARozcL5KJBvYQvLlZEmctRgW9xqIZc2ncN7PU0P8=
81+
modernc.org/sqlite v1.34.4/go.mod h1:3QQFCG2SEMtc2nv+Wq4cQCH7Hjcg+p/RMlS1XK+zwbk=
82+
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
83+
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
84+
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
85+
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=

0 commit comments

Comments
 (0)