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

Improve e2e perf #1227

Merged
merged 18 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 17 additions & 1 deletion .github/workflows/pr-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
version: latest

- name: Save
env:
BUILD_TARGETS: "botkube-agent"
run: |
make save-images

Expand Down Expand Up @@ -98,6 +100,8 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push
env:
BUILD_TARGETS: "botkube-agent"
run: make load-and-push-images

- name: Delete Docker image artifact
Expand Down Expand Up @@ -237,12 +241,24 @@ jobs:
env:
# we hardcode plugins version, so it's predictable in e2e tests
GORELEASER_CURRENT_TAG: "v0.0.0-latest"
OUTPUT_MODE: "archive"
OUTPUT_MODE: "binary"
SINGLE_PLATFORM: "true"
PLUGIN_TARGETS: "kubernetes,kubectl,cm-watcher,echo,helm"
run: |
make build-plugins

- name: CLI Cache
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
dist/botkube-cli_linux_amd64_v1/botkube
key: ${{ runner.os }}-botkube-cli

- name: Build CLI
run: make release-snapshot-cli

- name: Add Botkube CLI to env
run: |
echo CONFIG_PROVIDER_BOTKUBE_CLI_BINARY_PATH="$PWD/dist/botkube-cli_linux_amd64_v1/botkube" >> $GITHUB_ENV
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ plugins-dev-index.yaml
plugins-index.yaml
CHANGELOG.md
botkube-agent
.goreleaser_temp.yaml
6 changes: 6 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ dockers:
build_flag_templates:
- "--platform=linux/amd64"
- "--build-arg=botkube_version={{ .Env.IMAGE_TAG }}"
id: botkube-agent-amd64
- image_templates:
- "{{.Env.IMAGE_REGISTRY}}/{{.Env.IMAGE_REPOSITORY}}:{{ .Env.IMAGE_TAG }}-arm64"
use: buildx
Expand All @@ -105,6 +106,7 @@ dockers:
build_flag_templates:
- "--platform=linux/arm64"
- "--build-arg=botkube_version={{ .Env.IMAGE_TAG }}"
id: botkube-agent-arm64
- image_templates:
- "{{.Env.IMAGE_REGISTRY}}/{{.Env.IMAGE_REPOSITORY}}:{{ .Env.IMAGE_TAG }}-armv7"
use: buildx
Expand All @@ -114,6 +116,7 @@ dockers:
build_flag_templates:
- "--platform=linux/arm"
- "--build-arg=botkube_version={{ .Env.IMAGE_TAG }}"
id: botkube-agent-armv7
# Config Exporter
- image_templates:
- "{{.Env.IMAGE_REGISTRY}}/{{.Env.CFG_EXPORTER_IMAGE_REPOSITORY}}:{{ .Env.IMAGE_TAG }}-amd64"
Expand All @@ -122,6 +125,7 @@ dockers:
build_flag_templates:
- "--platform=linux/amd64"
- "--build-arg=botkube_config_exporter_version={{ .Env.IMAGE_TAG }}"
id: botkube-config-exporter-amd64
- image_templates:
- "{{.Env.IMAGE_REGISTRY}}/{{.Env.CFG_EXPORTER_IMAGE_REPOSITORY}}:{{ .Env.IMAGE_TAG }}-arm64"
use: buildx
Expand All @@ -130,6 +134,7 @@ dockers:
build_flag_templates:
- "--platform=linux/arm64"
- "--build-arg=botkube_config_exporter_version={{ .Env.IMAGE_TAG }}"
id: botkube-config-exporter-arm64
- image_templates:
- "{{.Env.IMAGE_REGISTRY}}/{{.Env.CFG_EXPORTER_IMAGE_REPOSITORY}}:{{ .Env.IMAGE_TAG }}-armv7"
use: buildx
Expand All @@ -139,6 +144,7 @@ dockers:
build_flag_templates:
- "--platform=linux/arm"
- "--build-arg=botkube_config_exporter_version={{ .Env.IMAGE_TAG }}"
id: botkube-config-exporter-armv7
docker_manifests:
- name_template: "{{.Env.IMAGE_REGISTRY}}/{{.Env.IMAGE_REPOSITORY}}:{{ .Env.IMAGE_TAG }}"
image_templates:
Expand Down
146 changes: 112 additions & 34 deletions hack/goreleaser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,27 @@ save_images() {
fi

export GORELEASER_CURRENT_TAG=${IMAGE_TAG}
goreleaser release --clean --snapshot --skip-publish

GORELEASER_FILE="$(prepare_goreleaser)"
goreleaser release --clean --snapshot --skip-publish --config="${GORELEASER_FILE}"

mkdir -p "${IMAGE_SAVE_LOAD_DIR}"

# Save images
IMAGE_FILE_NAME_PREFIX=$(echo "${IMAGE_REPOSITORY}" | tr "/" "-")
docker save ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64 >${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-amd64.tar
docker save ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64 >${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-arm64.tar
docker save ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7 >${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-armv7.tar

CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX=$(echo "${CFG_EXPORTER_IMAGE_REPOSITORY}" | tr "/" "-")
docker save ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64 >${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-amd64.tar
docker save ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64 >${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-arm64.tar
docker save ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7 >${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-armv7.tar
if [[ -z "$BUILD_TARGETS" || ",$BUILD_TARGETS," == *",botkube-agent,"* ]]; then
IMAGE_FILE_NAME_PREFIX=$(echo "${IMAGE_REPOSITORY}" | tr "/" "-")
docker save ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64 >${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-amd64.tar
docker save ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64 >${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-arm64.tar
docker save ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7 >${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-armv7.tar
fi

if [[ -z "$BUILD_TARGETS" || ",$BUILD_TARGETS," == *",botkube-config-exporter,"* ]]; then
CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX=$(echo "${CFG_EXPORTER_IMAGE_REPOSITORY}" | tr "/" "-")
docker save ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64 >${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-amd64.tar
docker save ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64 >${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-arm64.tar
docker save ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7 >${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-armv7.tar
fi

}

load_and_push_images() {
Expand All @@ -84,37 +91,49 @@ load_and_push_images() {
export GORELEASER_CURRENT_TAG=${IMAGE_TAG}

# Load images
IMAGE_FILE_NAME_PREFIX=$(echo "${IMAGE_REPOSITORY}" | tr "/" "-")
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-amd64.tar
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-arm64.tar
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-armv7.tar
if [[ -z "$BUILD_TARGETS" || ",$BUILD_TARGETS," == *",botkube-agent,"* ]]; then
IMAGE_FILE_NAME_PREFIX=$(echo "${IMAGE_REPOSITORY}" | tr "/" "-")
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-amd64.tar
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-arm64.tar
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${IMAGE_FILE_NAME_PREFIX}-armv7.tar
fi

CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX=$(echo "${CFG_EXPORTER_IMAGE_REPOSITORY}" | tr "/" "-")
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-amd64.tar
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-arm64.tar
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-armv7.tar
if [[ -z "$BUILD_TARGETS" || ",$BUILD_TARGETS," == *",botkube-config-exporter,"* ]]; then
CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX=$(echo "${CFG_EXPORTER_IMAGE_REPOSITORY}" | tr "/" "-")
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-amd64.tar
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-arm64.tar
docker load --input ${IMAGE_SAVE_LOAD_DIR}/${CFG_EXPORTER_IMAGE_FILE_NAME_PREFIX}-armv7.tar
fi

# Push images
docker push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64
docker push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64
docker push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7
if [[ -z "$BUILD_TARGETS" || ",$BUILD_TARGETS," == *",botkube-agent,"* ]]; then
docker push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64
docker push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64
docker push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7
fi

docker push ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64
docker push ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64
docker push ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7
if [[ -z "$BUILD_TARGETS" || ",$BUILD_TARGETS," == *",botkube-config-exporter,"* ]]; then
docker push ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64
docker push ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64
docker push ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7
fi

# Create manifest
docker manifest create ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG} \
--amend ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64 \
--amend ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64 \
--amend ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7
docker manifest push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}
if [[ -z "$BUILD_TARGETS" || ",$BUILD_TARGETS," == *",botkube-agent,"* ]]; then
docker manifest create ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG} \
--amend ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64 \
--amend ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64 \
--amend ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7
docker manifest push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}
fi

docker manifest create ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG} \
--amend ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64 \
--amend ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64 \
--amend ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7
docker manifest push ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}
if [[ -z "$BUILD_TARGETS" || ",$BUILD_TARGETS," == *",botkube-config-exporter,"* ]]; then
docker manifest create ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG} \
--amend ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-amd64 \
--amend ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-arm64 \
--amend ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}-armv7
docker manifest push ${IMAGE_REGISTRY}/${CFG_EXPORTER_IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}
fi
}

build() {
Expand Down Expand Up @@ -152,6 +171,65 @@ build_plugins_single() {
eval "$command"
}

prepare_goreleaser() {
if [ -z "${BUILD_TARGETS}" ]; then
echo ".goreleaser.yml"
exit 0
fi

cp .goreleaser.yml .goreleaser_temp.yaml

# Filter the builds section
for build_id in $(yq e '.builds[].id' .goreleaser_temp.yaml); do
if [[ ! ",$BUILD_TARGETS," == *",$build_id,"* ]]; then
yq e "del(.builds[] | select(.id == \"$build_id\"))" -i .goreleaser_temp.yaml
fi
done

# Filter the dockers section
for docker_id in $(yq e '.dockers[].id' .goreleaser_temp.yaml); do
build_name=$(echo "$docker_id" | rev | cut -d'-' -f2- | rev)
if [[ ! ",$BUILD_TARGETS," == *",$build_name,"* ]]; then
yq e "del(.dockers[] | select(.id == \"$docker_id\"))" -i .goreleaser_temp.yaml
fi
done

# Filter the archives section
for archive_id in $(yq e '.archives[].id' .goreleaser_temp.yaml); do
if [[ ! ",$BUILD_TARGETS," == *",$archive_id,"* ]]; then
yq e "del(.archives[] | select(.id == \"$archive_id\"))" -i .goreleaser_temp.yaml
fi
done

# Filter the brews section
DEFAULT_BREW_NAME="botkube"
BOTKUBE_CLI_ID="botkube-cli"
if [[ ! ",$BUILD_TARGETS," == *",$BOTKUBE_CLI_ID,"* ]]; then
yq e "del(.brews[] | select(.name == \"$DEFAULT_BREW_NAME\"))" -i .goreleaser_temp.yaml
fi

if [[ "${SINGLE_PLATFORM}" == "true" ]]; then
CURRENT_OS=$(go env GOOS)
CURRENT_ARCH=$(go env GOARCH)

# Remove the goarm from the YAML file if it's not Darwin
if [ "$CURRENT_OS" != "darwin" ]; then
yq eval 'del(.builds[].goos[] | select(. == "darwin"))' .goreleaser_temp.yaml -i
yq eval 'del(.builds[].goarm)' .goreleaser_temp.yaml -i
fi

if [ -n "$CURRENT_OS" ]; then
yq eval "del(.builds[].goos[] | select(. == \"$CURRENT_OS\"))" .goreleaser_temp.yaml -i
fi

if [ -n "$CURRENT_ARCH" ]; then
yq eval "del(.builds[].goarch[] | select(. == \"$CURRENT_ARCH\"))" .goreleaser_temp.yaml -i
fi
fi

echo ".goreleaser_temp.yaml"
}

build_single() {
export IMAGE_TAG=v9.99.9-dev
docker run --rm --privileged \
Expand Down
Loading