45 lines
1.0 KiB
Docker
45 lines
1.0 KiB
Docker
# --- Stage 1: Build the Go application ---
|
|
FROM golang:1.23 AS builder
|
|
|
|
ENV CGO_ENABLED=0
|
|
ENV GOOS=linux
|
|
ENV GOARCH=amd64
|
|
|
|
# Install goose
|
|
WORKDIR /goose.git
|
|
|
|
RUN git clone https://github.com/pressly/goose.git .
|
|
RUN go build -tags='no_clickhouse no_libsql no_mssql no_mysql no_sqlite3 no_vertica no_ydb' \
|
|
-o goose ./cmd/goose
|
|
|
|
# Build app
|
|
WORKDIR /app
|
|
|
|
# Copy the Go modules and dependencies
|
|
COPY ./src/go.mod ./src/go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy the source code
|
|
COPY ./src/cmd ./cmd
|
|
COPY ./src/assets ./assets
|
|
COPY ./src/internal ./internal
|
|
|
|
# Build the application
|
|
RUN go build -o main cmd/frontend/*
|
|
|
|
|
|
# --- Stage 3: Run the application ---
|
|
FROM alpine:latest
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy the built binary from the builder stage
|
|
COPY --from=builder /app/main .
|
|
COPY --from=builder /goose.git/goose .
|
|
COPY ./src/assets ./assets
|
|
|
|
EXPOSE 8080
|
|
|
|
# Command to run the application
|
|
CMD ["sh", "-c", "/app/goose -dir=/app/assets/migrations/ postgres postgresql://$DB_USER:$DB_PASS@$DB_HOST:$DB_PORT/$DB_NAME up && /app/main"]
|