setup go modules
build in docker build shell script
This commit is contained in:
parent
41dcf6226d
commit
14a45cb1de
26
Dockerfile
26
Dockerfile
@ -1,19 +1,11 @@
|
|||||||
#
|
FROM golang as builder
|
||||||
# Alpine image to get some needed data
|
WORKDIR /tmp/dnsupdater
|
||||||
#
|
COPY . .
|
||||||
FROM alpine:latest as alpine
|
RUN go get .
|
||||||
RUN apk add --no-cache \
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o dnsupdater .
|
||||||
ca-certificates \
|
|
||||||
tzdata
|
|
||||||
|
|
||||||
#
|
|
||||||
# Image
|
|
||||||
#
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
# copy files from other containers
|
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||||
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
COPY --from=builder /tmp/dnsupdater/dnsupdater .
|
||||||
COPY --from=alpine /usr/share/zoneinfo /usr/share/zoneinfo
|
ENTRYPOINT ["/dnsupdater"]
|
||||||
|
|
||||||
COPY main /
|
|
||||||
ENTRYPOINT ["/main"]
|
|
4
build.sh
Normal file
4
build.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
docker build --rm -t llehouerou/dnsupdater:latest .
|
||||||
|
docker push llehouerou/dnsupdater
|
9
go.mod
Normal file
9
go.mod
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module gogs.lehouerou.net/Laurent/dnsupdater
|
||||||
|
|
||||||
|
go 1.12
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/robfig/cron v1.1.0 // indirect
|
||||||
|
github.com/sirupsen/logrus v1.4.2 // indirect
|
||||||
|
github.com/urfave/cli v1.20.0 // indirect
|
||||||
|
)
|
13
go.sum
Normal file
13
go.sum
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/robfig/cron v1.1.0 h1:jk4/Hud3TTdcrJgUOBgsqrZBarcxl6ADIjSC2iniwLY=
|
||||||
|
github.com/robfig/cron v1.1.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||||
|
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||||
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||||
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
23
main.go
23
main.go
@ -97,8 +97,8 @@ func start(c *cli.Context) error {
|
|||||||
tryLockSem := make(chan bool, 1)
|
tryLockSem := make(chan bool, 1)
|
||||||
tryLockSem <- true
|
tryLockSem <- true
|
||||||
|
|
||||||
cron := cron.New()
|
cr := cron.New()
|
||||||
err := cron.AddFunc(
|
err := cr.AddFunc(
|
||||||
scheduleSpec,
|
scheduleSpec,
|
||||||
func() {
|
func() {
|
||||||
select {
|
select {
|
||||||
@ -112,7 +112,7 @@ func start(c *cli.Context) error {
|
|||||||
log.Debug("Skipped another update already running.")
|
log.Debug("Skipped another update already running.")
|
||||||
}
|
}
|
||||||
|
|
||||||
nextRuns := cron.Entries()
|
nextRuns := cr.Entries()
|
||||||
if len(nextRuns) > 0 {
|
if len(nextRuns) > 0 {
|
||||||
log.Debug("Scheduled next run: " + nextRuns[0].Next.String())
|
log.Debug("Scheduled next run: " + nextRuns[0].Next.String())
|
||||||
}
|
}
|
||||||
@ -122,8 +122,8 @@ func start(c *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("First run: " + cron.Entries()[0].Schedule.Next(time.Now()).String())
|
log.Info("First run: " + cr.Entries()[0].Schedule.Next(time.Now()).String())
|
||||||
cron.Start()
|
cr.Start()
|
||||||
|
|
||||||
// Graceful shut-down on SIGINT/SIGTERM
|
// Graceful shut-down on SIGINT/SIGTERM
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
@ -131,7 +131,7 @@ func start(c *cli.Context) error {
|
|||||||
signal.Notify(interrupt, syscall.SIGTERM)
|
signal.Notify(interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
<-interrupt
|
<-interrupt
|
||||||
cron.Stop()
|
cr.Stop()
|
||||||
log.Info("Waiting for running update to be finished...")
|
log.Info("Waiting for running update to be finished...")
|
||||||
<-tryLockSem
|
<-tryLockSem
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -167,7 +167,10 @@ func update(c *cli.Context) error {
|
|||||||
Info("Ip has changed %s -> %s", currentIp, newIp)
|
Info("Ip has changed %s -> %s", currentIp, newIp)
|
||||||
|
|
||||||
for _, domain := range configuration.Domains {
|
for _, domain := range configuration.Domains {
|
||||||
SetCurrentIp(newIp, domain, configuration)
|
err = SetCurrentIp(newIp, domain, configuration)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SendStatusMail(fmt.Sprintf(`Home IP has changed : %s -> %s
|
SendStatusMail(fmt.Sprintf(`Home IP has changed : %s -> %s
|
||||||
@ -211,6 +214,9 @@ func GetCurrentIp(configuration Configuration) (string, error) {
|
|||||||
url := "https://dns.api.gandi.net/api/v5/domains/lehouerou.net/records/@/A"
|
url := "https://dns.api.gandi.net/api/v5/domains/lehouerou.net/records/@/A"
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
req.Header.Set("X-Api-Key", configuration.GandiKey)
|
req.Header.Set("X-Api-Key", configuration.GandiKey)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
@ -236,6 +242,9 @@ func SetCurrentIp(newip string, domain string, configuration Configuration) erro
|
|||||||
fmt.Println("json:", str)
|
fmt.Println("json:", str)
|
||||||
var jsonStr = []byte(str)
|
var jsonStr = []byte(str)
|
||||||
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(jsonStr))
|
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(jsonStr))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
req.Header.Set("X-Api-Key", configuration.GandiKey)
|
req.Header.Set("X-Api-Key", configuration.GandiKey)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user