Skip to content

Commit

Permalink
enh: enhance hotreloading, update Go
Browse files Browse the repository at this point in the history
  • Loading branch information
petterip committed Oct 10, 2024
1 parent cb9aacb commit 503355d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
9 changes: 5 additions & 4 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ tmp_dir = "tmp" # Temporary directory for build artifacts
if command -v tailwindcss >/dev/null 2>&1; then
tailwindcss -i input.css -o assets/tailwind.css
elif command -v npx >/dev/null 2>&1; then
npx tailwindcss -i input.css -o assets/tailwind.css
npm install -D daisyui
npx --yes tailwindcss@latest -i input.css -o assets/tailwind.css
else
echo "Error: Neither 'tailwindcss' binary nor 'npx' found. Please install Tailwind CSS."
exit 1
Expand All @@ -33,14 +34,14 @@ tmp_dir = "tmp" # Temporary directory for build artifacts
delay = 1000 # Delay (in milliseconds) before restarting the app after a change

# Directories to exclude from watching
exclude_dir = ["assets", "tmp", "vendor", "testdata", "bin"]
exclude_dir = ["tmp", "vendor", "testdata", "bin"]
exclude_file = [] # Files to exclude from watching (none specified)
exclude_regex = ["_test.go"] # Exclude test files
exclude_unchanged = false # Watch even files that haven't changed
follow_symlink = false # Don't follow symlinks
full_bin = "" # Additional arguments when running the built binary
include_dir = ["views", "internal"] # Directories to include (watches all if empty)
include_ext = ["go", "tpl", "tmpl", "html", "css"] # File extensions to watch
include_dir = ["views", "internal", "assets"] # Directories to include (watches all if empty)
include_ext = ["go", "tpl", "tmpl", "html", "css", "js"] # File extensions to watch
kill_delay = "0s" # Delay before killing the app on a rebuild
log = "build-errors.log" # File to log build errors
send_interrupt = false # Send interrupt signal before killing the app
Expand Down
3 changes: 0 additions & 3 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ sudo apt-get install -y dialog

# Install air to support live reloading of server on code changes
go install github.com/air-verse/air@latest

# Install golangci-lint to allow running of linting locally
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin" v1.57.2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ output/soundscape.wav.csv
birdnet.db
birdnet.txt
custom_confidence_list.txt
node_modules
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
ARG TFLITE_LIB_DIR=/usr/lib

FROM --platform=$BUILDPLATFORM golang:1.22.3-bookworm as buildenv
FROM --platform=$BUILDPLATFORM golang:1.23.2-bookworm AS buildenv

# Install zip utility along with other dependencies
RUN apt-get update && apt-get install -y \
curl \
git \
sudo \
zip \
npm \
gcc-aarch64-linux-gnu \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -33,7 +34,7 @@ ARG TFLITE_LIB_DIR
RUN TFLITE_LIB_ARCH=$(echo ${TARGETPLATFORM} | tr '/' '_').tar.gz \
make download-tflite

FROM --platform=$BUILDPLATFORM buildenv as build
FROM --platform=$BUILDPLATFORM buildenv AS build
WORKDIR /home/dev-user/src/BirdNET-Go

# Compile BirdNET-Go
Expand All @@ -43,6 +44,10 @@ RUN --mount=type=cache,target=/go/pkg/mod,uid=10001,gid=10001 \
--mount=type=cache,target=/home/dev-user/.cache/go-build,uid=10001,gid=10001 \
make $(echo ${TARGETPLATFORM} | tr '/' '_')

# Download latest versions of Leaflet, htmx, Alpine.js and Tailwind CSS
RUN make download-assets
RUN make generate-tailwindcss

# Create final image using a multi-platform base image
FROM debian:bookworm-slim

Expand Down
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ LDFLAGS := -ldflags "-s -w -X 'main.buildDate=$(shell date -u +%Y-%m-%dT%H:%M:%S
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)

# Tailwind CSS
TAILWIND_INPUT := input.css
TAILWIND_OUTPUT := assets/tailwind.css

ifeq ($(UNAME_S),Linux)
NATIVE_TARGET := linux_$(if $(filter x86_64,$(UNAME_M)),amd64,arm64)
TFLITE_LIB_DIR := /usr/lib
Expand Down Expand Up @@ -69,6 +73,24 @@ download-tflite:
echo "TensorFlow Lite C library already exists."; \
fi


# Download assets
download-assets:
@echo "Downloading latest versions of Leaflet, htmx, Alpine.js, and Tailwind CSS"
@mkdir -p assets
@curl -sL https://unpkg.com/leaflet/dist/leaflet.js -o assets/leaflet.js
@curl -sL https://unpkg.com/leaflet/dist/leaflet.css -o assets/leaflet.css
@curl -sL https://unpkg.com/htmx.org -o assets/htmx.min.js
@curl -sL https://unpkg.com/alpinejs -o assets/alpinejs.min.js
@echo "Assets downloaded successfully"

# Create Tailwind CSS
generate-tailwindcss:
@echo "Creating Tailwind CSS with DaisyUI"
npm -D install daisyui
npx --yes tailwindcss@latest -i $(TAILWIND_INPUT) -o $(TAILWIND_OUTPUT) --minify
@echo "Tailwind CSS processed successfully"

# labels.zip depends on all files in the labels directory
$(LABELS_ZIP): $(LABELS_FILES)
@echo "Creating or updating labels.zip from contents of $(LABELS_DIR)/*"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tphakala/birdnet-go

go 1.22.3
go 1.23.2

require (
cgt.name/pkg/go-mwclient v1.3.0
Expand Down

0 comments on commit 503355d

Please sign in to comment.