Upgrade Go version and add Air to Dockerfile
Add Air live‑reload tool and update the base image to golang:1.25. Configure docker‑compose with code mounts and a cached Go module volume, and switch the container command to run Air.
This commit is contained in:
16
Dockerfile
16
Dockerfile
@@ -1,24 +1,22 @@
|
|||||||
# Use the official Golang image as the base.
|
# Use the official Golang image as the base.
|
||||||
FROM golang:1.22-alpine AS base
|
FROM golang:1.25-alpine AS base
|
||||||
|
|
||||||
# Install git (required by go modules) and any other utilities.
|
# Install git (required by go modules) and any other utilities.
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Set the working directory inside the container.
|
# Set the working directory inside the container.
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install Air (live‑reload tool for Go).
|
||||||
|
ENV PATH="/go/bin:${PATH}"
|
||||||
|
RUN go install github.com/air-verse/air@latest
|
||||||
|
|
||||||
# Cache go.mod and go.sum to speed up dependency installation.
|
# Cache go.mod and go.sum to speed up dependency installation.
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
# Copy the rest of the source code.
|
# Copy the rest of the source code.
|
||||||
COPY . .
|
COPY . .
|
||||||
# Build the binary after copying the source files.
|
|
||||||
RUN go build -o /app/tmp/main ./cmd/app
|
|
||||||
|
|
||||||
# The container will start Air, which watches the source files and rebuilds the app on change.
|
# Use Air to watch source files and run the app.
|
||||||
CMD ["./tmp/main"]
|
CMD ["air", "-c", ".air.toml"]
|
||||||
|
|||||||
@@ -3,9 +3,14 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
environment:
|
environment:
|
||||||
- GO111MODULE=on
|
- GO111MODULE=on
|
||||||
command: ["./tmp/main"]
|
volumes:
|
||||||
|
- .:/app # Mount your code
|
||||||
|
- /app/tmp # Exclude tmp (built binaries)
|
||||||
|
- go-mod-cache:/go/pkg/mod # Cache Go modules
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
go-mod-cache:
|
||||||
|
|||||||
Reference in New Issue
Block a user