abh / geodns

DNS server with per-client targeted responses
Apache License 2.0
1.37k stars 191 forks source link

feat: docker build #119

Open liuzheng opened 4 years ago

liuzheng commented 4 years ago

Docker image build with multi-stage and save build time. Some code in Dockerfile is useless, such as

Dockerfile:
-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 *.go build ./

+COPY . /goapp

There is no need to add code one by one. Use .dockerignore then one COPY .

Dockerfile:
+FROM golang as prepare
+COPY go.mod go.sum /goapp/
+WORKDIR /goapp/
+RUN go mod download

-ADD vendor/ vendor/

.dockerignore:
+.git/
+.idea/
+vendor/
+dist/

This change because vendor/ not always same in any OS system. Use stage prepare to download packages can save time.

Build Docker image

make docker-build