Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blueprint_ui_new #377

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Please include a description of the problem or feature this PR is addressing.

- [ ] I have self-reviewed the changes being requested
- [ ] I have updated the documentation (check issue ticket #218)
- [ ] I have updated the blueprint-ui when directory or file layout was changed
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
go-blueprint
main

site

*templ.go
output.css
tailwindcss
tmp/
46 changes: 46 additions & 0 deletions blueprint-ui/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./main"
cmd = "make build"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata", "node_modules"]
exclude_file = []
exclude_regex = ["_test.go", ".*_templ.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html", "templ"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
2 changes: 2 additions & 0 deletions blueprint-ui/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=8080
APP_ENV=local
23 changes: 23 additions & 0 deletions blueprint-ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.23-alpine AS build

RUN apk add --no-cache curl

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN go install github.com/a-h/templ/cmd/templ@latest && \
templ generate && \
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-linux-x64 -o tailwindcss && \
chmod +x tailwindcss && \
./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css

RUN go build -o main cmd/api/main.go

FROM alpine:3.20.1 AS prod
WORKDIR /app
COPY --from=build /app/main /app/main
EXPOSE ${PORT}
CMD ["./main"]
75 changes: 75 additions & 0 deletions blueprint-ui/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Simple Makefile for a Go project

# Build the application
all: run
templ-install:
@if ! command -v templ > /dev/null; then \
read -p "Go's 'templ' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/a-h/templ/cmd/templ@latest; \
if [ ! -x "$$(command -v templ)" ]; then \
echo "templ installation failed. Exiting..."; \
exit 1; \
fi; \
else \
echo "You chose not to install templ. Exiting..."; \
exit 1; \
fi; \
fi
tailwind-install:
@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-linux-x64 -o tailwindcss; fi

@chmod +x tailwindcss

build: tailwind-install templ-install
@echo "Building..."
@templ generate
@./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css
@go build -o main cmd/api/main.go

# Run the application
run: build
@echo "Starting server..."
@./main
# Create DB container
docker-run:
@if docker compose up --build 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
docker-compose up --build; \
fi

# Shutdown DB container
docker-down:
@if docker compose down 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
docker-compose down; \
fi

# Clean the binary
clean:
@echo "Cleaning..."
@pkill main || true
@rm -f main

# Live Reload
watch:
@if command -v air > /dev/null; then \
air; \
echo "Watching...";\
else \
read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/air-verse/air@latest; \
air; \
echo "Watching...";\
else \
echo "You chose not to install air. Exiting..."; \
exit 1; \
fi; \
fi

.PHONY: all build run clean watch tailwind-install templ-install
57 changes: 57 additions & 0 deletions blueprint-ui/cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"context"
"fmt"
"log"
"net/http"
"os/signal"
"syscall"
"time"

"blueprint-ui/internal/server"
)

func gracefulShutdown(apiServer *http.Server, done chan bool) {
// Create context that listens for the interrupt signal from the OS.
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

// Listen for the interrupt signal.
<-ctx.Done()

log.Println("shutting down gracefully, press Ctrl+C again to force")

// The context is used to inform the server it has 5 seconds to finish
// the request it is currently handling
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := apiServer.Shutdown(ctx); err != nil {
log.Printf("Server forced to shutdown with error: %v", err)
}

log.Println("Server exiting")

// Notify the main goroutine that the shutdown is complete
done <- true
}

func main() {

server := server.NewServer()

// Create a done channel to signal when the shutdown is complete
done := make(chan bool, 1)

// Run graceful shutdown in a separate goroutine
go gracefulShutdown(server, done)

err := server.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
panic(fmt.Sprintf("http server error: %s", err))
}

// Wait for the graceful shutdown to complete
<-done
log.Println("Graceful shutdown complete.")
}
Loading