customer/Dockerfile

56 lines
1.2 KiB
Docker
Raw Normal View History

2023-06-22 09:36:43 +00:00
# BUILD
FROM golang:1.20.3-alpine AS build
2023-09-14 10:07:28 +00:00
# Update packages and clear cache
RUN apk update && apk add --no-cache curl && rm -rf /var/cache/apk/*
# Set work directory
WORKDIR /app
# Create binary directory
2023-06-22 09:36:43 +00:00
RUN mkdir /app/bin -p
2023-09-14 10:07:28 +00:00
# Create golang migrate util directory
2023-06-22 09:36:43 +00:00
RUN mkdir /bin/golang-migrate -p
2023-09-14 10:07:28 +00:00
# Add migrate tool
ADD ./tools/migrate /bin/golang-migrate/
# Add main files to app
ADD . .
2023-06-22 09:36:43 +00:00
# Download go depences
RUN go mod download
# Build app
RUN GOOS=linux go build -o bin ./...
# TEST
2023-09-14 10:07:28 +00:00
FROM alpine:3.18.3 AS test
2023-06-22 09:36:43 +00:00
# Install packages
2023-09-14 10:07:28 +00:00
RUN apk --no-cache add ca-certificates && rm -rf /var/cache/apk/*
# Set GO111MODULE env
2023-06-22 09:36:43 +00:00
ENV GO111MODULE=off
# 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
2023-09-14 10:07:28 +00:00
# CMD
CMD [ "./app" ]
2023-06-22 09:36:43 +00:00
# PRODUCTION
2023-09-14 10:07:28 +00:00
FROM alpine:3.18.3 AS production
2023-06-22 09:36:43 +00:00
# Install packages
2023-09-14 10:07:28 +00:00
RUN apk --no-cache add ca-certificates && rm -rf /var/cache/apk/*
2023-06-22 09:36:43 +00:00
# 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"]