golang-app/Dockerfile

57 lines
1.4 KiB
Docker
Raw Permalink Normal View History

FROM golang:alpine as builder
2022-07-20 01:05:08 +03:00
LABEL org.opencontainers.image.authors="psssix <psssix@gmail.com>"
# set build environmet variables needed for multistage building
ENV CGO_ENABLED=0 \
GOOS=linux
# source workdir
WORKDIR /source
# Copy and download dependency using go mod
# Vendoring
COPY go.mod go.sum ./
RUN go mod download
# Copy the code into the container
COPY . .
# Build the application
RUN go build -ldflags "-s -w" -o bin/app .
FROM scratch
2022-08-03 23:17:49 +03:00
# or alpine, if you need install utilities
#
#FROM alpine:latest
#
## Add entrypoint dependency
#RUN apk add --no-cache bash
#RUN apk add --no-cache mysql-client mariadb-connector-c
2022-08-03 23:17:49 +03:00
# Move to /app directory as the place for resulting binary folder
WORKDIR /
# Copy binary from build to main folder
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /source/bin/app app
# Copy some application assets
2022-08-03 23:37:26 +03:00
#COPY --from=builder /source/deploy/docker/environment.sh ./deploy/docker/environment.sh
#COPY --from=builder /source/deploy/docker/logging.sh ./deploy/docker/logging.sh
2022-08-03 23:17:49 +03:00
#COPY --from=builder /source/entrypoint.sh .
#COPY --from=builder /source/migrations ./migrations
2022-07-20 01:05:08 +03:00
#COPY ./database/data.json /database/data.json
2022-08-03 23:17:49 +03:00
# Export necessary port
#EXPOSE 3000
2022-08-03 23:17:49 +03:00
# entry and start entrypoint with some actions and checks before CMD
#ENTRYPOINT ["bash", "/entrypoint.sh" ]
# Command to run when starting the container
2022-08-03 23:17:49 +03:00
CMD ["/app"]
# if have not application daemon
#CMD tail -f /dev/null