Skip to content

Commit 97bb5c0

Browse files
committed
Minor fixes
1 parent 2c0d178 commit 97bb5c0

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
FROM golang:1.22.2 AS builder
1+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.23.1 AS builder
22

33
COPY . /go/src/github.com/instabug/netbird-gitops/
44
WORKDIR /go/src/github.com/instabug/netbird-gitops/
55
RUN set -Eeux && \
66
go mod download && \
77
go mod verify
88

9-
RUN GOOS=linux GOARCH=amd64 \
10-
go build \
9+
ARG TARGETPLATFORM
10+
ARG BUILDPLATFORM
11+
ARG TARGETOS
12+
ARG TARGETARCH
13+
14+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
1115
-o app cmd/*
1216

13-
FROM alpine:3.17.1
17+
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.20.3
1418
RUN apk --no-cache add ca-certificates
1519
WORKDIR /root/
1620
COPY --from=builder /go/src/github.com/instabug/netbird-gitops/app .
1721

18-
EXPOSE 8123
19-
ENTRYPOINT ["./app"]
22+
ENTRYPOINT ["/root/app"]

cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/signal"
1010
"syscall"
11+
"time"
1112

1213
"github.com/Instabug/netbird-gitops/pkg/controller"
1314
"github.com/go-git/go-git/v5/plumbing/transport"
@@ -31,6 +32,7 @@ var (
3132
gitPassword = flag.String("git-password", os.Getenv("GIT_PASSWORD"), "git basic auth password, must be defined if --git-auth-method is basic")
3233
gitPrivateKeyPath = flag.String("git-private-key-path", os.Getenv("GIT_PRIVATE_KEY_PATH"), "git SSH private key path, must be defined if --git-auth-method is ssh")
3334
gitPrivateKeyPassword = flag.String("git-private-key-password", os.Getenv("GIT_PRIVATE_KEY_PASSWORD"), "git SSH private key password (if any)")
35+
syncFrequency = flag.Duration("sync-frequency", time.Minute, "Time between syncs")
3436
netbirdToken = flag.String("netbird-token", os.Getenv("NETBIRD_TOKEN"), "NetBird Management API token")
3537
netbirdManagementAPI = flag.String("netbird-mgmt-api", os.Getenv("NETBIRD_MANAGEMENT_API"), "NetBird Management API URL")
3638
logLevel = flag.String("log-level", os.Getenv("LOG_LEVEL"), "Log level (debug, info, warn, error)")

pkg/controller/controller.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/Instabug/netbird-gitops/pkg/client"
1414
"github.com/Instabug/netbird-gitops/pkg/data"
1515
"github.com/go-git/go-git/v5"
16+
"github.com/go-git/go-git/v5/plumbing"
1617
"github.com/go-git/go-git/v5/plumbing/transport"
1718
"github.com/nikoksr/notify"
1819
"gopkg.in/yaml.v3"
@@ -35,6 +36,7 @@ type Options struct {
3536
NetBirdToken string
3637
NetBirdAPI string
3738
SyncOnceAndExit bool
39+
PollFrequency time.Duration
3840
}
3941

4042
// NewController init
@@ -52,10 +54,11 @@ func (c *Controller) Start(ctx context.Context) error {
5254
slog.Info("Cloning repository")
5355
os.RemoveAll(localRepoPath)
5456
repo, err := git.PlainCloneContext(ctx, localRepoPath, false, &git.CloneOptions{
55-
URL: c.GitRepoURL,
56-
RemoteName: "origin",
57-
Auth: c.GitAuth,
58-
SingleBranch: true,
57+
URL: c.GitRepoURL,
58+
ReferenceName: plumbing.NewBranchReferenceName(c.GitBranch),
59+
RemoteName: "origin",
60+
Auth: c.GitAuth,
61+
SingleBranch: true,
5962
})
6063
if err != nil {
6164
return fmt.Errorf("Failed to initialize repo pull: %w", err)
@@ -99,10 +102,11 @@ func (c *Controller) Start(ctx context.Context) error {
99102
}
100103
slog.Info("Pulling changes")
101104
err = workTree.PullContext(ctx, &git.PullOptions{
102-
RemoteName: "origin",
103-
RemoteURL: c.GitRepoURL,
104-
Auth: c.GitAuth,
105-
SingleBranch: true,
105+
RemoteName: "origin",
106+
RemoteURL: c.GitRepoURL,
107+
ReferenceName: plumbing.NewBranchReferenceName(c.GitBranch),
108+
Auth: c.GitAuth,
109+
SingleBranch: true,
106110
})
107111
if err != nil && err != git.NoErrAlreadyUpToDate {
108112
slog.Error("Failed to pull repo", "err", err)

0 commit comments

Comments
 (0)