64 lines
1.7 KiB
Docker
64 lines
1.7 KiB
Docker
# Build image for building the application
|
|
FROM golang:1.24.0-bookworm AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install required packages (включая ca-certificates)
|
|
RUN apt-get update && apt-get install -y \
|
|
git \
|
|
curl \
|
|
ca-certificates && \
|
|
update-ca-certificates
|
|
|
|
# Install migrate
|
|
RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.18.1/migrate.linux-amd64.tar.gz | tar xvz && \
|
|
mv migrate /usr/local/bin/migrate
|
|
|
|
# Get login
|
|
COPY ./.netrc /root/.netrc
|
|
RUN chmod 600 /root/.netrc
|
|
|
|
# Let Go know which domains are private (important!)
|
|
ENV GOPRIVATE=gitea.cybertalant.ru
|
|
|
|
# (optional) If Go still tries HTTPS auth, force it to use credentials from .netrc
|
|
RUN git config --global credential.helper store
|
|
|
|
# Copy go.mod and go.sum for caching dependencies
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy the source code
|
|
COPY . ./
|
|
|
|
# Build the application
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -o main ./cmd/main.go
|
|
|
|
# Minimal image for running the application
|
|
FROM debian:bookworm-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Устанавливаем ca-certificates в финальный образ
|
|
RUN apt-get update && \
|
|
apt-get install -y --no-install-recommends ca-certificates && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create virtual environment
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Copy application files
|
|
COPY --from=builder /app/main .
|
|
COPY --from=builder /usr/local/bin/migrate /usr/local/bin/migrate
|
|
COPY --from=builder /app/migrations ./migrations
|
|
|
|
# Create directories
|
|
RUN mkdir -p ./docs
|
|
|
|
# Copy entrypoint
|
|
COPY docker-entrypoint.sh /usr/local/bin/
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
EXPOSE 6589
|
|
|
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] |