-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
147 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ jobs: | |
uses: actions/checkout@v2 | ||
- name: CI Tasks | ||
run: make ci | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Create and publish the Docker image | ||
|
||
on: | ||
push: | ||
tags: ['v*'] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: | | ||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | ||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm/v7 | ||
file: ./build/package/Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# build stage | ||
FROM golang:1.18.1-alpine3.15 as build-stage | ||
WORKDIR /app | ||
COPY . . | ||
RUN CGO_ENABLED=0 go build -o /dyndns-docker ./cmd/dyndns-netcup-docker/main.go | ||
|
||
# production stage | ||
LABEL org.opencontainers.image.source https://github.com/Hentra/dyndns-netcup-go | ||
FROM alpine:latest | ||
RUN mkdir /cache/ | ||
COPY --from=build-stage /dyndns-docker /dyndns-docker | ||
|
||
ENTRYPOINT ["/dyndns-docker"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/Hentra/dyndns-netcup-go/internal" | ||
) | ||
|
||
const ( | ||
configFileLocation = "/config.yml" | ||
ipCacheLocation = "/ipcache" | ||
defaultInterval = time.Minute | ||
intervalEnv = "INTERVAL" | ||
) | ||
|
||
func main() { | ||
interval, err := parseEnv() | ||
if err != nil { | ||
log.Fatal("Could not parse interval: ", err) | ||
} | ||
|
||
logger := internal.NewLogger(true) | ||
|
||
config, err := internal.LoadConfig(configFileLocation) | ||
if err != nil { | ||
logger.Error("Error loading config file. Make sure a config file is mounted to ", configFileLocation, ":", err) | ||
} | ||
|
||
config.IPCache = ipCacheLocation | ||
|
||
cache, err := internal.NewCache(config.IPCache, time.Second*time.Duration(config.IPCacheTimeout)) | ||
if err != nil { | ||
logger.Error(err) | ||
} | ||
|
||
configurator := internal.NewDNSConfigurator(config, cache, logger) | ||
for { | ||
logger.Info("configure DNS records") | ||
configurator.Configure() | ||
time.Sleep(interval) | ||
} | ||
} | ||
|
||
func parseEnv() (time.Duration, error) { | ||
intervalTime := defaultInterval | ||
if interval, exists := os.LookupEnv(intervalEnv); exists { | ||
intervalSeconds, err := strconv.Atoi(interval) | ||
if err != nil { | ||
return 0, err | ||
} | ||
intervalTime = time.Duration(intervalSeconds) * time.Second | ||
} | ||
|
||
return intervalTime, nil | ||
} |