Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: docker build #119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git/
.idea/
vendor/
dist/
49 changes: 20 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
FROM golang:1.14-alpine3.11 as build

RUN apk add --no-cache git tar

WORKDIR /go/src/github.com/abh/geodns
FROM golang as prepare
COPY go.mod go.sum /goapp/
WORKDIR /goapp/
RUN go mod download

FROM golang as build
ENV CGO_ENABLED=0

ADD vendor/ vendor/
ADD applog/ applog/
ADD countries/ countries/
ADD geodns-logs/ geodns-logs/
ADD health/ health/
ADD monitor/ monitor/
ADD querylog/ querylog/
ADD server/ server/
ADD targeting/ targeting/
ADD typeutil/ typeutil/
ADD zones/ zones/
ADD service/ service/
ADD service-logs/ service-logs/
ADD .git/ .git/
ADD *.go build ./

RUN ./build
RUN ls -l
RUN ls -l dist

RUN ln dist/* /
ARG REVISION=${REVISION:-""}
ENV REVISION=${REVISION}
COPY --from=prepare /go/pkg/mod /go/pkg/mod
COPY . /goapp
WORKDIR /goapp/
RUN go mod vendor
RUN go build -o dist/geodns \
-mod=vendor \
-trimpath \
-ldflags "-X main.gitVersion=$REVISION -X main.buildTime=`TZ=UTC date "+%Y-%m-%dT%H:%MZ"`" \
-v && \
(cd geodns-logs && go build -trimpath -mod=vendor -v -o ../dist/geodns-logs && cd ..)

FROM scratch
COPY --from=build /geodns-linux-amd64 /geodns
COPY --from=build /geodns-logs-linux-amd64 /geodns-logs
COPY --from=build /goapp/dist/geodns /geodns
COPY --from=build /goapp/dist/geodns-logs /geodns-logs
RUN mkdir ./dns/
ENTRYPOINT ["/geodns"]
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ docker-test: .PHONY
golang:1.14-alpine3.11 -- \
go test ./...

docker-build: .PHONY
docker build --build-arg REVISION=`git rev-parse --short=5 HEAD` -t geodns .

devel:
go build -tags devel

Expand Down