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

Provide npcap distribution internally #148

Merged
merged 17 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Dockerfile
.status.*
*.bck
CHANGELOG.md
npcap/lib/*.exe
19 changes: 19 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pipeline {
withGithubNotify(context: "Build ${GO_FOLDER} ${MAKEFILE} ${PLATFORM}") {
deleteDir()
unstash 'source'
prepareNcap()
buildImages()
}
}
Expand All @@ -115,6 +116,7 @@ pipeline {
withGithubNotify(context: "Staging ${GO_FOLDER} ${MAKEFILE} ${PLATFORM}") {
// It will use the already cached docker images that were created in the
// Build stage. But it's required to retag them with the staging repo.
prepareNcap()
buildImages()
publishImages()
}
Expand Down Expand Up @@ -156,6 +158,23 @@ pipeline {
}
}

def prepareNcap() {
if (PLATFORM?.trim().equals('arm')) {
log(level: 'INFO', text: "prepareNcap is not supported for ${PLATFORM}")
return
}
log(level: 'INFO', text: "prepareNcap for ${PLATFORM}")
withGoEnv(){
withGCPEnv(secret: 'secret/observability-team/ci/elastic-observability-account-auth'){
dir("${env.BASE_DIR}"){
retryWithSleep(retries: 3, seconds: 15, backoff: true) {
sh "make copy-npcap"
}
}
}
}
}

def buildImages(){
log(level: 'INFO', text: "buildImages ${GO_FOLDER} with ${MAKEFILE} for ${PLATFORM}")
withGoEnv(){
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
include Makefile.common

TARGETS=go1.16 go1.17
ARM_TARGETS=go1.16 go1.17

# Requires login at google storage.
copy-npcap: status=".status.copy-npcap"
copy-npcap:
ifeq ($(CI),true)
@echo '0' > ${status}
$(foreach var,$(TARGETS), \
gsutil cp gs://obs-ci-cache/private/$(NPCAP_FILE) $(var)/npcap/lib/$(NPCAP_FILE) || echo '1' > ${status})
else
@echo 'Only available if running in the CI'
endif

build: status=".status.build"
build:
@echo '0' > ${status}
Expand Down
21 changes: 18 additions & 3 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@ VCS_REF := $(shell git rev-parse HEAD)
VCS_URL := https://github.com/elastic/golang-crossbuild
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
.DEFAULT_GOAL := build
NPCAP_VERSION := 1.60
# TODO: to be replaced once we validate it works as expected
#NPCAP_FILE := npcap-$(NPCAP_VERSION)-oem.exe
NPCAP_FILE := test.txt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO: to be replaced once we validate it works as expected
#NPCAP_FILE := npcap-$(NPCAP_VERSION)-oem.exe
NPCAP_FILE := test.txt
NPCAP_FILE := npcap-$(NPCAP_VERSION)-oem.exe

SUFFIX_NPCAP_VERSION := -npcap-$(NPCAP_VERSION)
NPCAP_REPOSITORY := docker.elastic.co/observability-ci

# Requires login at https://docker.elastic.co:7000/.
push:
echo ">> Pushing $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
@[ "$(SUFFIX)" = "$(SUFFIX_NPCAP_VERSION)" ] \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find the way to use ifeq with SUFFIX and SUFFIX_NPCAP_VERSION, even though these values were the same, but the ifeq returned false.

I guess, something should be related to where the SUFFIX is defined and the include function.

&& ( \
[ "$(REPOSITORY)" = "$(NPCAP_REPOSITORY)" ] \
&& $(MAKE) atomic-push \
|| echo "NOTE: $(SUFFIX) can only be published in $(NPCAP_REPOSITORY)" \
) \
|| $(MAKE) atomic-push

# Requires login at https://docker.elastic.co:7000/.
atomic-push:
@echo ">> Pushing $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
@docker push "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"

push-arm:
echo ">> Pushing $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
@echo ">> Pushing $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
@docker push "$(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"

.PHONY: push push-arm
9 changes: 9 additions & 0 deletions NPCAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# NPCAP

If you'd like to bump the npcap version please follow the below steps:

1) Update `NPCAP_VERSION` value in the `Makefile`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1) Update `NPCAP_VERSION` value in the `Makefile`.
1) Update `NPCAP_VERSION` value in the `Makefile.common`.

2) Download the new artifact.
3) Upload the artifact to `gs://obs-ci-cache/private`.

Credentials to the artifact service can be found in the APM-Shared folder in the password management tool.
2 changes: 1 addition & 1 deletion go1.16/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x npcap
ARM_IMAGES := base-arm

build:
Expand Down
8 changes: 7 additions & 1 deletion go1.16/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ include $(SELF_DIR)/../Makefile.common
NAME := golang-crossbuild
VERSION := 1.16.9
DEBIAN_VERSION ?= 9
SUFFIX := -$(shell basename $(CURDIR))
FOLDER := -$(shell basename $(CURDIR))
TAG_EXTENSION ?=

export DEBIAN_VERSION TAG_EXTENSION

ifeq ($(FOLDER),-npcap)
SUFFIX = $(SUFFIX_NPCAP_VERSION)
else
SUFFIX = $(FOLDER)
endif

build:
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
@go run $(SELF_DIR)/../template.go -t Dockerfile.tmpl -o Dockerfile
Expand Down
5 changes: 3 additions & 2 deletions go1.16/Makefile.debian10
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x darwin-arm64
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x darwin-arm64 npcap
DEBIAN_VERSION := 10
TAG_EXTENSION := -debian10
NPCAP_VERSION ?=

export DEBIAN_VERSION TAG_EXTENSION
export DEBIAN_VERSION NPCAP_VERSION TAG_EXTENSION

build:
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;)
Expand Down
5 changes: 3 additions & 2 deletions go1.16/Makefile.debian8
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
IMAGES := base main darwin
IMAGES := base main darwin npcap
DEBIAN_VERSION := 8
TAG_EXTENSION := -debian8
NPCAP_VERSION ?=

export DEBIAN_VERSION TAG_EXTENSION
export DEBIAN_VERSION NPCAP_VERSION TAG_EXTENSION

build:
export |grep TAG_EXTENSION
Expand Down
5 changes: 3 additions & 2 deletions go1.16/Makefile.debian9
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x npcap
ARM_IMAGES := base-arm
DEBIAN_VERSION := 9
TAG_EXTENSION := -debian9
NPCAP_VERSION ?=

export DEBIAN_VERSION TAG_EXTENSION
export DEBIAN_VERSION NPCAP_VERSION TAG_EXTENSION

build:
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;)
Expand Down
1 change: 1 addition & 0 deletions go1.16/npcap/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Makefile
17 changes: 17 additions & 0 deletions go1.16/npcap/Dockerfile.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG REPOSITORY
ARG VERSION
ARG TAG_EXTENSION=''
FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-main${TAG_EXTENSION}

COPY lib /installer

# Build-time metadata as defined at http://label-schema.org.
ARG BUILD_DATE
ARG IMAGE
ARG VCS_REF
ARG VCS_URL
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name=$IMAGE \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url=$VCS_URL \
org.label-schema.schema-version="1.0"
1 change: 1 addition & 0 deletions go1.16/npcap/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../Makefile.common
Empty file added go1.16/npcap/lib/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion go1.17/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x npcap
ARM_IMAGES := base-arm

build:
Expand Down
8 changes: 7 additions & 1 deletion go1.17/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ include $(SELF_DIR)/../Makefile.common
NAME := golang-crossbuild
VERSION := 1.17.6
DEBIAN_VERSION ?= 9
SUFFIX := -$(shell basename $(CURDIR))
FOLDER := -$(shell basename $(CURDIR))
TAG_EXTENSION ?=

export DEBIAN_VERSION TAG_EXTENSION

ifeq ($(FOLDER),-npcap)
SUFFIX = $(SUFFIX_NPCAP_VERSION)
else
SUFFIX = $(FOLDER)
endif

build:
@echo ">> Building $(REPOSITORY)/$(NAME):$(VERSION)$(SUFFIX)$(TAG_EXTENSION)"
@go run $(SELF_DIR)/../template.go -t Dockerfile.tmpl -o Dockerfile
Expand Down
5 changes: 3 additions & 2 deletions go1.17/Makefile.debian10
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x darwin-arm64
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x darwin-arm64 npcap
DEBIAN_VERSION := 10
TAG_EXTENSION := -debian10
NPCAP_VERSION ?=

export DEBIAN_VERSION TAG_EXTENSION
export DEBIAN_VERSION NPCAP_VERSION TAG_EXTENSION

build:
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;)
Expand Down
5 changes: 3 additions & 2 deletions go1.17/Makefile.debian8
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
IMAGES := base main darwin
IMAGES := base main darwin npcap
DEBIAN_VERSION := 8
TAG_EXTENSION := -debian8
NPCAP_VERSION ?=

export DEBIAN_VERSION TAG_EXTENSION
export DEBIAN_VERSION NPCAP_VERSION TAG_EXTENSION

build:
export |grep TAG_EXTENSION
Expand Down
5 changes: 3 additions & 2 deletions go1.17/Makefile.debian9
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x
IMAGES := base main darwin arm armhf armel mips mips32 ppc s390x npcap
ARM_IMAGES := base-arm
DEBIAN_VERSION := 9
TAG_EXTENSION := -debian9
NPCAP_VERSION ?=

export DEBIAN_VERSION TAG_EXTENSION
export DEBIAN_VERSION NPCAP_VERSION TAG_EXTENSION

build:
@$(foreach var,$(IMAGES),$(MAKE) -C $(var) build || exit 1;)
Expand Down
1 change: 1 addition & 0 deletions go1.17/npcap/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Makefile
17 changes: 17 additions & 0 deletions go1.17/npcap/Dockerfile.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARG REPOSITORY
ARG VERSION
ARG TAG_EXTENSION=''
FROM ${REPOSITORY}/golang-crossbuild:${VERSION}-main${TAG_EXTENSION}

COPY lib /installer

# Build-time metadata as defined at http://label-schema.org.
ARG BUILD_DATE
ARG IMAGE
ARG VCS_REF
ARG VCS_URL
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name=$IMAGE \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url=$VCS_URL \
org.label-schema.schema-version="1.0"
1 change: 1 addition & 0 deletions go1.17/npcap/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../Makefile.common
Empty file added go1.17/npcap/lib/.gitkeep
Empty file.