Skip to content
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

WIP: E2e sink #84

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0a8b44d
Implement Send And Get Event APIs
muralov Sep 7, 2023
e8e8487
Build docker image with GithubAction
muralov Sep 8, 2023
5fd5a92
Don't trigger Lint and Validation for E2E Test Sink
muralov Sep 8, 2023
cc9fad0
Improve API Name and Makefile
muralov Sep 8, 2023
fd08ff2
Dummy commit to test GH Action Workflow
muralov Sep 8, 2023
65c1795
Test gh action workflow
muralov Sep 8, 2023
85bccf4
Test 2
muralov Sep 8, 2023
ad34127
Test 3
muralov Sep 8, 2023
a8ada48
Test 4
muralov Sep 8, 2023
71ba6dd
TEst 5
muralov Sep 8, 2023
02a1065
Test 6
muralov Sep 8, 2023
1065cf7
Test not relevant changes
muralov Sep 8, 2023
a64b138
Move working-directory
muralov Sep 8, 2023
6103350
test 7
muralov Sep 8, 2023
6bf5f23
Test 8
muralov Sep 8, 2023
4f73043
Improve GH Action
muralov Sep 8, 2023
7140264
Test 9
muralov Sep 8, 2023
ec3c4ec
Test 10
muralov Sep 8, 2023
9f2912d
Improve GH Action
muralov Sep 8, 2023
ed1ca0b
Improve GH Action
muralov Sep 8, 2023
1b3cd61
Improve GH Action 3
muralov Sep 8, 2023
bb54790
Test 11
muralov Sep 8, 2023
9383319
delete vs code files
muralov Sep 8, 2023
f2d952c
Test GH Action 4
muralov Sep 8, 2023
cfd5142
Rename E2E Test Sink image
muralov Sep 8, 2023
d3df5b4
Add workflow path and improve path
muralov Sep 8, 2023
ae8dd51
Change Image Name
muralov Sep 8, 2023
5e09418
dummy change to test image push
muralov Sep 8, 2023
7d5a30f
Test outside files change
muralov Sep 8, 2023
94b009a
set docker build working-directory
muralov Sep 8, 2023
54dbe1f
Build only sink docker image
muralov Sep 8, 2023
a9a387c
test image push by making true
muralov Sep 8, 2023
712343f
Revert changes
muralov Sep 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: golangci-lint
on: [pull_request]
on:
pull_request:
paths-ignore:
- 'e2e/sink/**'
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
Expand Down
72 changes: 69 additions & 3 deletions .github/workflows/sink.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,77 @@
name: E2E Tests Sink

on: [push]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: 'kyma-project/e2e-tests-sink'

on:
push:
branches:
- main
tags: [ '*.*.*' ]
paths:
- 'e2e/sink/**/*'
- .github/workflows/sink.yml
pull_request:
branches:
- main
paths:
- 'e2e/sink/**/*'
- .github/workflows/sink.yml

jobs:
build:
runs-on: ubuntu-latest
permissions: write-all

defaults:
run:
working-directory: e2e/sink

steps:
- name: Say Hello
run: echo "Hello, World!"
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19
cache: true

- name: Build
run: go build -v ./...

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=semver,pattern={{version}},event=tag

- name: Build Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: e2e/sink
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
load: ${{ github.event_name == 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 4 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ name: validate
on:
push:
branches: [ "main" ]
paths-ignore:
- 'e2e/sink/**'
pull_request:
branches: [ "main" ]
paths-ignore:
- 'e2e/sink/**'

jobs:
unit-tests:
Expand Down
4 changes: 4 additions & 0 deletions e2e/sink/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
testbin/
38 changes: 38 additions & 0 deletions e2e/sink/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin
testbin/*
Dockerfile.cross

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
.DS_Store
# vscode
*.code-workspace
.vscode/*

# Binaries
bin/*

# Vendor
vendor/

.env.dev
15 changes: 0 additions & 15 deletions e2e/sink/.vscode/launch.json

This file was deleted.

36 changes: 36 additions & 0 deletions e2e/sink/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Build the sink binary
FROM europe-docker.pkg.dev/kyma-project/prod/external/golang:1.21.0-alpine3.18 as builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY internal internal

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o sink cmd/main.go

# Use distroless as minimal base image to package the sink binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
LABEL source = [email protected]:kyma-project/eventing-manager.git

WORKDIR /
COPY --from=builder /workspace/sink .
USER nonroot:nonroot

ENTRYPOINT ["/sink"]
117 changes: 117 additions & 0 deletions e2e/sink/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

# Image URL to use all building/pushing image targets
IMG ?= sink:latest

# VERIFY_IGNORE is a grep pattern to exclude files and directories from verification
VERIFY_IGNORE := /vendor\|/automock

# FILES_TO_CHECK is a command used to determine which files should be verified
FILES_TO_CHECK = find . -type f -name "*.go" | grep -v "$(VERIFY_IGNORE)"
# DIRS_TO_CHECK is a command used to determine which directories should be verified
DIRS_TO_CHECK = go list ./... | grep -v "$(VERIFY_IGNORE)"
# DIRS_TO_IGNORE is a command used to determine which directories should not be verified
DIRS_TO_IGNORE = go list ./... | grep "$(VERIFY_IGNORE)"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


##@ Build

.PHONY: build
build: fmt vet
go build -o bin/sink cmd/main.go

.PHONY: run
run: fmt vet ## Run a sink from your host.
go run ./cmd/main.go

# If you wish built the sink image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: ## Build docker image with the sink.
docker build -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the sink.
docker push ${IMG}

# PLATFORMS defines the target platforms for the sink image be build to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
# To properly provided solutions that supports more than one platform you should use this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: ## Build and push docker image for the sink for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
- docker buildx rm project-v3-builder
rm Dockerfile.cross

##@ Deployment

ifndef ignore-not-found
ignore-not-found = false
endif

##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: fmt
fmt: ## Reformat files using `go fmt`
go fmt $$($(DIRS_TO_CHECK))

imports: ## Optimize imports
goimports -w -l $$($(FILES_TO_CHECK))

lint-thoroughly:
golangci-lint run

fmt-local: ## Reformat files using `go fmt`
go fmt $$($(DIRS_TO_CHECK))

imports-local: ## Optimize imports
goimports -w -l $$($(FILES_TO_CHECK))
20 changes: 20 additions & 0 deletions e2e/sink/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"github.com/kyma-project/eventing-manager/sink/internal/handler"
"go.uber.org/zap"
)

func main() {
logger, err := zap.NewProduction()
if err != nil {
panic(err)
}
defer logger.Sync()

sHandler := handler.NewSinkHandler(logger)
err = sHandler.Start()
if err != nil {
logger.Error("failed to start SinkHandler", zap.Error(err))
}
}
17 changes: 17 additions & 0 deletions e2e/sink/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/kyma-project/eventing-manager/sink

go 1.20

require (
github.com/cloudevents/sdk-go/v2 v2.14.0
github.com/gorilla/mux v1.8.0
go.uber.org/zap v1.10.0
)

require (
github.com/json-iterator/go v1.1.10 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
)
32 changes: 32 additions & 0 deletions e2e/sink/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
github.com/cloudevents/sdk-go/v2 v2.14.0 h1:Nrob4FwVgi5L4tV9lhjzZcjYqFVyJzsA56CwPaPfv6s=
github.com/cloudevents/sdk-go/v2 v2.14.0/go.mod h1:xDmKfzNjM8gBvjaF8ijFjM1VYOVUEeUfapHMUX1T5To=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Loading