feat: multistage build Dockerfile, not tested
This commit is contained in:
parent
304b9c7381
commit
b9006e4a1b
@ -6,6 +6,9 @@
|
|||||||
# Visual Studio Code workspace files
|
# Visual Studio Code workspace files
|
||||||
/workstations.code-workspace
|
/workstations.code-workspace
|
||||||
|
|
||||||
# vendoring
|
# directories
|
||||||
/vendor/
|
/vendor/
|
||||||
/build/
|
/build/
|
||||||
|
|
||||||
|
go.mod
|
||||||
|
go.sum
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,9 +6,9 @@
|
|||||||
# Visual Studio Code workspace files
|
# Visual Studio Code workspace files
|
||||||
/workstations.code-workspace
|
/workstations.code-workspace
|
||||||
|
|
||||||
# vendoring
|
# directories
|
||||||
/vendor/
|
/vendor/
|
||||||
/build/pkg/
|
/build/
|
||||||
|
|
||||||
.env
|
.env
|
||||||
.env.docker
|
.env.docker
|
||||||
|
|||||||
49
Dockerfile
49
Dockerfile
@ -1,49 +1,44 @@
|
|||||||
FROM golang:alpine
|
LABEL org.opencontainers.image.authors="psssix <psssix@gmail.com>"
|
||||||
|
|
||||||
MAINTAINER psssix <psssix@gmail.com>
|
FROM golang:alpine as builder
|
||||||
|
|
||||||
# Set necessary environmet variables needed for our image
|
# set build environmet variables needed for multistage building
|
||||||
ENV GO111MODULE=on \
|
ENV CGO_ENABLED=0 \
|
||||||
CGO_ENABLED=0 \
|
GOOS=linux
|
||||||
GOOS=linux \
|
|
||||||
GOARCH=amd64
|
|
||||||
|
|
||||||
# Use workdir
|
# source workdir
|
||||||
RUN mkdir /source
|
|
||||||
WORKDIR /source
|
WORKDIR /source
|
||||||
|
|
||||||
# Copy and download dependency using go mod
|
# Copy and download dependency using go mod
|
||||||
COPY go.mod .
|
# Vendoring
|
||||||
COPY go.sum .
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
# Copy the code into the container
|
# Copy the code into the container
|
||||||
COPY . .
|
COPY . .
|
||||||
# Vendoring
|
# Some different way for vendoring
|
||||||
RUN go mod tidy && go mod vendor
|
#RUN go mod tidy && go mod vendor
|
||||||
|
|
||||||
# Build the application
|
# 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
|
FROM scratch
|
||||||
RUN mkdir /app
|
|
||||||
WORKDIR /app
|
# Move to /app directory as the place for resulting binary folder
|
||||||
|
WORKDIR /
|
||||||
|
|
||||||
# Copy binary from build to main folder
|
# Copy binary from build to main folder
|
||||||
#
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
# some application assets
|
COPY --from=builder build/app app
|
||||||
# RUN cp /source/build/bot . \
|
|
||||||
# && cp -R /source/docs/dictionaries .
|
|
||||||
RUN cp /source/build/golang-app
|
|
||||||
|
|
||||||
|
# Copy some application assets
|
||||||
#COPY ./database/data.json /dist/database/data.json
|
#COPY ./database/data.json /dist/database/data.json
|
||||||
|
|
||||||
RUN rm -rf /source
|
|
||||||
|
|
||||||
# Export necessary port
|
# Export necessary port
|
||||||
#EXPOSE 3000
|
#EXPOSE 3000
|
||||||
|
|
||||||
ENTRYPOINT ["/app/golang-app"]
|
ENTRYPOINT ["/app"]
|
||||||
|
|
||||||
# Command to run when starting the container
|
# Command to run when starting the container
|
||||||
#CMD ["/dist/golang-app"]
|
#CMD ["/app"]
|
||||||
# if have not application daemon
|
# if have not application daemon
|
||||||
#CMD tail -f /dev/null
|
#CMD tail -f /dev/null
|
||||||
Loading…
x
Reference in New Issue
Block a user