Makefile!
Some checks failed
Fly Deploy / Deploy app (push) Failing after 3s
Some checks failed
Fly Deploy / Deploy app (push) Failing after 3s
This commit is contained in:
parent
842711825b
commit
043803e041
5 changed files with 196 additions and 78 deletions
46
.air.toml
46
.air.toml
|
@ -1,46 +0,0 @@
|
||||||
root = "."
|
|
||||||
testdata_dir = "testdata"
|
|
||||||
tmp_dir = "tmp"
|
|
||||||
|
|
||||||
[build]
|
|
||||||
args_bin = ["-ip", "127.0.0.1", "-port", "3000"]
|
|
||||||
bin = "./tmp/main"
|
|
||||||
pre_cmd = []
|
|
||||||
cmd = "cd lib/stylegen && ./gen.sh -e html -d ../../pages/templates -o ../../public/css && cd ../.. && go build -o ./tmp/main ."
|
|
||||||
delay = 1000
|
|
||||||
exclude_dir = ["assets", "tmp", "vendor", "testdata", "lib/stylegen"]
|
|
||||||
exclude_file = []
|
|
||||||
exclude_regex = ["_test.go"]
|
|
||||||
exclude_unchanged = false
|
|
||||||
follow_symlink = false
|
|
||||||
full_bin = ""
|
|
||||||
include_dir = []
|
|
||||||
include_ext = ["go", "tpl", "tmpl", "html"]
|
|
||||||
include_file = []
|
|
||||||
kill_delay = "0s"
|
|
||||||
log = "build-errors.log"
|
|
||||||
poll = false
|
|
||||||
poll_interval = 0
|
|
||||||
post_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
|
|
25
Dockerfile
25
Dockerfile
|
@ -2,18 +2,26 @@ FROM golang:1.23.2-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Download dependencies
|
# Download dependencies and install required tools
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download && \
|
||||||
|
go install github.com/swaggo/swag/cmd/swag@latest
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code and Makefile
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Install UPX
|
# Install required tools and make scripts executable
|
||||||
RUN apk add --no-cache upx
|
RUN apk add --no-cache upx make bash && \
|
||||||
|
chmod +x /app/lib/stylegen/gen.sh && \
|
||||||
|
chmod +x /app/lib/stylegen/tw/*
|
||||||
|
|
||||||
# Build with optimizations
|
# Create necessary directories
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
RUN mkdir -p /app/public/css
|
||||||
|
|
||||||
|
# Generate assets and build with optimizations
|
||||||
|
SHELL ["/bin/bash", "-c"]
|
||||||
|
RUN cd /app && make generate && \
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
||||||
-ldflags='-s -w -extldflags "-static"' \
|
-ldflags='-s -w -extldflags "-static"' \
|
||||||
-tags netgo,osusergo \
|
-tags netgo,osusergo \
|
||||||
-o /go/bin/app
|
-o /go/bin/app
|
||||||
|
@ -21,6 +29,9 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
||||||
# Final stage
|
# Final stage
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
|
# Copy static files and assets
|
||||||
|
COPY --from=builder /app/public/css/styles.css /public/css/styles.css
|
||||||
|
COPY --from=builder /app/docs /docs
|
||||||
COPY --from=builder /go/bin/app /app
|
COPY --from=builder /go/bin/app /app
|
||||||
|
|
||||||
ENTRYPOINT ["/app"]
|
ENTRYPOINT ["/app"]
|
||||||
|
|
142
Makefile
Normal file
142
Makefile
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
# Colors
|
||||||
|
CYAN := \033[36m
|
||||||
|
YELLOW := \033[33m
|
||||||
|
GREEN := \033[32m
|
||||||
|
RED := \033[31m
|
||||||
|
RESET := \033[0m
|
||||||
|
|
||||||
|
# Emoji
|
||||||
|
CHECK := ✅
|
||||||
|
BUILD := 🔨
|
||||||
|
CLEAN := 🧹
|
||||||
|
RUN := 🚀
|
||||||
|
CSS := 🎨
|
||||||
|
TEST := 🧪
|
||||||
|
DOCKER := 🐳
|
||||||
|
WARN := ⚠️
|
||||||
|
DOCS := 📚
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
BINARY_NAME := goth.stack
|
||||||
|
DOCKER_IMAGE := goth-stack
|
||||||
|
GO_FILES := $(wildcard *.go)
|
||||||
|
CSS_INPUT := lib/stylegen/base.css
|
||||||
|
CSS_OUTPUT := public/css/styles.css
|
||||||
|
|
||||||
|
# Docker detection
|
||||||
|
DOCKER_ENV := $(shell if [ -f /.dockerenv ]; then echo true; else echo false; fi)
|
||||||
|
ifeq ($(DOCKER_ENV),true)
|
||||||
|
BASE_PATH := /app
|
||||||
|
else
|
||||||
|
BASE_PATH := $(CURDIR)
|
||||||
|
endif
|
||||||
|
|
||||||
|
.PHONY: all build clean run dev stylegen docker-dev docker-build docker-run test help reset ensure-swag
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo "$(CYAN)Available commands:$(RESET)"
|
||||||
|
@echo "$(YELLOW)make clean$(RESET) - Remove build artifacts"
|
||||||
|
@echo "$(YELLOW)make reset$(RESET) - Clean and reset the project to initial state"
|
||||||
|
@echo "$(YELLOW)make build$(RESET) - Generate CSS, docs, and build Go binary"
|
||||||
|
@echo "$(YELLOW)make run$(RESET) - Build and run the binary"
|
||||||
|
@echo "$(YELLOW)make dev$(RESET) - Run in development mode"
|
||||||
|
@echo "$(YELLOW)make docker-dev$(RESET)- Run development environment in Docker"
|
||||||
|
@echo "$(YELLOW)make docker-run$(RESET)- Run production container"
|
||||||
|
@echo "$(YELLOW)make test$(RESET) - Run tests"
|
||||||
|
@echo "$(YELLOW)make prod$(RESET) - Full production build"
|
||||||
|
|
||||||
|
# Check if swag is installed
|
||||||
|
ensure-swag:
|
||||||
|
@command -v swag >/dev/null 2>&1 || { \
|
||||||
|
echo "$(WARN) $(RED)Swagger CLI (swag) is not installed. Installing...$(RESET)"; \
|
||||||
|
go install github.com/swaggo/swag/cmd/swag@latest; \
|
||||||
|
}
|
||||||
|
|
||||||
|
reset:
|
||||||
|
@echo "$(CLEAN) $(CYAN)Performing complete project reset...$(RESET)"
|
||||||
|
@rm -f $(BINARY_NAME)
|
||||||
|
@rm -f $(CSS_OUTPUT)
|
||||||
|
@rm -rf public/css/*
|
||||||
|
@rm -f tailwind.config.js
|
||||||
|
@rm -rf docs/docs.go docs/swagger.json docs/swagger.yaml
|
||||||
|
@go clean -cache -testcache -modcache
|
||||||
|
@echo "$(CHECK) $(GREEN)Project reset complete$(RESET)"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo "$(CLEAN) $(CYAN)Cleaning build artifacts...$(RESET)"
|
||||||
|
@rm -f $(BINARY_NAME)
|
||||||
|
@rm -f $(CSS_OUTPUT)
|
||||||
|
@echo "$(CHECK) $(GREEN)Cleanup complete$(RESET)"
|
||||||
|
|
||||||
|
stylegen:
|
||||||
|
@echo "$(CSS) $(CYAN)Generating CSS styles...$(RESET)"
|
||||||
|
@echo "Current working directory: $$(pwd)"
|
||||||
|
@echo "Contents of current directory:"
|
||||||
|
@ls -la
|
||||||
|
@echo "\nContents of lib/stylegen:"
|
||||||
|
@ls -la lib/stylegen
|
||||||
|
@echo "\nContents of lib/stylegen/tw:"
|
||||||
|
@ls -la lib/stylegen/tw
|
||||||
|
@chmod +x $(BASE_PATH)/lib/stylegen/gen.sh
|
||||||
|
@chmod +x $(BASE_PATH)/lib/stylegen/tw/*
|
||||||
|
@$(BASE_PATH)/lib/stylegen/gen.sh \
|
||||||
|
-e "html" \
|
||||||
|
-d "$(BASE_PATH)/pages/templates" \
|
||||||
|
-o "$(BASE_PATH)/public/css"
|
||||||
|
@echo "$(CHECK) $(GREEN)CSS generation complete$(RESET)"
|
||||||
|
|
||||||
|
swaggergen: ensure-swag
|
||||||
|
@echo "$(DOCS) $(CYAN)Generating Swagger documentation...$(RESET)"
|
||||||
|
@swag init
|
||||||
|
@echo "$(CHECK) $(GREEN)Swagger docs generated$(RESET)"
|
||||||
|
|
||||||
|
# Combined generation target
|
||||||
|
generate: stylegen swaggergen
|
||||||
|
|
||||||
|
build: generate
|
||||||
|
@echo "$(BUILD) $(CYAN)Building binary...$(RESET)"
|
||||||
|
@go build -o $(BINARY_NAME)
|
||||||
|
@echo "$(CHECK) $(GREEN)Build complete: $(BINARY_NAME)$(RESET)"
|
||||||
|
|
||||||
|
test:
|
||||||
|
@echo "$(TEST) $(CYAN)Running tests...$(RESET)"
|
||||||
|
@go test ./...
|
||||||
|
@echo "$(CHECK) $(GREEN)Tests complete$(RESET)"
|
||||||
|
|
||||||
|
dev: generate
|
||||||
|
@echo "$(RUN) $(CYAN)Starting development server...$(RESET)"
|
||||||
|
@go run main.go
|
||||||
|
|
||||||
|
run: build
|
||||||
|
@echo "$(RUN) $(CYAN)Running server...$(RESET)"
|
||||||
|
@./$(BINARY_NAME)
|
||||||
|
|
||||||
|
docker-dev:
|
||||||
|
@echo "$(DOCKER) $(CYAN)Starting development container...$(RESET)"
|
||||||
|
@docker-compose -f docker-compose.dev.yml up --build
|
||||||
|
|
||||||
|
docker-build: generate
|
||||||
|
@echo "$(DOCKER) $(CYAN)Building production Docker image...$(RESET)"
|
||||||
|
@docker build -t $(DOCKER_IMAGE) .
|
||||||
|
@echo "$(CHECK) $(GREEN)Docker image build complete$(RESET)"
|
||||||
|
|
||||||
|
docker-run: docker-build
|
||||||
|
@echo "$(DOCKER) $(CYAN)Running production container...$(RESET)"
|
||||||
|
@docker-compose up
|
||||||
|
|
||||||
|
deps:
|
||||||
|
@echo "$(BUILD) $(CYAN)Installing dependencies...$(RESET)"
|
||||||
|
@go mod download
|
||||||
|
@go install github.com/swaggo/swag/cmd/swag@latest
|
||||||
|
@echo "$(CHECK) $(GREEN)Dependencies installed$(RESET)"
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
@echo "$(BUILD) $(CYAN)Formatting code...$(RESET)"
|
||||||
|
@go fmt ./...
|
||||||
|
@echo "$(CHECK) $(GREEN)Code formatting complete$(RESET)"
|
||||||
|
|
||||||
|
# Full production build
|
||||||
|
prod: clean generate build
|
||||||
|
@echo "$(CHECK) $(GREEN)Production build complete$(RESET)"
|
||||||
|
|
||||||
|
.DEFAULT_GOAL := help
|
6
docker-compose.yml
Normal file
6
docker-compose.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: ${IMAGE}
|
||||||
|
command: ["/app"]
|
||||||
|
ports:
|
||||||
|
- "${APP_PORT}:3000"
|
|
@ -22,6 +22,10 @@ while [[ $# -gt 0 ]]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Get the directory where this script is located
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
echo "Script directory: $SCRIPT_DIR"
|
||||||
|
|
||||||
OS=$(uname -s)
|
OS=$(uname -s)
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
|
|
||||||
|
@ -46,7 +50,7 @@ case $ARCH in
|
||||||
"x86_64")
|
"x86_64")
|
||||||
ARCH="x64"
|
ARCH="x64"
|
||||||
;;
|
;;
|
||||||
"arm64")
|
"arm64"|"aarch64")
|
||||||
ARCH="arm64"
|
ARCH="arm64"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -54,28 +58,34 @@ case $ARCH in
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# Construct the binary file name
|
|
||||||
BINARY="./tw/${OS}-${ARCH}"
|
echo "Detected OS: $OS"
|
||||||
|
echo "Detected Architecture: $ARCH"
|
||||||
|
|
||||||
|
# Use tw directory in script location
|
||||||
|
BINARY="${SCRIPT_DIR}/tw/${OS}-${ARCH}"
|
||||||
if [ "$OS" = "windows" ]; then
|
if [ "$OS" = "windows" ]; then
|
||||||
BINARY="${BINARY}.exe"
|
BINARY="${BINARY}.exe"
|
||||||
else
|
|
||||||
# Set execute permissions on the binary
|
|
||||||
chmod +x $BINARY
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Looking for binary at: $BINARY"
|
||||||
|
|
||||||
|
# Check if binary exists
|
||||||
|
if [ ! -f "$BINARY" ]; then
|
||||||
|
echo "Binary not found: $BINARY"
|
||||||
|
echo "Contents of ${SCRIPT_DIR}/tw/:"
|
||||||
|
ls -la "${SCRIPT_DIR}/tw/"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Make binary executable
|
||||||
|
chmod +x "$BINARY"
|
||||||
|
|
||||||
|
echo "Using binary: $BINARY"
|
||||||
echo "Extensions: $EXTENSIONS"
|
echo "Extensions: $EXTENSIONS"
|
||||||
echo "Directory: $DIRECTORY"
|
echo "Directory: $DIRECTORY"
|
||||||
echo "Output Directory: $OUTPUT_DIR"
|
echo "Output Directory: $OUTPUT_DIR"
|
||||||
|
|
||||||
# Set default values if not provided
|
|
||||||
OUTPUT_DIR="${OUTPUT_DIR:-../../public/css}"
|
|
||||||
DIRECTORY="${DIRECTORY:-.}"
|
|
||||||
|
|
||||||
if [[ -z "$EXTENSIONS" ]]; then
|
|
||||||
echo "No extensions provided."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Initialize an array for name conditions
|
# Initialize an array for name conditions
|
||||||
name_conditions=()
|
name_conditions=()
|
||||||
|
|
||||||
|
@ -90,12 +100,10 @@ INCLUDE_FILES=$(find "$DIRECTORY" -type f \( "${name_conditions[@]}" \))
|
||||||
|
|
||||||
echo "Files found: $INCLUDE_FILES"
|
echo "Files found: $INCLUDE_FILES"
|
||||||
|
|
||||||
# Optionally, remove leading './' if necessary
|
|
||||||
INCLUDE_FILES=$(echo "$INCLUDE_FILES" | sed 's|^\./||')
|
|
||||||
|
|
||||||
INCLUDE_FILES_ARRAY=$(echo "$INCLUDE_FILES" | awk '{printf "\"%s\",", $0}' | sed 's/,$//')
|
INCLUDE_FILES_ARRAY=$(echo "$INCLUDE_FILES" | awk '{printf "\"%s\",", $0}' | sed 's/,$//')
|
||||||
|
|
||||||
# Generate Tailwind config
|
# Generate Tailwind config in script directory
|
||||||
|
CONFIG_FILE="${SCRIPT_DIR}/tailwind.config.js"
|
||||||
echo "module.exports = {
|
echo "module.exports = {
|
||||||
content: [$INCLUDE_FILES_ARRAY],
|
content: [$INCLUDE_FILES_ARRAY],
|
||||||
theme: {
|
theme: {
|
||||||
|
@ -105,13 +113,10 @@ echo "module.exports = {
|
||||||
themes: [\"night\"],
|
themes: [\"night\"],
|
||||||
},
|
},
|
||||||
plugins: [require('daisyui'), require('@tailwindcss/typography')],
|
plugins: [require('daisyui'), require('@tailwindcss/typography')],
|
||||||
}" > tailwind.config.js
|
}" > "$CONFIG_FILE"
|
||||||
|
|
||||||
# Delete original CSS file if it exists
|
|
||||||
rm -f "${OUTPUT_DIR}/styles.css"
|
|
||||||
|
|
||||||
# Run the binary with the generated config
|
# Run the binary with the generated config
|
||||||
$BINARY build -i ./base.css -c tailwind.config.js -o "${OUTPUT_DIR}/styles.css" --minify
|
"$BINARY" build -i "${SCRIPT_DIR}/base.css" -c "$CONFIG_FILE" -o "${OUTPUT_DIR}/styles.css" --minify
|
||||||
|
|
||||||
# Wait for all background processes to finish
|
# Wait for all background processes to finish
|
||||||
wait
|
wait
|
||||||
|
|
Loading…
Add table
Reference in a new issue