Skip to content

Commit 167cb71

Browse files
Automated commit by Forgejo CI/CD [v1.5.0] - Personal CI/CD Bot
1 parent a105a2e commit 167cb71

16 files changed

+665
-108
lines changed

.env

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
# This is an example and should be edited first
2-
BACKEND=http://YourBackend.example.com:8080 # note: add port and http:// here as well
3-
HOSTNAME="ZEHD" # leave blank to get the actual hostname of the server/container
4-
TEMPLATEDIRECTORY="/var/zehd/templates" # change this, if there a specific dir inside the container it should be (attached NFS/ISCSI/SMB share)
5-
TEMPLATETYPE="gohtml" # change this, to the type of template you would normally use (html/org/md)
6-
REFRESHCACHE="60" # change this, if you need it to refresh faster
7-
PROFILER=false # change this, if you would like to log performance of functions (DEV purposes)
1+
# This is an example and should be edited first, the values here are default values
2+
BACKEND="http://YourBackend.example.com:8080" # note: add port and http:// here as well
3+
HOSTNAME="ZEHD" # leave blank to get the actual hostname of the server/container
4+
TEMPLATEDIRECTORY="/var/zehd/templates" # if there a specific dir inside the container it should be (attached NFS/ISCSI/SMB share)
5+
TEMPLATETYPE="gohtml" # change this, to the type of template you would normally use (html/org/md)
6+
REFRESHCACHE="60" # if you need it to refresh faster
7+
PROFILER=false # if you would like to log performance of functions (DEV purposes)
8+
GITLINK="" # if you would like to use a git repo, containing files to your website
9+
GITUSERNAME="" # you will require a username for the repo as well
10+
GITTOKEN="" # if your repo is made private, you will require a token
11+
JSPATH="" # if you would like to specify a different js path (default: "js")
12+
CSSPATH="" # if you would like to specify a different css path (default: "css")
13+
IMAGESPATH="" # if you would like to specify a different images path (default: "images")
14+
DOWNLOADSPATH="" # if you would like to specify a different downloads path (default: "downloads")

CHANGELOG

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## [1.2.0] - 13-11-2023
1+
## [1.5.0] - 13-11-2024
22
### Added
3-
- I shelved the replicator for now, and decided to implement functions to template building, aptly named: func my template
4-
- for now its an empty funcmap, until I have a test function in my other repo, which will be open to additions
3+
- Added git functionality, so that one does not have to upload, or automate updates to you website
4+
- It can either use a password or token (with the correct permissions, it is up to the user how open they want their token to be if it gets leaked)
5+
- Changed to scratch image for docker, it managed to reduce the size by another couple of MB
6+
- bumped the go version in the go.mod file
7+
- made the http handler use a switch for GET and POST, where I have an idea with POST
8+
- reworked how the env vars initialize and how it should visually display how much is configured to the user
9+
- added ability to disable static paths individually, as well as change them to custom paths (css, js, images and downloads)

Dockerfile

+31-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
1-
#build stage
2-
FROM golang:latest AS builder
1+
# build stage
2+
FROM golang:alpine AS builder
33
ARG VERSION
4-
RUN apk add --no-cache git
54
WORKDIR /go/src/app
65
COPY . .
7-
RUN mkdir -p /go/bin/
8-
RUN go mod tidy
9-
RUN go get -d -v ./...
10-
RUN go build -o /go/bin/app -v ./cmd/zehd/main.go
6+
RUN mkdir -p /go/bin/ && \
7+
go mod tidy && \
8+
go get -d -v ./... && \
9+
go build -o /go/bin/app -v ./cmd/zehd/main.go
1110

