From c8f6d3a0d6bc0fb60b8f589e5eb98e4fc76ce49c Mon Sep 17 00:00:00 2001 From: networkop Date: Sun, 26 Jul 2020 13:20:45 +0100 Subject: [PATCH] Updated Tiltfile based with docker_build_with_restart --- DockerfileTilt | 28 ---------------------------- Tiltfile | 21 +++++++++++++-------- setup.go | 1 + tilt.Dockerfile | 12 ++++++++++++ 4 files changed, 26 insertions(+), 36 deletions(-) delete mode 100644 DockerfileTilt create mode 100644 tilt.Dockerfile diff --git a/DockerfileTilt b/DockerfileTilt deleted file mode 100644 index ac42039..0000000 --- a/DockerfileTilt +++ /dev/null @@ -1,28 +0,0 @@ -FROM golang:1.14.4 as builder - -WORKDIR /build - -# Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum -# cache deps before building and copying source so that we don't need to re-download as much -# and so that source changes don't invalidate our downloaded layer -RUN go mod download - -COPY cmd/ cmd/ -COPY *.go ./ - -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -o coredns cmd/coredns.go - -FROM debian:stable-slim - -RUN apt-get update && apt-get -uy upgrade -RUN apt-get -y install ca-certificates && update-ca-certificates - -FROM scratch - -COPY --from=0 /etc/ssl/certs /etc/ssl/certs -COPY --from=builder /build/coredns . - -EXPOSE 53 53/udp -ENTRYPOINT ["/coredns"] diff --git a/Tiltfile b/Tiltfile index 546a0ed..2dde47e 100644 --- a/Tiltfile +++ b/Tiltfile @@ -1,11 +1,20 @@ +load('ext://restart_process', 'docker_build_with_restart') +IMG = 'localhost:5000/coredns' -def local_build(): - local("CGO_ENABLED=0 go build cmd/coredns.go") +def binary(): + return "CGO_ENABLED=0 GOOS=linux GOATCH=amd64 GO111MODULE=on go build cmd/coredns.go" +local_resource('recompile', binary(), deps=['cmd', 'gateway.go', 'kubernetes.go', 'setup.go']) -local_build() -docker_build('localhost:5000/coredns', '.', dockerfile='./DockerfileTilt') +docker_build_with_restart(IMG, '.', + dockerfile='tilt.Dockerfile', + entrypoint=['/coredns'], + only=['./coredns'], + live_update=[ + sync('./coredns', '/coredns'), + ] + ) k8s_kind("kind") @@ -18,7 +27,3 @@ k8s_yaml('./test/ingress.yaml') # Metallb k8s_yaml('./test/metallb.yaml') - -watch_file("./gateway.go") -watch_file("./kubernetes.go") -watch_file("./cmd/*.go") \ No newline at end of file diff --git a/setup.go b/setup.go index 3c0ed99..5f881e5 100644 --- a/setup.go +++ b/setup.go @@ -20,6 +20,7 @@ func init() { } func setup(c *caddy.Controller) error { + gw, err := parse(c) if err != nil { return plugin.Error(thisPlugin, err) diff --git a/tilt.Dockerfile b/tilt.Dockerfile new file mode 100644 index 0000000..7bb1553 --- /dev/null +++ b/tilt.Dockerfile @@ -0,0 +1,12 @@ +FROM debian:stable-slim + +RUN apt-get update && apt-get -uy upgrade +RUN apt-get -y install ca-certificates && update-ca-certificates + +FROM golang:alpine + +COPY --from=0 /etc/ssl/certs /etc/ssl/certs +COPY coredns / + +EXPOSE 53 53/udp +CMD ["/coredns"]