Add air for hot reload

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-09-05 23:55:33 -06:00
parent 62ca473d12
commit ae6555c6b2
7 changed files with 56 additions and 90 deletions

22
.air.toml Normal file
View File

@@ -0,0 +1,22 @@
# Docs for .air.toml
# https://github.com/cosmtrek/air/blob/master/air_example.toml
root = "."
[build]
cmd = "task build"
full_bin = "task serve"
delay = 100
exclude_dir = ["tmp", "dist", "internal/database/dbgen"]
exclude_regex = [
"_test.go",
"_generated.go",
".sql.go",
".gen.go",
".min.js",
".min.css",
]
include_ext = ["go", "sql", "js", "css", "json"]
[log]
main_only = true

View File

@@ -25,8 +25,7 @@ RUN apt update && apt install -y postgresql-common=248 && \
# Install system dependencies and PostgreSQL clients
RUN apt update && \
apt install -y \
wget=1.21.3-1+b2 unzip=6.0-28 git=1:2.39.2-1.1 \
tzdata=2024a-0+deb12u1 lsof=4.95.0-1 \
wget=1.21.3-1+b2 unzip=6.0-28 tzdata=2024a-0+deb12u1 \
postgresql-client-13 postgresql-client-14 \
postgresql-client-15 postgresql-client-16 && \
rm -rf /var/lib/apt/lists/*
@@ -38,29 +37,29 @@ RUN \
tar -xzf task_linux_amd64.tar.gz && \
mv ./task /usr/local/bin/task && \
chmod +x /usr/local/bin/task && \
\
# Install GitHub CLI
wget --no-verbose https://github.com/cli/cli/releases/download/v2.55.0/gh_2.55.0_linux_amd64.tar.gz && \
tar -xzf gh_2.55.0_linux_amd64.tar.gz && \
mv gh_2.55.0_linux_amd64/bin/gh /usr/local/bin/gh && \
chmod +x /usr/local/bin/gh && \
\
# Install goose
wget --no-verbose https://github.com/pressly/goose/releases/download/v3.22.0/goose_linux_x86_64 && \
mv ./goose_linux_x86_64 /usr/local/bin/goose && \
chmod +x /usr/local/bin/goose && \
\
# Install sqlc
wget --no-verbose https://github.com/sqlc-dev/sqlc/releases/download/v1.27.0/sqlc_1.27.0_linux_amd64.tar.gz && \
tar -xzf sqlc_1.27.0_linux_amd64.tar.gz && \
mv ./sqlc /usr/local/bin/sqlc && \
chmod +x /usr/local/bin/sqlc && \
\
# Install golangci-lint
wget --no-verbose https://github.com/golangci/golangci-lint/releases/download/v1.60.3/golangci-lint-1.60.3-linux-amd64.tar.gz && \
tar -xzf golangci-lint-1.60.3-linux-amd64.tar.gz && \
mv ./golangci-lint-1.60.3-linux-amd64/golangci-lint /usr/local/bin/golangci-lint && \
chmod +x /usr/local/bin/golangci-lint
chmod +x /usr/local/bin/golangci-lint && \
# Install air
wget --no-verbose https://github.com/cosmtrek/air/releases/download/v1.52.3/air_1.52.3_linux_amd64.tar.gz && \
tar -xzf air_1.52.3_linux_amd64.tar.gz && \
mv ./air /usr/local/bin/air && \
chmod +x /usr/local/bin/air
# Go to the app dir, delete the temporary dir and create backups dir
WORKDIR /app

View File

@@ -25,8 +25,7 @@ RUN apt update && apt install -y postgresql-common=248 && \
# Install system dependencies and PostgreSQL clients
RUN apt update && \
apt install -y \
wget=1.21.3-1+b2 unzip=6.0-28 git=1:2.39.2-1.1 \
tzdata=2024a-0+deb12u1 lsof=4.95.0-1 \
wget=1.21.3-1+b2 unzip=6.0-28 tzdata=2024a-0+deb12u1 \
postgresql-client-13 postgresql-client-14 \
postgresql-client-15 postgresql-client-16 && \
rm -rf /var/lib/apt/lists/*
@@ -38,29 +37,29 @@ RUN \
tar -xzf task_linux_amd64.tar.gz && \
mv ./task /usr/local/bin/task && \
chmod +x /usr/local/bin/task && \
\
# Install GitHub CLI
wget --no-verbose https://github.com/cli/cli/releases/download/v2.55.0/gh_2.55.0_linux_amd64.tar.gz && \
tar -xzf gh_2.55.0_linux_amd64.tar.gz && \
mv gh_2.55.0_linux_amd64/bin/gh /usr/local/bin/gh && \
chmod +x /usr/local/bin/gh && \
\
# Install goose
wget --no-verbose https://github.com/pressly/goose/releases/download/v3.22.0/goose_linux_x86_64 && \
mv ./goose_linux_x86_64 /usr/local/bin/goose && \
chmod +x /usr/local/bin/goose && \
\
# Install sqlc
wget --no-verbose https://github.com/sqlc-dev/sqlc/releases/download/v1.27.0/sqlc_1.27.0_linux_amd64.tar.gz && \
tar -xzf sqlc_1.27.0_linux_amd64.tar.gz && \
mv ./sqlc /usr/local/bin/sqlc && \
chmod +x /usr/local/bin/sqlc && \
\
# Install golangci-lint
wget --no-verbose https://github.com/golangci/golangci-lint/releases/download/v1.60.3/golangci-lint-1.60.3-linux-amd64.tar.gz && \
tar -xzf golangci-lint-1.60.3-linux-amd64.tar.gz && \
mv ./golangci-lint-1.60.3-linux-amd64/golangci-lint /usr/local/bin/golangci-lint && \
chmod +x /usr/local/bin/golangci-lint
chmod +x /usr/local/bin/golangci-lint && \
# Install air
wget --no-verbose https://github.com/cosmtrek/air/releases/download/v1.52.3/air_1.52.3_linux_amd64.tar.gz && \
tar -xzf air_1.52.3_linux_amd64.tar.gz && \
mv ./air /usr/local/bin/air && \
chmod +x /usr/local/bin/air
# Go to the app dir, delete the temporary dir and create backups dir
WORKDIR /app

View File

@@ -25,8 +25,7 @@ RUN apt update && apt install -y postgresql-common=248 && \
# Install system dependencies and PostgreSQL clients
RUN apt update && \
apt install -y \
wget=1.21.3-1+b2 unzip=6.0-28 git=1:2.39.2-1.1 \
tzdata=2024a-0+deb12u1 lsof=4.95.0-1 \
wget=1.21.3-1+b2 unzip=6.0-28 tzdata=2024a-0+deb12u1 \
postgresql-client-13 postgresql-client-14 \
postgresql-client-15 postgresql-client-16 && \
rm -rf /var/lib/apt/lists/*
@@ -38,29 +37,29 @@ RUN \
tar -xzf task_linux_amd64.tar.gz && \
mv ./task /usr/local/bin/task && \
chmod +x /usr/local/bin/task && \
\
# Install GitHub CLI
wget --no-verbose https://github.com/cli/cli/releases/download/v2.55.0/gh_2.55.0_linux_amd64.tar.gz && \
tar -xzf gh_2.55.0_linux_amd64.tar.gz && \
mv gh_2.55.0_linux_amd64/bin/gh /usr/local/bin/gh && \
chmod +x /usr/local/bin/gh && \
\
# Install goose
wget --no-verbose https://github.com/pressly/goose/releases/download/v3.22.0/goose_linux_x86_64 && \
mv ./goose_linux_x86_64 /usr/local/bin/goose && \
chmod +x /usr/local/bin/goose && \
\
# Install sqlc
wget --no-verbose https://github.com/sqlc-dev/sqlc/releases/download/v1.27.0/sqlc_1.27.0_linux_amd64.tar.gz && \
tar -xzf sqlc_1.27.0_linux_amd64.tar.gz && \
mv ./sqlc /usr/local/bin/sqlc && \
chmod +x /usr/local/bin/sqlc && \
\
# Install golangci-lint
wget --no-verbose https://github.com/golangci/golangci-lint/releases/download/v1.60.3/golangci-lint-1.60.3-linux-amd64.tar.gz && \
tar -xzf golangci-lint-1.60.3-linux-amd64.tar.gz && \
mv ./golangci-lint-1.60.3-linux-amd64/golangci-lint /usr/local/bin/golangci-lint && \
chmod +x /usr/local/bin/golangci-lint
chmod +x /usr/local/bin/golangci-lint && \
# Install air
wget --no-verbose https://github.com/cosmtrek/air/releases/download/v1.52.3/air_1.52.3_linux_amd64.tar.gz && \
tar -xzf air_1.52.3_linux_amd64.tar.gz && \
mv ./air /usr/local/bin/air && \
chmod +x /usr/local/bin/air
# Go to the app dir, delete the temporary dir and create backups dir
WORKDIR /app

29
package-lock.json generated
View File

@@ -11,7 +11,6 @@
"devDependencies": {
"daisyui": "4.12.10",
"esbuild": "0.23.1",
"kill-port": "^2.0.1",
"standard": "17.1.0",
"tailwindcss": "3.4.6"
}
@@ -2409,13 +2408,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-them-args": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/get-them-args/-/get-them-args-1.3.2.tgz",
"integrity": "sha512-LRn8Jlk+DwZE4GTlDbT3Hikd1wSHgLMme/+7ddlqKd7ldwR6LjJgTVWzBnR01wnYGe4KgrXjg287RaI22UHmAw==",
"dev": true,
"license": "MIT"
},
"node_modules/glob": {
"version": "10.4.5",
"resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz",
@@ -3152,20 +3144,6 @@
"json-buffer": "3.0.1"
}
},
"node_modules/kill-port": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/kill-port/-/kill-port-2.0.1.tgz",
"integrity": "sha512-e0SVOV5jFo0mx8r7bS29maVWp17qGqLBZ5ricNSajON6//kmb7qqqNnml4twNE8Dtj97UQD+gNFOaipS/q1zzQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"get-them-args": "1.3.2",
"shell-exec": "1.0.2"
},
"bin": {
"kill-port": "cli.js"
}
},
"node_modules/levn": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
@@ -4253,13 +4231,6 @@
"node": ">=8"
}
},
"node_modules/shell-exec": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/shell-exec/-/shell-exec-1.0.2.tgz",
"integrity": "sha512-jyVd+kU2X+mWKMmGhx4fpWbPsjvD53k9ivqetutVW/BQ+WIZoDoP4d8vUMGezV6saZsiNoW2f9GIhg9Dondohg==",
"dev": true,
"license": "MIT"
},
"node_modules/side-channel": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",

View File

@@ -5,13 +5,11 @@
"scripts": {
"tailwindcss": "tailwindcss",
"standard": "standard",
"kill-port": "kill-port",
"esbuild": "esbuild"
},
"devDependencies": {
"daisyui": "4.12.10",
"esbuild": "0.23.1",
"kill-port": "2.0.1",
"standard": "17.1.0",
"tailwindcss": "3.4.6"
},

View File

@@ -1,7 +1,5 @@
version: "3"
interval: 500ms
dotenv: [".env"]
tasks:
@@ -17,27 +15,7 @@ tasks:
dev:
desc: Build and serve the project with hot reloading
watch: true
sources:
- "**/*.go"
- "**/*.sql"
- "**/*.js"
- "**/*.css"
- "**/*.json"
- ".env"
- exclude: "tmp/**"
- exclude: "dist/**"
- exclude: "internal/database/dbgen/**"
- exclude: "internal/view/static/css/style.min.css"
- exclude: "internal/view/static/js/app.min.js"
- exclude: "**/*.gen.go"
- exclude: "**/*.sql.go"
- exclude: "**/*_test.go"
- exclude: "**/_generated.go"
cmds:
- npm run kill-port -- 8085
- task build
- task serve
cmd: air -c .air.toml
build:
desc: Build the project