Compare commits

...

23 Commits

Author SHA1 Message Date
952c7b8660 tza not needed 2024-12-10 18:48:09 -04:00
9ba30d10b7 ADD tz data to alpine now comes without it
All checks were successful
Generic Build / build (push) Successful in 8s
Build Push Prod / build (push) Successful in 2m27s
2024-12-10 18:40:43 -04:00
94b1681a38 delete master check
All checks were successful
dev workflow / test (push) Successful in 16s
dev workflow / vulnCheck (push) Successful in 26s
Generic Build / build (push) Successful in 7s
Build Push Prod / build (push) Successful in 2m31s
2024-12-10 12:49:07 -04:00
574467e307 FIX create unknow name
Some checks failed
dev workflow / test (push) Successful in 17s
dev workflow / vulnCheck (push) Successful in 26s
Build Push Prod / build (push) Failing after 5s
Generic Build / build (push) Successful in 24s
2024-12-10 12:46:18 -04:00
dcb4c5cfc6 Merge pull request 'ADD path trigger' (#3) from feature/add_path_trigger into dev
All checks were successful
dev workflow / test (push) Successful in 5s
dev workflow / vulnCheck (push) Successful in 9s
Reviewed-on: http://gitea/maximo/ddns/pulls/3
2024-11-16 23:08:59 -04:00
3e799c00d3 ADD path trigger
All checks were successful
dev workflow / test (push) Successful in 5s
dev workflow / vulnCheck (push) Successful in 9s
2024-11-16 23:07:30 -04:00
7bf6521002 Refine triggers
All checks were successful
dev workflow / test (push) Successful in 5s
dev workflow / vulnCheck (push) Successful in 8s
2024-11-16 22:38:26 -04:00
ab94f6207e REMOVE path trigger
All checks were successful
dev workflow / test (push) Successful in 4s
dev workflow / vulnCheck (push) Successful in 33s
2024-11-16 22:36:22 -04:00
412fcb497d ADD master to trigger 2024-11-16 22:35:37 -04:00
0218ccd4cb test change 2024-11-16 22:34:08 -04:00
34d5d40bd6 Merge pull request 'feature/add_dev_workflow' (#1) from feature/add_dev_workflow into master
Reviewed-on: http://gitea/maximo/ddns/pulls/1
2024-11-16 22:31:59 -04:00
5f0f92ebda Test trigger 2024-11-16 22:29:06 -04:00
45230f4627 ADD feature branch to trigger 2024-11-16 22:26:54 -04:00
bbf2a8d354 FIX sintax 2024-11-16 22:25:32 -04:00
c93003055c ADD env to steps 2024-11-16 22:22:54 -04:00
c2aa4b82e5 FIX typo 2024-11-16 22:21:41 -04:00
b93c7cdfd2 CHANGED to all push 2024-11-16 22:20:28 -04:00
2caa61e3a3 ADD path to pull request 2024-11-16 22:17:55 -04:00
7c7c359954 ADD feature to run 2024-11-16 22:11:28 -04:00
353b046344 ADD vuklln check 2024-11-16 22:09:06 -04:00
4d1e262afd RENAMe jub
All checks were successful
dev workflow / build (push) Successful in 5s
2024-11-16 13:56:09 -04:00
37a6573ce8 ADD test to all branches for changes
All checks were successful
dev workflow / build (push) Successful in 24s
2024-11-16 13:54:43 -04:00
fba129ec43 squash from 47e81fd011
All checks were successful
Build Push / build (push) Successful in 2m8s
2024-11-16 11:14:03 -04:00
12 changed files with 186 additions and 43 deletions

0
.dockerignore Normal file
View File

44
.github/workflows/image_creation.yaml vendored Normal file
View File

@ -0,0 +1,44 @@
name: Build Push Prod
on:
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
env:
TOKEN: ${{ secrets.TOKEN }}
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Quemu
uses: docker/setup-qemu-action@v3
- name: Set Up BuildX
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
registry: https://git.maximotejeda.com
username: ${{ vars.USERNAME }}
password: ${{ secrets.PWD }}
- name: calculate short sha
id: calculate-sha
run: |
echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: git.maximotejeda.com/maximo/ddns:${{ github.ref_name }}
build-args: |
version=${{ github.ref_name }}
SHORTSHA=${{ steps.calculate-sha.outputs.shortsha }}

View File

@ -1,4 +1,4 @@
name: Go-tags
name: Generic Build
on:
push:
tags:
@ -6,25 +6,42 @@ on:
jobs:
build:
runs-on: ubuntu-latest
env:
TOKEN: ${{ secrets.TOKEN }}
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v4
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
- name: install dependencies
run: go get .
- name: Build
env:
TAG_VERSION: ${{ github.ref_name }}
run: go mod tidy
- name: set shortsha
id: set-sha
run: |
go build -v -o ./bin/ddnser-$TAG_VERSION ./cmd/...
zip -r ddnser-$TAG_VERSION ./bin/ddnser-$TAG_VERSION
- name: Push to gitea
env:
USERNAME: ${{ vars.USERNAME }}
TOKEN: ${{ secrets.TOKEN }}
TAG_VERSION: ${{ github.ref_name }}
run: curl --user $USERNAME:$TOKEN \
--upload-file ./bin/ddnser-$TAG_VERSION.zip \
http://10.0.0.171/api/packages/$USERNAME/go/upload
echo "shortsha=$(git rev-parse --short HEAD)" >> GITHUB_OUTPUT
- name: Build amd64
run: |
shortsha=${{ steps.set-sha.outputs.shortsha }} GOOS=linux GOARCH=amd64 go build -o bin/ddns_amd64_$TAG_VERSION -ldflags "-X main.Shortsha=$shortsha -X main.Version=$TAG_VERSION -X main.Aarch=amd64" ./cmd/...
- name: Build arm64
run: |
shortsha=${{ steps.set-sha.outputs.shortsha }} GOOS=linux GOARCH=arm64 go build -o bin/ddns_arm64_$TAG_VERSION -ldflags "-X main.Shortsha=$shortsha -X main.Version=$TAG_VERSION -X main.Aarch=arm64" ./cmd/...
- name: push generic registry amd64
run: |
curl --user $USERNAME:${{ secrets.TOKEN }} --upload-file bin/ddns_amd64_$TAG_VERSION https://git.maximotejeda.com/api/packages/$USERNAME/generic/ddns/amd64_$TAG_VERSION/ddns
- name: push generic registry arm64
run: |
curl --user $USERNAME:${{ secrets.TOKEN }} --upload-file bin/ddns_arm64_$TAG_VERSION https://git.maximotejeda.com/api/packages/$USERNAME/generic/ddns/arm64_$TAG_VERSION/ddns
- name: test env download path
run: |
echo "curl -OJ http://gitea/api/packages/$USERNAME/generic/ddns/arm64_$TAG_VERSION/ddns"

47
.github/workflows/test_workflow.yml vendored Normal file
View File

@ -0,0 +1,47 @@
name: dev workflow
on:
push:
branches:
- master
- dev
- 'feature/**'
paths:
- '**.go'
- '**.yml'
- '**.yaml'
jobs:
test:
runs-on: ubuntu-latest
env:
TOKEN: ${{ secrets.TOKEN }}
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: test with go
run: go test -v ./...
vulnCheck:
runs-on: ubuntu-latest
env:
TOKEN: ${{ secrets.TOKEN }}
USERNAME: ${{ vars.USERNAME }}
TAG_VERSION: ${{ github.ref_name }}
steps:
- name: checkout Code
uses: actions/checkout@v4
- name: go vuln check
uses: golang/govulncheck-action@v1
with:
go-version-file: 'go.mod'
go-package: ./...

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
/.env
bin/*
bin/*
/.env2

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM golang:alpine AS builder
ARG TARGETARCH
ARG version=not-set
ARG SHORTSHA=not-set
WORKDIR /app
COPY . .
# https://stackoverflow.com/questions/70369368/check-architecture-in-dockerfile-to-get-amd-arm
RUN go build -o bin/ddns \
-ldflags "-X main.Shortsha=${SHORTSHA} \
-X main.Version=${version} \
-X main.Aarch=${TARGETARCH}" ./cmd
FROM alpine AS runner
COPY --from=builder /app/bin/ddns /usr/bin/
ENTRYPOINT /usr/bin/ddns

View File

@ -1,3 +1,12 @@
#+CAPTION: Gh badge
#+NAME: fig:gh-badge
[[https://git.maximotejeda.com/maximo/ddns/actions/workflows/tags.yml/badge.svg?branch=master]]
#+begin_src markdown
![tags](https://git.maximotejeda.com/maximo/ddns/actions/workflows/tags.yml/badge.svg?branch=master)
#+end_src
Working creating Request
#+begin_src shell
curl --request POST \
@ -63,3 +72,8 @@ check config for a zone
#+RESULTS:
| {"result":{"nameservers":{"type":"cloudflare.standard"} | foundation_dns:false | multi_provider:false | secondary_overrides:false | soa:{"mname":null | rname:"dns.cloudflare.com" | refresh:10000 | retry:2400 | expire:604800 | min_ttl:1800 | ttl:3600} | ns_ttl:86400 | zone_mode:"standard" | internal_dns:{"reference_zone_id":null} | flatten_all_cnames:false} | success:true | errors:[] | messages:[]} |
To Download bin from gitea instance
#+begin_src shell
curl -OJ http://gitea/api/packages/maximo/generic/ddns/arm64_v0.0.0-13/ddns
#+end_src

View File

@ -20,7 +20,11 @@ var (
proxied bool
helpMsg string
provider string
rID string
rID string
comment string
Version string
Shortsha string
Aarch string
)
func init() {
@ -40,20 +44,21 @@ func init() {
flag.StringVar(&provider, "pv", "cf", "Dns records provider")
flag.StringVar(&rID, "rid", "", "Select record id (shorthand)")
flag.StringVar(&rID, "record-id", "", "Select record id")
flag.StringVar(&comment, "comment", "", "comment")
flag.StringVar(&comment, "c", "", "comment operation")
}
func main() {
flag.Parse()
lvl := new(slog.LevelVar)
switch os.Getenv("ENV"){
switch os.Getenv("ENV") {
case "debug", "dev":
lvl.Set(slog.LevelDebug)
case "prod":
lvl.Set(slog.LevelInfo)
}
log := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: lvl}))
log = log.With("version", Version, "shortsha", Shortsha, "aarch", Aarch)
ctx := context.Background()
helpmsg := "required flag not provided "
if tok == "" {
@ -89,7 +94,7 @@ func main() {
fmt.Println(zid)
panic(err)
}
app.Operation(operation, name, tipe, ip, proxied, rID)
app.Operation(operation, name, tipe, ip, rID, comment, proxied)
}

4
compose.yaml Normal file
View File

@ -0,0 +1,4 @@
services:
ddns:
image: ddns
env_file: ".env"

View File

@ -66,7 +66,7 @@ func (c *client) Do() (res *Response, err error) {
ipSTR, err := io.ReadAll(resp.Body)
if err != nil {
c.log.Error("reading body", err)
c.log.Error("reading body", "error", err.Error())
}
ipi := net.ParseIP(string(ipSTR))

View File

@ -1,14 +1,2 @@
package provider
import (
"os"
"testing"
)
func TestGetSettings(t *testing.T) {
os.Setenv("ENVIRONMENT", "dev")
s := GetSettingsFile("")
if s != nil {
t.Errorf("empty settings: %v", s)
}
}

View File

@ -129,7 +129,7 @@ func (app *Application) Create(rBody cf.RequestBody) (res *cf.DetailsResult, err
// Overwrite
func (app *Application) Overwrite(re *cf.Result, rBody *cf.RequestBody) {
rBody.Comment = "Overwrite from app cli tool"
rBody.Comment = rBody.Comment + " Overwrite from app cli tool"
res, err := app.client.Overwrite(*rBody, re.ID)
if err != nil {
app.log.Error("[Overwrite]", "error", err)
@ -150,7 +150,7 @@ func (app Application) Delete(re *cf.Result) {
// Operation
// expose required
func (app *Application) Operation(op string, name, tipo, ipSTR string, proxied bool, rID string) {
func (app *Application) Operation(op string, name, tipo, ipSTR,rID, comment string, proxied bool) {
var (
res *checker.Response
err error
@ -205,7 +205,7 @@ func (app *Application) Operation(op string, name, tipo, ipSTR string, proxied b
if dn == "*" {
for _, rec := range app.zoneRecords {
if rec.Content != app.publicIP.String() {
rBody = app.GenerateReqBody(rec.Name, res.Type, app.publicIP.String(), proxied)
rBody = app.GenerateReqBody(rec.Name, res.Type, app.publicIP.String(), comment, proxied)
app.Update(&rec, *rBody)
} else {
app.log.Info("same ip for", "record", rec.Name, "DstIP", rec.Content, "NewIP", app.publicIP)
@ -216,7 +216,7 @@ func (app *Application) Operation(op string, name, tipo, ipSTR string, proxied b
}
} else {
if rs.Content != app.publicIP.String() {
rBody = app.GenerateReqBody(name, res.Type, app.publicIP.String(), proxied)
rBody = app.GenerateReqBody(name, res.Type, app.publicIP.String(),comment, proxied)
app.Update(rs, *rBody)
} else {
app.log.Error("same ip on dns record")
@ -227,8 +227,13 @@ func (app *Application) Operation(op string, name, tipo, ipSTR string, proxied b
if name == "" {
panic("name cant be empty for op create")
}
if dn == "" {
app.log.Debug("domains available", "domains", app.zoneRecords)
dn = name
}
fmt.Printf("domain name: %s", dn)
rBody = app.GenerateReqBody(dn, tipo, app.publicIP.String(), proxied)
rBody = app.GenerateReqBody(dn, tipo, app.publicIP.String(),comment, proxied)
app.Create(*rBody)
case "delete":
if name == "" {
@ -248,7 +253,7 @@ func (app *Application) Operation(op string, name, tipo, ipSTR string, proxied b
app.log.Error(fmt.Sprintf("could not find record: %s -> %s", name, dn), "operation", "overwrite")
} else {
rBody = app.GenerateReqBody(dn, tipo, app.publicIP.String(), proxied)
rBody = app.GenerateReqBody(dn, tipo, app.publicIP.String(), comment, proxied)
app.Overwrite(rs, rBody)
}
case "details":
@ -257,7 +262,7 @@ func (app *Application) Operation(op string, name, tipo, ipSTR string, proxied b
}
if rs != nil {
rBody = app.GenerateReqBody(dn, tipo, app.publicIP.String(), proxied)
rBody = app.GenerateReqBody(dn, tipo, app.publicIP.String(), comment, proxied)
app.Details(rs.ID)
}
@ -293,8 +298,9 @@ func (app *Application) SelectNameAndType(name, tipo string) (rec *cf.Result, er
}
}
func (app *Application) GenerateReqBody(name, tipo, ipSTR string, proxied bool) (rBody *cf.RequestBody) {
func (app *Application) GenerateReqBody(name, tipo, ipSTR, comment string, proxied bool) (rBody *cf.RequestBody) {
rBody = &cf.RequestBody{}
rBody.Comment = comment
rBody.DomainName = name
rBody.Type = tipo
rBody.Content = ipSTR