generated from PenaSide/GolangTemplate
52 lines
1.0 KiB
Docker
52 lines
1.0 KiB
Docker
# BUILD
|
|
FROM golang:1.20.3-alpine AS build
|
|
|
|
# Update packages and clear cache
|
|
RUN apk add --no-cache curl
|
|
# Set work directory
|
|
WORKDIR /app
|
|
# Create binary directory
|
|
RUN mkdir /app/bin -p
|
|
# Create golang migrate util directory
|
|
RUN mkdir /bin/golang-migrate -p
|
|
# Add migrate tool
|
|
ADD ./tools/migrate /bin/golang-migrate/
|
|
# Add main files to app
|
|
ADD . .
|
|
# Build app
|
|
RUN GOOS=linux go build -o bin ./...
|
|
|
|
|
|
|
|
# TEST
|
|
FROM alpine:3.18.3 AS test
|
|
|
|
# Install packages
|
|
RUN apk --no-cache add ca-certificates
|
|
# Create home directory
|
|
WORKDIR /app
|
|
# Copy build file
|
|
COPY --from=build /app/bin/app ./app
|
|
# Copy migration dir
|
|
COPY --from=build /app/migrations/test ./migrations
|
|
# Install migrate tool
|
|
COPY --from=build /bin/golang-migrate /usr/local/bin
|
|
# CMD
|
|
CMD [ "./app" ]
|
|
|
|
|
|
|
|
# PRODUCTION
|
|
FROM alpine:3.18.3 AS production
|
|
|
|
# Install packages
|
|
RUN apk --no-cache add ca-certificates
|
|
# Create home directory
|
|
WORKDIR /app
|
|
# Copy build file
|
|
COPY --from=build /app/bin/app ./app
|
|
# Install migrate tool
|
|
COPY --from=build /bin/golang-migrate /usr/local/bin
|
|
# CMD
|
|
CMD ["./app"]
|