axyut commited on
Commit
bf98406
·
1 Parent(s): 02b4e96

local env setup

Browse files
Files changed (5) hide show
  1. .air.toml +51 -0
  2. Dockerfile.dev +36 -0
  3. README.md +8 -1
  4. docker-compose.yml +20 -0
  5. main.go +1 -1
.air.toml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ root = "."
2
+ testdata_dir = "testdata"
3
+ tmp_dir = "tmp"
4
+
5
+ [build]
6
+ args_bin = []
7
+ bin = "./tmp/niyam"
8
+ cmd = "go build -o ./tmp/niyam ."
9
+ delay = 1000
10
+ exclude_dir = ["assets", "tmp", "vendor", "testdata", ".git", ".idea", ".vscode"]
11
+ exclude_file = ["README.md", "LICENSE", "CHANGELOG.md", "CONTRIBUTING.md", "Dockerfile", "docker-compose.yml", ".air.toml", ".gitignore", ".dockerignore"]
12
+ exclude_regex = ["_test.go"]
13
+ exclude_unchanged = false
14
+ follow_symlink = false
15
+ full_bin = ""
16
+ include_dir = []
17
+ include_ext = ["go", "tpl", "tmpl", "html"]
18
+ include_file = []
19
+ kill_delay = "0s"
20
+ log = "build-errors.log"
21
+ poll = false
22
+ poll_interval = 0
23
+ post_cmd = []
24
+ pre_cmd = []
25
+ rerun = false
26
+ rerun_delay = 500
27
+ send_interrupt = false
28
+ stop_on_error = false
29
+
30
+ [color]
31
+ app = ""
32
+ build = "yellow"
33
+ main = "magenta"
34
+ runner = "green"
35
+ watcher = "cyan"
36
+
37
+ [log]
38
+ main_only = false
39
+ time = false
40
+
41
+ [misc]
42
+ clean_on_exit = false
43
+
44
+ [proxy]
45
+ app_port = 0
46
+ enabled = false
47
+ proxy_port = 0
48
+
49
+ [screen]
50
+ clear_on_rebuild = false
51
+ keep_scroll = true
Dockerfile.dev ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dockerfile (modified for development with 'air')
2
+
3
+ # Stage 1: Builder
4
+ FROM golang:1.24.2-alpine AS builder
5
+
6
+ # Set the working directory inside the builder container
7
+ WORKDIR /app
8
+
9
+ # Enable Go modules and disable CGO for a statically linked binary.
10
+ ENV GO111MODULE=on \
11
+ CGO_ENABLED=0
12
+
13
+ # Install 'air' for live reloading (only needed in dev)
14
+ # Make sure to install it before copying all source code if you want to cache this layer.
15
+ RUN go install github.com/air-verse/air@latest
16
+
17
+ # Copy go.mod and go.sum to leverage Docker's build cache.
18
+ COPY go.mod go.sum ./
19
+
20
+ # Download Go module dependencies
21
+ RUN go mod download
22
+
23
+ # We will NOT build here for development, as 'air' will handle it.
24
+ # COPY . .
25
+ # RUN go build -o /app/niyam -ldflags "-s -w" ./main.go
26
+
27
+ # ---
28
+
29
+ # Stage 2: Runner (This stage is primarily for production builds.
30
+ # For development, Docker Compose will use the 'builder' stage for live reloading directly.)
31
+ FROM scratch
32
+
33
+ WORKDIR /app
34
+ COPY --from=builder /app/niyam .
35
+ EXPOSE 8080
36
+ CMD ["./niyam"]
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: GoAPI
3
  emoji: 🦀
4
  colorFrom: blue
5
  colorTo: pink
@@ -10,3 +10,10 @@ pinned: false
10
  # niyamAPI
11
 
12
  System for the Niyam project.
 
 
 
 
 
 
 
 
1
  ---
2
+ title: NiyamAPI
3
  emoji: 🦀
4
  colorFrom: blue
5
  colorTo: pink
 
10
  # niyamAPI
11
 
12
  System for the Niyam project.
13
+ https://axyut-niyamapi.hf.space/docs
14
+
15
+ # Run Locally
16
+
17
+ ```bash
18
+ docker compose up --build
19
+ ```
docker-compose.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # docker-compose.yml
2
+ version: "3.8"
3
+
4
+ services:
5
+ app:
6
+ build:
7
+ context: .
8
+ dockerfile: Dockerfile.dev # Refers to your main Dockerfile
9
+ target: builder # IMPORTANT: Build only the 'builder' stage for dev
10
+ ports:
11
+ - "7860:7860" # Map host port 8080 to container port 8080
12
+ volumes:
13
+ - .:/app # Mount your current host directory into /app inside the container
14
+ environment:
15
+ # Any environment variables your app needs for dev
16
+ - PORT=7860
17
+ command: air # Run the 'air' command, which watches files and rebuilds
18
+ # Optional: If you need to specify the main Go file path for air,
19
+ # you might need an .air.toml config file, or adjust the command.
20
+ # By default, air looks for main.go in the current directory or cmd/.
main.go CHANGED
@@ -40,7 +40,7 @@ func main() {
40
  // }
41
 
42
  addr := fmt.Sprintf(":%s", port) // Listen on all interfaces
43
- fmt.Printf("Server starting on http://localhost%s...\n", addr)
44
  err := http.ListenAndServe(addr, router) // <--- THIS IS KEY
45
  if err != nil {
46
  fmt.Printf("Server failed to start: %v\n", err)
 
40
  // }
41
 
42
  addr := fmt.Sprintf(":%s", port) // Listen on all interfaces
43
+ fmt.Printf("Server starting on http://localhost%s/docs\n", addr)
44
  err := http.ListenAndServe(addr, router) // <--- THIS IS KEY
45
  if err != nil {
46
  fmt.Printf("Server failed to start: %v\n", err)