wrappd.sh/Dockerfile

29 lines
800 B
Docker
Raw Normal View History

2024-12-05 14:00:58 +01:00
FROM golang:1.21.4
# Set default build-time value, not persisted in the container
ARG DOCKER_ENV=production
# Set runtime environment variable inside the container
ENV DOCKER_ENV=${DOCKER_ENV}
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.toml; \
else \
echo "Production environment detected, building and running the web..."; \
go build -o tmp/web ./cmd/web/main.go && ./tmp/web; \
fi