diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..e3ea210 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,15 @@ +FROM golang:1.26 + +WORKDIR /app + +RUN apt install -y make gcc + +ENV CGO_ENABLED=1 + +# Copy dependency definitions first (caching optimization) +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN make build BUILD_DIR=/tmp diff --git a/Dockerfile.grunt b/Dockerfile.grunt new file mode 100644 index 0000000..3843997 --- /dev/null +++ b/Dockerfile.grunt @@ -0,0 +1,11 @@ +# Node.js runtime +FROM node:24 + +WORKDIR /var/www/html/ + +COPY package.* /var/www/html/ + +RUN npm install + +# Run the app +CMD [ "npm", "run", "grunt" ] diff --git a/Makefile b/Makefile index 519740f..d89e400 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,24 @@ NAME=blt VERSION=`git describe --tags` -.PHONY: build -## build: Compile the packages. +# used for changing the output directory within docker containers +BUILD_DIR ?= . + +dev-up: + docker compose -f docker-dev.yml up -d + +dev-down: + docker compose -f docker-dev.yml down + +dev-build: + docker compose -f docker-dev.yml build + build: - @go build -o $(NAME) -ldflags "-X git.metaunix.net/bitgoblin/blt/app.AppVersion=$(VERSION)" + @echo "Building Go binary..." + @go build -o $(BUILD_DIR)/$(NAME) -ldflags "-X git.metaunix.net/bitgoblin/blt/app.AppVersion=$(VERSION)" -.PHONY: grunt -## grunt: Compile frontend assets. -grunt: - @npm run grunt - -.PHONY: grunt-watch -## grunt-watch: Compile frontend assets while watching for changes. -grunt-watch: - @npm run grunt watch - -.PHONY: run -## run: Build and Run in development mode. -run: build - @./$(NAME) -e development - -.PHONY: run-prod -## run-prod: Build and Run in production mode. -run-prod: build - @./$(NAME) -e production - -.PHONY: clean -## clean: Clean project and previous builds. -clean: - @rm -f $(NAME) - -.PHONY: deps -## deps: Download modules -deps: - @go mod download - -.PHONY: test -## test: Run tests with verbose mode -test: - @go test -v ./tests/* +run: + $(BUILD_DIR)/$(NAME) .PHONY: help all: help diff --git a/docker-dev.yml b/docker-dev.yml new file mode 100644 index 0000000..01b0f6b --- /dev/null +++ b/docker-dev.yml @@ -0,0 +1,32 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile.dev + command: make run BUILD_DIR=/tmp + ports: + - "2830:2830" + volumes: + - .:/app # Mounts local directory for hot-reloading/live edits + - go-modules:/go/pkg/mod # Caches Go modules on host + # Mount the compiled static assets generated by Grunt + - static-assets:/app/public + environment: + - APP_ENV=development + assets: + build: + context: . + dockerfile: Dockerfile.grunt + # Override CMD to run watch mode during local dev + command: npm run grunt watch + volumes: + # Mount host code so Grunt detects file changes in real time + - .:/var/www/html + # Preserve container node_modules from being overwritten by host + - /var/www/html/node_modules + # Output compiled assets into the shared volume + - static-assets:/var/www/html/public + +volumes: + go-modules: + static-assets: diff --git a/main.go b/main.go index 672e89e..2f4548f 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,6 @@ func main() { web.RegisterRoutes(f) // alert the user and start the server - log.Println("Server is running...") + log.Println("Server is listening on 0.0.0.0:2830.") log.Println(http.ListenAndServe("0.0.0.0:2830", f)) }