-
Notifications
You must be signed in to change notification settings - Fork 0
Add GitLab webhook support #56
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| name: Build and push Cauldron GitHub Consumer | ||
| name: GitHub Consumer (build-push) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
.github/workflows/build-push-cauldron-github-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
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 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 | ||
| platforms: linux/amd64 | ||
| push: true | ||
| provenance: false | ||
| tags: ghcr.io/${{ github.repository }}/cauldron-gitlab-consumer: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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| name: Build and push Cauldron Migrator | ||
| name: Migrator (build-push) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| name: Build and push Cauldron Webhook Server | ||
| name: Cauldron (build-push) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: Staging - GitLab 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 | ||
| platforms: linux/amd64 | ||
| push: true | ||
| provenance: false | ||
| tags: ghcr.io/${{ github.repository }}/cauldron-stg-gitlab-consumer: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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| name: Staging - Build and push Cauldron Migrator | ||
| name: Staging - Migrator (build-push) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
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
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 consumer cmd/gitlabconsumer/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/consumer /consumer | ||
|
|
||
| ENTRYPOINT ["/consumer"] | ||
|
|
||
| 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
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
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,101 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log" | ||
|
|
||
| "github.com/IBM/sarama" | ||
| "github.com/devchain-network/cauldron/internal/kafkacp" | ||
| "github.com/devchain-network/cauldron/internal/kafkacp/kafkaconsumer" | ||
| "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) kafkaconsumer.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. | ||
| func Run() error { | ||
| logLevel := getenv.String("LOG_LEVEL", slogger.DefaultLogLevel) | ||
| brokersList := getenv.String("KCP_BROKERS", kafkacp.DefaultKafkaBrokers) | ||
|
|
||
| kafkaTopic := getenv.String("KC_TOPIC_GITLAB", "") | ||
| kafkaPartition := getenv.Int("KC_PARTITION", kafkaconsumer.DefaultPartition) | ||
| kafkaDialTimeout := getenv.Duration("KC_DIAL_TIMEOUT", kafkaconsumer.DefaultDialTimeout) | ||
| kafkaReadTimeout := getenv.Duration("KC_READ_TIMEOUT", kafkaconsumer.DefaultReadTimeout) | ||
| kafkaWriteTimeout := getenv.Duration("KC_WRITE_TIMEOUT", kafkaconsumer.DefaultWriteTimeout) | ||
| kafkaBackoff := getenv.Duration("KC_BACKOFF", kafkaconsumer.DefaultBackoff) | ||
| kafkaMaxRetries := getenv.Int("KC_MAX_RETRIES", kafkaconsumer.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 := kafkaconsumer.New( | ||
| kafkaconsumer.WithLogger(logger), | ||
| kafkaconsumer.WithProcessMessageFunc(storeMessage(db)), | ||
| kafkaconsumer.WithKafkaBrokers(*brokersList), | ||
| kafkaconsumer.WithDialTimeout(*kafkaDialTimeout), | ||
| kafkaconsumer.WithReadTimeout(*kafkaReadTimeout), | ||
| kafkaconsumer.WithWriteTimeout(*kafkaWriteTimeout), | ||
| kafkaconsumer.WithBackoff(*kafkaBackoff), | ||
| kafkaconsumer.WithMaxRetries(*kafkaMaxRetries), | ||
| kafkaconsumer.WithTopic(*kafkaTopic), | ||
| kafkaconsumer.WithPartition(*kafkaPartition), | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf("gitlab kafka consumer instantiate error: [%w]", err) | ||
| } | ||
|
|
||
| defer func() { _ = kafkaGitLabConsumer.SaramaConsumer.Close() }() | ||
|
|
||
| if err = kafkaGitLabConsumer.Consume(); err != nil { | ||
| return fmt.Errorf("gitlab kafka consumer consume error: [%w]", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func main() { | ||
| if err := Run(); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } |
Oops, something went wrong.
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 unpinned base images
alpine:latestandbusybox:latest, which are mutable tags and introduce a supply-chain risk if the upstream images are compromised. Because the GitLab consumer container will be built and run with access to Kafka and database credentials, a malicious update to those tags could silently run attacker-controlled code inside your deployment. Pin these images to immutable digests or at least specific version tags to ensure you only run trusted image content.