12-
#final stage
13-
FROM alpine:latest
14-
RUN apk --no-cache add ca-certificates
11+
# final stage
12+
FROM scratch
1513
COPY --from=builder /go/bin/app /app
1614
COPY --from=builder /go/src/app/VERSION /VERSION
17-
ENV BACKEND=$BACKEND
18-
ENV HOSTNAME=$HOSTNAME
19-
ENV TEMPLATEDIRECTORY=$TEMPLATEDIRECTORY
20-
ENV TEMPLATETYPE=$TEMPLATETYPE
21-
ENV REFRESHCACHE=$REFRESHCACHE
22-
ENV PROFILER=$PROFILER
15+
16+
# Container config
17+
ENV BACKEND=${BACKEND} \
18+
HOSTNAME=${HOSTNAME} \
19+
# Templating config
20+
TEMPLATEDIRECTORY=${TEMPLATEDIRECTORY} \
21+
TEMPLATETYPE=${TEMPLATETYPE} \
22+
REFRESHCACHE=${REFRESHCACHE} \
23+
# Git config
24+
GITLINK=${GITLINK} \
25+
GITTOKEN=${GITTOKEN} \
26+
GITUSERNAME=${GITUSERNAME} \
27+
# Paths config
28+
JSPATH=${JSPATH} \
29+
CSSPATH=${CSSPATH} \
30+
DOWNLOADSPATH=${DOWNLOADSPATH} \
31+
IMAGESPATH=${IMAGESPATH} \
32+
PROFILER=${PROFILER}
33+
2334
ARG VERSION
24-
ENTRYPOINT ["/app"]
25-
LABEL Name=zehd Version=VERSION
35+
LABEL org.opencontainers.image.name="zehd" \
36+
org.opencontainers.image.version="${VERSION}"
37+
2638
EXPOSE 80
2739

40+
ENTRYPOINT ["/app"]

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.1
1+
1.5.0

cmd/zehd/main.go

+49-11
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import (
55
"html/template"
66
"log"
77
"net/http"
8-
"zehd-frontend/pkg"
9-
"zehd-frontend/pkg/backendconnector"
10-
"zehd-frontend/pkg/caching"
11-
"zehd-frontend/pkg/env"
12-
"zehd-frontend/pkg/kubernetes"
138
"strconv"
149
"strings"
1510
"sync/atomic"
1611
"time"
12+
"zehd/pkg"
13+
"zehd/pkg/backendconnector"
14+
"zehd/pkg/caching"
15+
"zehd/pkg/env"
16+
"zehd/pkg/kubernetes"
1717

1818
"github.com/APoniatowski/boillog"
1919

@@ -27,6 +27,20 @@ func main() {
2727
fmt.Printf(" Starting liveness probe...")
2828
http.HandleFunc("/k8s/api/health", kubernetes.Healthz)
2929
fmt.Println(" Done.")
30+
// cloning repo from git source, if specified.
31+
fmt.Println(" Checking git repo:")
32+
fmt.Printf(" Cloning")
33+
if len(pkg.GitLink) == 0 {
34+
fmt.Printf("... Skipped.\n")
35+
} else {
36+
err := caching.Git("startup")
37+
if err != nil {
38+
fmt.Printf("\n")
39+
log.Println(err.Error())
40+
} else {
41+
fmt.Println(" Done.")
42+
}
43+
}
3044
// init caching via go func(){check files for changes and figure out a way to pass them to handler}
3145
fmt.Printf(" Building and Caching templates...")
3246
cache := &caching.Pages{}
@@ -37,7 +51,7 @@ func main() {
3751
if err != nil {
3852
log.Println(err.Error())
3953
}
40-
timer, err := strconv.Atoi(env.EnvCacheRefresh())
54+
timer, err := strconv.Atoi(pkg.RefreshCache)
4155
if err != nil {
4256
boillog.LogIt("EnvCacheRefresh", "ERROR", "error loading environment variables")
4357
}
@@ -46,11 +60,35 @@ func main() {
4660
}()
4761
fmt.Println(" Done.")
4862
// JS and CSS handling/serving
49-
fmt.Printf(" Serving Static CSS/JS...")
50-
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir(pkg.TemplatesDir+"css"))))
51-
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir(pkg.TemplatesDir+"js"))))
52-
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(pkg.TemplatesDir+"images"))))
53-
fmt.Println(" Done.")
63+
fmt.Printf(" Serving Static paths:\n")
64+
fmt.Printf(" CSS...")
65+
if pkg.CSS != pkg.Disable {
66+
http.Handle("/"+pkg.CSS+"/", http.StripPrefix("/"+pkg.CSS+"/", http.FileServer(http.Dir(pkg.TemplatesDir+pkg.CSS))))
67+
fmt.Println(" Done.")
68+
} else {
69+
fmt.Println(" Disabled.")
70+
}
71+
fmt.Printf(" JS... ")
72+
if pkg.Javascript != pkg.Disable {
73+
http.Handle("/"+pkg.Javascript+"/", http.StripPrefix("/"+pkg.Javascript+"/", http.FileServer(http.Dir(pkg.TemplatesDir+pkg.Javascript))))
74+
fmt.Println(" Done.")
75+
} else {
76+
fmt.Println(" Disabled.")
77+
}
78+
fmt.Printf(" Images... ")
79+
if pkg.Images != pkg.Disable {
80+
http.Handle("/"+pkg.Images+"/", http.StripPrefix("/"+pkg.Images+"/", http.FileServer(http.Dir(pkg.TemplatesDir+pkg.Images))))
81+
fmt.Println(" Done.")
82+
} else {
83+
fmt.Println(" Disabled.")
84+
}
85+
fmt.Printf(" Downloads... ")
86+
if pkg.Downloads != pkg.Disable {
87+
http.Handle("/"+pkg.Downloads+"/", http.StripPrefix("/"+pkg.Downloads+"/", http.FileServer(http.Dir(pkg.TemplatesDir+pkg.Downloads))))
88+
fmt.Println(" Done.")
89+
} else {
90+
fmt.Println(" Disabled.")
91+
}
5492
// Initialize the database and determine if collector should be enabled
5593
fmt.Printf(" Initializing Database...")
5694
errEnv := godotenv.Load("/usr/local/env/.env")

