FROM golang:1.22-alpine AS base
RUN apk add --no-cache postgresql-client git make
RUN go install ariga.io/atlas/cmd/atlas@latest
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
RUN go install github.com/vektra/mockery/v2@v2.42.1
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod tidy
COPY . .
EXPOSE 8080
# 開発環境用のステージFROM base AS local
RUN go install github.com/cosmtrek/air@latest
CMD ["air"]
# 本番環境用のステージFROM base AS prod
RUN go build -tags netgo -ldflags '-s -w' -o app
# スクリプトに実行権限を付与RUN chmod +x start.sh
CMD ["./start.sh"]
# デフォルトのステージを本番環境に設定FROM prod