updating build

remove exists function
This commit is contained in:
Laurent Le Houerou 2019-07-09 15:13:44 +04:00
parent 64d066ba4b
commit 8272d2d934
4 changed files with 19 additions and 23 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
build.sh
Dockerfile
.git
.idea
.gitignore
.dockerignore

View File

@ -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"]

View File

@ -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

20
main.go
View File

@ -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
}