diff --git a/.dockerignore b/.dockerignore index f93757f..7645523 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,6 +6,9 @@ # Visual Studio Code workspace files /workstations.code-workspace -# vendoring +# directories /vendor/ -/build/ \ No newline at end of file +/build/ + +go.mod +go.sum \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0f36fad..557f4c0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,9 @@ # Visual Studio Code workspace files /workstations.code-workspace -# vendoring +# directories /vendor/ -/build/pkg/ +/build/ .env .env.docker diff --git a/Dockerfile b/Dockerfile index 0f64ee6..65ad9aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,44 @@ -FROM golang:alpine +LABEL org.opencontainers.image.authors="psssix " -MAINTAINER psssix +FROM golang:alpine as builder -# Set necessary environmet variables needed for our image -ENV GO111MODULE=on \ - CGO_ENABLED=0 \ - GOOS=linux \ - GOARCH=amd64 +# set build environmet variables needed for multistage building +ENV CGO_ENABLED=0 \ + GOOS=linux -# Use workdir -RUN mkdir /source +# source workdir WORKDIR /source # Copy and download dependency using go mod -COPY go.mod . -COPY go.sum . +# Vendoring +COPY go.mod go.sum ./ +RUN go mod download + # Copy the code into the container COPY . . -# Vendoring -RUN go mod tidy && go mod vendor +# Some different way for vendoring +#RUN go mod tidy && go mod vendor # Build the application -RUN go build -o build/golang-app -mod=vendor . +RUN go build -o build/app . -# Move to /smart-bot directory as the place for resulting binary folder -RUN mkdir /app -WORKDIR /app +FROM scratch + +# Move to /app directory as the place for resulting binary folder +WORKDIR / # Copy binary from build to main folder -# -# some application assets -# RUN cp /source/build/bot . \ -# && cp -R /source/docs/dictionaries . -RUN cp /source/build/golang-app - -# COPY ./database/data.json /dist/database/data.json - -RUN rm -rf /source +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder build/app app +# Copy some application assets +#COPY ./database/data.json /dist/database/data.json # Export necessary port -# EXPOSE 3000 +#EXPOSE 3000 -ENTRYPOINT ["/app/golang-app"] +ENTRYPOINT ["/app"] # Command to run when starting the container -#CMD ["/dist/golang-app"] +#CMD ["/app"] # if have not application daemon #CMD tail -f /dev/null \ No newline at end of file