diff --git a/Dockerfile b/Dockerfile index e69de29..acf5b24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.24-alpine AS builder +RUN apk update && apk add --no-cache git && apk add -U --no-cache ca-certificates +WORKDIR /app/ +ADD go.mod go.sum ./ +RUN go mod download +ADD . . +RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o next-book . + +FROM scratch +WORKDIR /app/ +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /app/next-book /app/next-book +ENTRYPOINT ["/app/next-book"] diff --git a/Makefile b/Makefile index 503e0c9..eae0fa4 100644 --- a/Makefile +++ b/Makefile @@ -7,43 +7,27 @@ test: lint check-format run-tests .PHONY: lint # Perform lint checks against code lint: - @echo "⚠️ 'lint' unimplemented" - # GO Projects - # @go vet && golint -set_exit_status ./... + @go vet && golint -set_exit_status ./... .PHONY: check-format # Checks code formatting and returns a non-zero exit code if formatting errors found check-format: - @echo "⚠️ 'check-format' unimplemented" - # GO Projects - # @gofmt -e -l . + @gofmt -e -l . .PHONY: format # Performs automatic format fixes on all code format: - @echo "⚠️ 'format' unimplemented" - # GO Projects - # @gofmt -s -w . + @gofmt -s -w . .PHONY: run-tests # Runs all tests run-tests: - @echo "⚠️ 'run-tests' unimplemented" - # GO Projects - # @go test - # Node Projects - # @npm test + @go test .PHONY: fetch-deps # Fetch all project dependencies fetch-deps: - @echo "⚠️ 'fetch-deps' unimplemented" - # GO Projects - # @go mod tidy - # Node Projects - # @npm install + @go mod tidy .PHONY: build # Build the project build: lint check-format fetch-deps - @echo "⚠️ 'build' unimplemented" - # GO Projects - # @go build -o PROJECT_NAME main.go + @go build -o PROJECT_NAME main.go .PHONY: docker-build # Build the docker image docker-build: @@ -55,11 +39,7 @@ docker-publish: .PHONY: run # Run the application run: - @echo "⚠️ 'run' unimplemented" - # GO Projects - # @go run main.go - # Node Projects - # @npm start + @go run main.go .PHONY: ci # Perform CI specific tasks to perform on a pull request ci: diff --git a/README.md b/README.md index 293afec..e1d70e4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # next-book - +Checks the users Storygraph "to read" list and shows the highest rated in various catergories. ## Features diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f3c9cff --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module nextbook + +go 1.24.0 + +require github.com/joho/godotenv v1.5.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d61b19e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= diff --git a/main.go b/main.go new file mode 100644 index 0000000..22ef23e --- /dev/null +++ b/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "net/http" + "os" + + "github.com/joho/godotenv" +) + +var ( + port string +) + +func init() { + godotenv.Load(os.Getenv("DOTENV_DIR") + ".env") + + var ok bool + port, ok = os.LookupEnv("PORT") + if !ok { + port = "8000" + } +} + +func main() { + go updateWorker() + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + + w.WriteHeader(http.StatusBadRequest) + }) + + http.ListenAndServe(fmt.Sprintf(":%s", port), nil) +} + +func updateWorker() { + // TODO: Update worker +}