Skip to content

Commit

Permalink
Merge remote-tracking branch 'elastic/main' into release-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkroh committed Apr 2, 2024
2 parents 0483c3c + 69177af commit 8a75c03
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 29 deletions.
10 changes: 8 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ steps:
- label: "Publish PR Docker Image"
key: "publish-pr-img"
if: build.env("BUILDKITE_PULL_REQUEST") != "false"
command: ".buildkite/scripts/docker-build.sh ${DOCKER_IMG_PR}"
command:
- "sudo apt-get update"
- "sudo apt-get install -y qemu-user-static binfmt-support"
- ".buildkite/scripts/docker-build.sh ${DOCKER_IMG_PR}"
notify:
- github_commit_status:
context: "Publish PR Image"
Expand All @@ -66,7 +69,10 @@ steps:
- label: "Publish Docker Image"
key: "publish-nonpr-img"
if: build.env("BUILDKITE_PULL_REQUEST") == "false"
command: ".buildkite/scripts/docker-build.sh ${DOCKER_IMG}"
command:
- "sudo apt-get update"
- "sudo apt-get install -y qemu-user-static binfmt-support"
- ".buildkite/scripts/docker-build.sh ${DOCKER_IMG}"
notify:
- github_commit_status:
context: "Publish non-PR Image"
Expand Down
11 changes: 2 additions & 9 deletions .buildkite/scripts/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,5 @@ base_commit=$(get_base_commit)
commit_tag=$(docker_commit_tag "${docker_img}" "${base_commit}")
branch_tag=$(docker_branch_tag "${docker_img}" "${BUILDKITE_BRANCH}")

echo ":: Building image - ${commit_tag} ::"
build_image "${commit_tag}" "${base_commit}"

echo ":: Pushing image - ${commit_tag} ::"
retry 3 docker push "${commit_tag}"

echo ":: Re-tagging image from ${commit_tag} to ${branch_tag} ::"
retry 3 docker tag "${commit_tag}" "${branch_tag}"
retry 3 docker push "${branch_tag}"
echo ":: Building and pushing image - ${commit_tag} ::"
build_and_push_image "${base_commit}" -t "${commit_tag}" -t "${branch_tag}"
22 changes: 17 additions & 5 deletions .buildkite/scripts/image-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,30 @@ docker_branch_tag() {
branch_tag="${branch}"
fi

# Sanitize the branch name using parameter expansion.
# The tag must be valid ASCII and can contain lowercase and uppercase letters,
# digits, underscores, periods, and hyphens. It can't start with a period or
# hyphen and must be no longer than 128 characters.
branch_tag=${branch_tag//[^a-zA-Z0-9]/_}
branch_tag=${branch_tag:0:128}

echo "${image}:${branch_tag}"
}

build_image() {
local commit_tag=$1
local base_commit=$2
build_and_push_image() {
local base_commit=$1
shift
local extra_args=("$@")

docker build \
-t "${commit_tag}" \
docker buildx create --platform linux/amd64,linux/arm64 --use
docker buildx build \
--progress=plain \
--platform linux/amd64,linux/arm64 \
--push \
--label BRANCH_NAME="${BUILDKITE_BRANCH}" \
--label GIT_SHA="${base_commit}" \
--label GO_VERSION="${GOLANG_VERSION}" \
--label TIMESTAMP="$(date +%Y-%m-%d_%H:%M)" \
${extra_args[@]} \
.
}
3 changes: 1 addition & 2 deletions .buildkite/scripts/retag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ old_tag=$(docker_commit_tag "${docker_img}" "${base_commit}")
new_tag="${BUILDKITE_TAG}"

echo ":: Re-tagging image from ${old_tag} to ${new_tag} ::"
retry 3 docker tag "${old_tag}" "${new_tag}"
retry 3 docker push "${new_tag}"
retry 3 docker buildx imagetools create -t "${new_tag}" "${old_tag}"
3 changes: 3 additions & 0 deletions .changelog/88.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bugfix
pcap input: Check for nil packet and transport layer when streaming pcap files.
```
14 changes: 4 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
FROM golang:1.22.1 as builder
FROM golang:1.22.1-alpine3.19 as builder

RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y libpcap-dev \
&& rm -rf /var/lib/apt/lists/*
RUN apk add --no-cache musl-dev gcc libpcap libpcap-dev

ADD . /app

Expand All @@ -14,12 +11,9 @@ RUN go mod download
RUN go build

# ------------------------------------------------------------------------------
FROM debian:stable-slim
FROM alpine:3.19

RUN apt-get update \
&& apt-get dist-upgrade -y \
&& apt-get install -y libpcap0.8 \
&& rm -rf /var/lib/apt/lists/*
RUN apk add --no-cache libpcap

COPY --chown=0:0 --from=builder /app/stream /stream

Expand Down
13 changes: 12 additions & 1 deletion internal/command/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@ func (r *pcapRunner) sendPCAP(path string, out output.Output) error {
break
}

payloadData := packet.TransportLayer().LayerPayload()
if packet == nil {
logger.Warnw("Skipping nil packet")
continue
}

tl := packet.TransportLayer()
if tl == nil {
logger.Warnw("Skipping packet with no transport layer")
continue
}

payloadData := tl.LayerPayload()

// TODO: Rate-limit for UDP.
n, err := out.Write(payloadData)
Expand Down

0 comments on commit 8a75c03

Please sign in to comment.