-
Notifications
You must be signed in to change notification settings - Fork 0
Add GitLab consumer group support #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
.github/workflows/build-push-cauldron-gitlab-group-consumer.yml
This file contains hidden or 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,33 @@ | ||
| name: GitLab Group Consumer (build-push) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-image: | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and push to GitHub Container Registry | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: Dockerfile.gitlab-consumer-group | ||
| platforms: linux/amd64 | ||
| push: true | ||
| provenance: false | ||
| tags: ghcr.io/${{ github.repository }}/cauldron-gitlab-consumer-group:latest | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max |
This file contains hidden or 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,33 @@ | ||
| name: Staging - GitLab Group Consumer (build-push) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-image: | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and push to GitHub Container Registry | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: Dockerfile.gitlab-consumer-group | ||
| platforms: linux/amd64 | ||
| push: true | ||
| provenance: false | ||
| tags: ghcr.io/${{ github.repository }}/cauldron-stg-gitlab-consumer-group:latest | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max |
This file contains hidden or 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,31 @@ | ||
| FROM golang:1.25-alpine AS builder | ||
|
|
||
| WORKDIR /build | ||
| COPY . . | ||
|
|
||
| ARG GOOS | ||
| ARG GOARCH | ||
| RUN CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o consumergroup cmd/gitlabconsumergroup/main.go | ||
|
|
||
| FROM alpine:latest AS certs | ||
| RUN apk add --update --no-cache ca-certificates | ||
|
|
||
| FROM busybox:latest | ||
| ARG UID=10001 | ||
| RUN adduser \ | ||
| --disabled-password \ | ||
| --gecos "" \ | ||
| --home "/nonexistent" \ | ||
| --shell "/sbin/nologin" \ | ||
| --no-create-home \ | ||
| --uid "${UID}" \ | ||
| appuser | ||
| USER appuser | ||
| COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
| COPY --from=builder /build/consumergroup /consumergroup | ||
|
|
||
| ENTRYPOINT ["/consumergroup"] | ||
|
|
||
| LABEL org.opencontainers.image.authors="Uğur vigo Özyılmazel <vigo@devchain.network>" | ||
| LABEL org.opencontainers.image.licenses="MIT" | ||
| LABEL org.opencontainers.image.source="https://github.com/devchain-network/cauldron" | ||
This file contains hidden or 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,100 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log" | ||
|
|
||
| "github.com/IBM/sarama" | ||
| "github.com/devchain-network/cauldron/internal/kafkacp" | ||
| "github.com/devchain-network/cauldron/internal/kafkacp/kafkaconsumergroup" | ||
| "github.com/devchain-network/cauldron/internal/slogger" | ||
| "github.com/devchain-network/cauldron/internal/storage" | ||
| "github.com/devchain-network/cauldron/internal/storage/gitlabstorage" | ||
| "github.com/vigo/getenv" | ||
| ) | ||
|
|
||
| func storeMessage(strg storage.PingStorer) kafkaconsumergroup.ProcessMessageFunc { | ||
| return func(ctx context.Context, msg *sarama.ConsumerMessage) error { | ||
| if err := strg.MessageStore(ctx, msg); err != nil { | ||
| return fmt.Errorf("message store error: [%w]", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // Run runs kafka gitlab consumer group. | ||
| func Run() error { | ||
| logLevel := getenv.String("LOG_LEVEL", slogger.DefaultLogLevel) | ||
| brokersList := getenv.String("KCP_BROKERS", kafkacp.DefaultKafkaBrokers) | ||
| kafkaTopic := getenv.String("KC_TOPIC_GITLAB", "") | ||
| kafkaConsumerGroup := getenv.String("KCG_NAME", "") | ||
| kafkaDialTimeout := getenv.Duration("KC_DIAL_TIMEOUT", kafkaconsumergroup.DefaultDialTimeout) | ||
| kafkaReadTimeout := getenv.Duration("KC_READ_TIMEOUT", kafkaconsumergroup.DefaultReadTimeout) | ||
| kafkaWriteTimeout := getenv.Duration("KC_WRITE_TIMEOUT", kafkaconsumergroup.DefaultWriteTimeout) | ||
| kafkaBackoff := getenv.Duration("KC_BACKOFF", kafkaconsumergroup.DefaultBackoff) | ||
| kafkaMaxRetries := getenv.Int("KC_MAX_RETRIES", kafkaconsumergroup.DefaultMaxRetries) | ||
| databaseURL := getenv.String("DATABASE_URL", "") | ||
|
|
||
| if err := getenv.Parse(); err != nil { | ||
| return fmt.Errorf("environment variable parse error: [%w]", err) | ||
| } | ||
|
|
||
| logger, err := slogger.New( | ||
| slogger.WithLogLevelName(*logLevel), | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf("logger instantiate error: [%w]", err) | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), storage.DefaultDBPingTimeout) | ||
| defer cancel() | ||
|
|
||
| db, err := gitlabstorage.New( | ||
| ctx, | ||
| gitlabstorage.WithDatabaseDSN(*databaseURL), | ||
| gitlabstorage.WithLogger(logger), | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf("gitlab storage instantiate error: [%w]", err) | ||
| } | ||
|
|
||
| if err = db.Ping(ctx, storage.DefaultDBPingMaxRetries, storage.DefaultDBPingBackoff); err != nil { | ||
| return fmt.Errorf("gitlab storage ping error: [%w]", err) | ||
| } | ||
| defer func() { | ||
| logger.Info("gitlab storage - closing pgx pool") | ||
| db.Pool.Close() | ||
| }() | ||
|
|
||
| kafkaGitLabConsumer, err := kafkaconsumergroup.New( | ||
| kafkaconsumergroup.WithLogger(logger), | ||
| kafkaconsumergroup.WithProcessMessageFunc(storeMessage(db)), | ||
| kafkaconsumergroup.WithKafkaBrokers(*brokersList), | ||
| kafkaconsumergroup.WithDialTimeout(*kafkaDialTimeout), | ||
| kafkaconsumergroup.WithReadTimeout(*kafkaReadTimeout), | ||
| kafkaconsumergroup.WithWriteTimeout(*kafkaWriteTimeout), | ||
| kafkaconsumergroup.WithBackoff(*kafkaBackoff), | ||
| kafkaconsumergroup.WithMaxRetries(*kafkaMaxRetries), | ||
| kafkaconsumergroup.WithTopic(*kafkaTopic), | ||
| kafkaconsumergroup.WithKafkaGroupName(*kafkaConsumerGroup), | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf("gitlab kafka group consumer instantiate error: [%w]", err) | ||
| } | ||
|
|
||
| defer func() { _ = kafkaGitLabConsumer.SaramaConsumerGroup.Close() }() | ||
|
|
||
| if err = kafkaGitLabConsumer.StartConsume(); err != nil { | ||
| return fmt.Errorf("gitlab kafka group consumer start consume error: [%w]", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func main() { | ||
| if err := Run(); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Dockerfile uses mutable base image tags
alpine:latestandbusybox:latest, which are susceptible to supply chain attacks because the image contents can change over time without any change on your side. If either upstream image is compromised, future builds or deployments of this consumer group could silently pull a malicious image with access to your runtime environment and secrets. To mitigate this, pin these images to immutable, specific versions or digests (e.g.,alpine:3.19andbusybox:1.36or corresponding SHA digests) and update them intentionally as part of your dependency management process.