Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN go build -o /app/app main.go
# Runtime
FROM alpine:3.19
WORKDIR /app
RUN apk add --no-cache sqlite-libs ca-certificates && \
RUN apk add --no-cache sqlite-libs ca-certificates tzdata && \
mkdir -p /data

COPY --from=builder /app/app /app/app
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ BackApp supports the following command-line flags:
- `-port` - Port to run the server on (default: `8080`)
- `-db` - SQLite database path (default: `/data/app.db`)

### Environment Variables

- `TZ` - Set the timezone for the application (e.g., `Asia/Bangkok`, `America/New_York`, `Europe/London`). This affects all timestamps in logs, backup runs, and naming rules. If not set, the system default timezone (typically UTC in Docker) is used.

Examples:
```bash
# Run on a different port
Expand All @@ -41,6 +45,9 @@ Examples:

# Combine multiple flags
./backapp -port=9090 -db=/custom/path/app.db

# Set timezone using environment variable
TZ=Asia/Bangkok ./backapp
```

## Quick start
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ services:
- "8080:8080"
command: [ "-port=8080" ]
restart: unless-stopped
# Optionally set timezone using TZ environment variable
# environment:
# - TZ=Asia/Bangkok
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:8080/health || exit 1"]
interval: 30s
Expand Down
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module backapp-server
go 1.24.0

require (
github.com/SherClockHolmes/webpush-go v1.4.0
github.com/gin-gonic/gin v1.10.0
github.com/robfig/cron/v3 v3.0.1
golang.org/x/crypto v0.46.0
Expand All @@ -11,7 +12,6 @@ require (
)

require (
github.com/SherClockHolmes/webpush-go v1.4.0 // indirect
github.com/bytedance/sonic v1.12.3 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
Expand Down
4 changes: 0 additions & 4 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -152,8 +150,6 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
13 changes: 13 additions & 0 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io/fs"
"log"
"net/http"
"os"
"time"

"backapp-server/config"
"backapp-server/controller"
Expand Down Expand Up @@ -36,6 +38,17 @@ func CORSMiddleware() gin.HandlerFunc {
var embeddedStaticFiles embed.FS

func main() {
// Load timezone from TZ environment variable
if tzEnv := os.Getenv("TZ"); tzEnv != "" {
loc, err := time.LoadLocation(tzEnv)
if err != nil {
log.Printf("Warning: Failed to load timezone '%s': %v. Using system default.", tzEnv, err)
} else {
time.Local = loc
log.Printf("Timezone set to: %s", tzEnv)
}
}

// Parse command line flags
port := flag.Int("port", 8080, "Port to run the server on")
dbPath := flag.String("db", "./app.db", "SQLite database path")
Expand Down