heating-monitor/Dockerfile.web
2024-11-28 22:53:45 +01:00

27 lines
795 B
Docker

FROM golang:1.21.4
ARG DOCKER_ENV=production # Set default build-time value, not persisted in the container
ENV DOCKER_ENV=${DOCKER_ENV} # Set runtime environment variable inside the container
WORKDIR /code
RUN echo "Building with DOCKER_ENV=${DOCKER_ENV}"
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go mod tidy && \
if [ "$DOCKER_ENV" = "local" ]; then \
echo "Local environment detected, installing Air..."; \
go install github.com/cosmtrek/air@v1.49.0; \
fi
CMD if [ "$DOCKER_ENV" = "local" ]; then \
echo "Local environment detected, running Air..." && \
air -c .air.web.toml; \
else \
echo "Production environment detected, building and running web..."; \
go build -o web ./cmd/web/main.go && ./web; \
fi