Skip to content

Commit

Permalink
Merge branch 'release/2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kutzilla committed Mar 7, 2022
2 parents 272a8e8 + 31e3350 commit 099b4ab
Show file tree
Hide file tree
Showing 22 changed files with 1,005 additions and 398 deletions.
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ WORKDIR /app

COPY go.mod ./
COPY go.sum ./
RUN go mod download

COPY main.go ./
COPY /pkg /app/pkg
COPY /cmd /app/cmd

RUN go build -o /hetzner-ddns
RUN go mod download
RUN go build -o hetzner-ddns ./cmd/hetzner-ddns

ENTRYPOINT ["/hetzner-ddns"]
ENTRYPOINT ["/app/hetzner-ddns"]
64 changes: 64 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
pipeline {

agent any

tools {
go '1.17.4'
}

environment {
REGISTRY_CREDENTIAL_ID = 'docker-hub'
}

stages {
stage('Install') {
steps {
sh 'go mod download'
}
}
stage('Build') {
steps {
sh 'go build -o hetzner-ddns ./cmd/hetzner-ddns'
}
}
stage('Test') {
steps {
sh 'go test ./pkg/*'
}
}
stage('Package') {
when {
anyOf {
branch 'develop';
branch 'release/*'
}
}
steps {
script {
docker.build("kutzilla/hetzner-ddns:latest")
}
}
}
stage('Publish') {
when {
branch 'release/*'
}
steps {
script {
def buildVersion = env.BRANCH_NAME.split('\\/')
if (buildVersion.length > 1) {
def version = buildVersion[1]
docker.withRegistry('', env.REGISTRY_CREDENTIAL_ID) {
def image = docker.build("kutzilla/hetzner-ddns:${version}")
image.push()
}
} else {
exit('No version to publish provided')
}

}

}
}
}
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://app.travis-ci.com/kutzilla/docker-hetzner-ddns.svg?branch=master)](https://app.travis-ci.com/kutzilla/docker-hetzner-ddns) [![Docker Pulls](https://img.shields.io/docker/pulls/kutzilla/hetzner-ddns.svg)](https://hub.docker.com/r/kutzilla/hetzner-ddns)
[![Build Status](https://jenkins.matthias-kutz.com/job/gitea/job/docker-hetzner-ddns/job/develop/badge/icon)](https://jenkins.matthias-kutz.com/job/gitea/job/docker-hetzner-ddns/job/develop/) [![Docker Pulls](https://img.shields.io/docker/pulls/kutzilla/hetzner-ddns.svg)](https://hub.docker.com/r/kutzilla/hetzner-ddns)

# Docker Hetzner DDNS

Expand Down Expand Up @@ -33,20 +33,21 @@ docker run kutzilla/hetzner-ddns example.com my-secret-api-token A


* `-e ZONE_NAME` - The DNS zone that DDNS updates should be applied to. **Required**
* `-e API_TOKEN` - Your Hetzner API token. **Required**
* `-e API_TOKEN` - Your Hetzner API token. **Required**
* `-e RECORD_TYPE` - The record type of your zone. If your zone uses an IPv4 address use `A`. Use `AAAA` if it uses an IPv6 address. **Required**
* `--restart=always` - ensure the container restarts automatically after host reboot.

## Optional Parameters

* `-e RECORD_NAME` - The name of the DNS-record that DDNS updates should be applied to. This could be `sub` if you like to update the subdomain `sub.example.com` of `example.com`. The default value is `@`.
* `-e CRON_EXPRESSION` - The cron expression of the DDNS update interval. The default is every 5 minutes - `*/5 * * * *`.
* `-e TTL` - The TTL (Time To Live) value specifies how long the record is valid before the nameservers are prompted to reload the zone file. The default is `86400`.

## Build

Build the latest version of the Docker image with the following command:

```
docker build kutzilla/hetzner-ddns .
docker build -t kutzilla/hetzner-ddns .
```

47 changes: 47 additions & 0 deletions cmd/hetzner-ddns/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"matthias-kutz.com/hetzner-ddns/pkg/args"
"matthias-kutz.com/hetzner-ddns/pkg/ddns"
"matthias-kutz.com/hetzner-ddns/pkg/dns"
"matthias-kutz.com/hetzner-ddns/pkg/ip"
)

func main() {
// Set args by cli values or env variables
var zoneName, apiToken, recordType string
args.SetArgs(&zoneName, &apiToken, &recordType)

// Validate args
args.ValidateArgs(zoneName, apiToken, recordType)

// Set optional args or set the default values
var recordName, cronExpression string
args.SetOptionalArgs(&recordName, &cronExpression)

dnsProvider := dns.Hetzner{
ApiToken: apiToken,
}

ipProvider := ip.Ipify{}

ddnsParameter := ddns.Parameter{
ZoneName: zoneName,
RecordName: recordName,
RecordType: recordType,
TTL: 0,
}

ddnsService := ddns.Service{
DnsProvider: dnsProvider,
IpProvider: ipProvider,
Parameter: ddnsParameter,
}

ddnsScheduler := ddns.Scheduler{
CronExpression: cronExpression,
Service: ddnsService,
}

ddnsScheduler.Start()
}
12 changes: 11 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ module matthias-kutz.com/hetzner-ddns

go 1.17

require github.com/robfig/cron/v3 v3.0.0
require (
github.com/robfig/cron/v3 v3.0.0
github.com/stretchr/testify v1.7.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/namsral/flag v1.7.4-pre // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/namsral/flag v1.7.4-pre h1:b2ScHhoCUkbsq0d2C15Mv+VU8bl8hAXV8arnWiOHNZs=
github.com/namsral/flag v1.7.4-pre/go.mod h1:OXldTctbM6SWH1K899kPZcf65KxJiD7MsceFUpB5yDo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E=
github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 099b4ab

Please sign in to comment.