go.mod

+31-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
1-
module zehd-frontend
1+
module zehd
22

3-
go 1.21.5
4-
5-
toolchain go1.21.6
3+
go 1.22.5
64

75
require (
86
github.com/aws/smithy-go v1.12.1
97
github.com/joho/godotenv v1.4.0
108
)
119

1210
require (
13-
github.com/APoniatowski/boillog v1.1.0
11+
github.com/APoniatowski/boillog v1.2.4
1412
github.com/APoniatowski/funcmytemplate v0.0.1
13+
github.com/go-git/go-git v4.7.0+incompatible
14+
github.com/go-git/go-git/v5 v5.12.0
1515
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c
1616
github.com/russross/blackfriday/v2 v2.1.0
17+
golang.org/x/sys v0.18.0
1718
)
1819

19-
require golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 // indirect
20+
require (
21+
dario.cat/mergo v1.0.0 // indirect
22+
github.com/Microsoft/go-winio v0.6.1 // indirect
23+
github.com/ProtonMail/go-crypto v1.0.0 // indirect
24+
github.com/cloudflare/circl v1.3.7 // indirect
25+
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
26+
github.com/emirpasic/gods v1.18.1 // indirect
27+
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
28+
github.com/go-git/go-billy/v5 v5.5.0 // indirect
29+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
30+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
31+
github.com/kevinburke/ssh_config v1.2.0 // indirect
32+
github.com/pjbgf/sha1cd v0.3.0 // indirect
33+
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
34+
github.com/skeema/knownhosts v1.2.2 // indirect
35+
github.com/src-d/gcfg v1.4.0 // indirect
36+
github.com/xanzy/ssh-agent v0.3.3 // indirect
37+
golang.org/x/crypto v0.21.0 // indirect
38+
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 // indirect
39+
golang.org/x/mod v0.14.0 // indirect
40+
golang.org/x/net v0.22.0 // indirect
41+
golang.org/x/tools v0.15.0 // indirect
42+
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
43+
gopkg.in/warnings.v0 v0.1.2 // indirect
44+
)

0 commit comments

Comments
 (0)