From 8272d2d934a2f73a726c2cc2f1163cbd766e42fd Mon Sep 17 00:00:00 2001 From: Laurent Le Houerou Date: Tue, 9 Jul 2019 15:13:44 +0400 Subject: [PATCH] updating build remove exists function --- .dockerignore | 6 ++++++ Dockerfile | 15 ++++++++------- build.sh | 1 + main.go | 20 ++++---------------- 4 files changed, 19 insertions(+), 23 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..782f39c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +build.sh +Dockerfile +.git +.idea +.gitignore +.dockerignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4d2b71c..951b564 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,17 @@ -FROM golang as builder +FROM golang:1.12.6-alpine3.10 as builder +RUN apk add --update --no-cache ca-certificates git tzdata WORKDIR /tmp/dnsupdater -COPY . . -RUN go get . +COPY go.mod go.sum ./ +RUN go mod download +COPY ./ ./ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o dnsupdater . FROM busybox:glibc COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo -COPY --from=builder /tmp/dnsupdater/dnsupdater . - RUN mkdir -p /var/spool/cron/crontabs /var/log -COPY entry.sh /entry.sh RUN touch /var/log/cron.log -WORKDIR "/" + +COPY entry.sh /entry.sh +COPY --from=builder /tmp/dnsupdater/dnsupdater . ENTRYPOINT ["/entry.sh"] diff --git a/build.sh b/build.sh index a987ca1..2825884 100644 --- a/build.sh +++ b/build.sh @@ -4,4 +4,5 @@ docker build --rm -t llehouerou/dnsupdater:latest . rc=$? if [[ ${rc} == 0 ]]; then docker push llehouerou/dnsupdater + ssh srv03 'docker pull llehouerou/dnsupdater; cd docker/conf/goservices; docker-compose up -d --remove-orphans' fi \ No newline at end of file diff --git a/main.go b/main.go index 4b98fc2..147a6ba 100644 --- a/main.go +++ b/main.go @@ -77,15 +77,14 @@ func before(c *cli.Context) error { log.SetLevel(log.InfoLevel) configPath = path.Join(c.String("config"), "conf.json") - if confPathExists, _ := exists(configPath); !confPathExists { - return fmt.Errorf("config file does not exist : %s", configPath) + file, err := os.Open(configPath) + if err != nil { + return fmt.Errorf("error while opening config file: %v", err) } - - file, _ := os.Open(configPath) defer file.Close() decoder := json.NewDecoder(file) configuration = &Configuration{} - err := decoder.Decode(configuration) + err = decoder.Decode(configuration) if err != nil { return err } @@ -264,14 +263,3 @@ func GetOutboundIP() (string, error) { } return matches[1], nil } - -func exists(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return true, err -}