-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #239 Signed-off-by: Sergio Castaño Arteaga <[email protected]>
- Loading branch information
Showing
26 changed files
with
862 additions
and
236 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,41 @@ | ||
apiVersion: batch/v1beta1 | ||
kind: CronJob | ||
metadata: | ||
name: falco-tracker | ||
spec: | ||
schedule: "*/30 * * * *" | ||
successfulJobsHistoryLimit: 1 | ||
failedJobsHistoryLimit: 1 | ||
jobTemplate: | ||
spec: | ||
template: | ||
spec: | ||
{{- with .Values.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
restartPolicy: Never | ||
initContainers: | ||
- name: check-db-ready | ||
image: {{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }} | ||
imagePullPolicy: {{ .Values.pullPolicy }} | ||
resources: | ||
{{- toYaml .Values.falcoTracker.cronjob.resources | nindent 14 }} | ||
env: | ||
- name: PGHOST | ||
value: {{ .Values.db.host }} | ||
- name: PGPORT | ||
value: "{{ .Values.db.port }}" | ||
command: ['sh', '-c', 'until pg_isready; do echo waiting for database; sleep 2; done;'] | ||
containers: | ||
- name: falco-tracker | ||
image: {{ .Values.falcoTracker.cronjob.image.repository }}:{{ .Values.imageTag }} | ||
imagePullPolicy: {{ .Values.pullPolicy }} | ||
volumeMounts: | ||
- name: falco-tracker-config | ||
mountPath: "/home/falco-tracker/.cfg" | ||
readOnly: true | ||
volumes: | ||
- name: falco-tracker-config | ||
secret: | ||
secretName: falco-tracker-config |
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,21 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: falco-tracker-config | ||
type: Opaque | ||
stringData: | ||
falco-tracker.yaml: |- | ||
log: | ||
level: {{ .Values.log.level }} | ||
pretty: {{ .Values.log.pretty }} | ||
db: | ||
host: {{ .Values.db.host }} | ||
port: {{ .Values.db.port }} | ||
database: {{ .Values.db.database }} | ||
user: {{ .Values.db.user }} | ||
password: {{ .Values.db.password }} | ||
tracker: | ||
concurrency: {{ .Values.falcoTracker.concurrency }} | ||
repositoriesNames: {{ .Values.falcoTracker.repositories }} | ||
imageStore: {{ .Values.falcoTracker.imageStore }} | ||
bypassDigestCheck: {{ .Values.falcoTracker.bypassDigestCheck }} |
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
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,15 @@ | ||
# Build falco-tracker | ||
FROM golang:1.14-alpine AS builder | ||
WORKDIR /go/src/github.com/artifacthub/hub | ||
COPY go.* ./ | ||
COPY cmd/falco-tracker cmd/falco-tracker | ||
COPY internal internal | ||
RUN cd cmd/falco-tracker && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /falco-tracker . | ||
|
||
# Final stage | ||
FROM alpine:latest | ||
RUN apk --no-cache add ca-certificates && addgroup -S falco-tracker && adduser -S falco-tracker -G falco-tracker | ||
USER falco-tracker | ||
WORKDIR /home/falco-tracker | ||
COPY --from=builder /falco-tracker ./ | ||
CMD ["./falco-tracker"] |
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,78 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"sync" | ||
"syscall" | ||
|
||
"github.com/artifacthub/hub/internal/hub" | ||
"github.com/artifacthub/hub/internal/pkg" | ||
"github.com/artifacthub/hub/internal/repo" | ||
"github.com/artifacthub/hub/internal/tracker" | ||
"github.com/artifacthub/hub/internal/util" | ||
"github.com/rs/zerolog/log" | ||
"golang.org/x/time/rate" | ||
) | ||
|
||
func main() { | ||
// Setup configuration and logger | ||
cfg, err := util.SetupConfig("falco-tracker") | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("configuration setup failed") | ||
} | ||
fields := map[string]interface{}{ | ||
"cmd": "falco-tracker", | ||
} | ||
if err := util.SetupLogger(cfg, fields); err != nil { | ||
log.Fatal().Err(err).Msg("logger setup failed") | ||
} | ||
|
||
// Shutdown gracefully when SIGINT or SIGTERM signal is received | ||
log.Info().Int("pid", os.Getpid()).Msg("falco tracker started") | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
shutdown := make(chan os.Signal, 1) | ||
signal.Notify(shutdown, os.Interrupt, syscall.SIGTERM) | ||
go func() { | ||
<-shutdown | ||
cancel() | ||
log.Info().Msg("falco tracker shutting down..") | ||
}() | ||
|
||
// Setup internal services required | ||
db, err := util.SetupDB(cfg) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("database setup failed") | ||
} | ||
rm := repo.NewManager(db) | ||
pm := pkg.NewManager(db) | ||
is, err := util.SetupImageStore(cfg, db) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("image store setup failed") | ||
} | ||
|
||
// Track registered Falco repositories | ||
repos, err := tracker.GetRepositories(cfg, rm, hub.Falco) | ||
if err != nil { | ||
log.Fatal().Err(err).Send() | ||
} | ||
ec := tracker.NewDBErrorsCollector(ctx, rm, repos) | ||
concurrency := cfg.GetInt("tracker.concurrency") | ||
limiter := rate.NewLimiter(rate.Limit(concurrency), concurrency) | ||
var wg sync.WaitGroup | ||
for _, r := range repos { | ||
_ = limiter.Wait(ctx) | ||
wg.Add(1) | ||
w := NewTracker(ctx, cfg, r, rm, pm, is, ec) | ||
go func(r *hub.Repository) { | ||
if err := w.Track(&wg); err != nil { | ||
ec.Append(r.RepositoryID, err) | ||
w.Logger.Err(err).Send() | ||
} | ||
}(r) | ||
} | ||
wg.Wait() | ||
ec.Flush() | ||
log.Info().Msg("falco tracker finished") | ||
} |
Empty file.
Empty file.
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 @@ | ||
version: invalid |
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,12 @@ | ||
apiVersion: v1 | ||
kind: FalcoRules | ||
vendor: Sample provider | ||
name: test | ||
shortDescription: Short description | ||
version: 0.1.0 | ||
description: Description | ||
keywords: | ||
- kw1 | ||
- kw2 | ||
rules: | ||
- raw: Falco rules in YAML |
Oops, something went wrong.