-
Notifications
You must be signed in to change notification settings - Fork 155
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
feat: add helm package mage target #7232
Draft
pkoutsovasilis
wants to merge
11
commits into
elastic:main
Choose a base branch
from
pkoutsovasilis:feat/mage_helm_package
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+129
−8
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9094768
feat: add helm package mage target
pkoutsovasilis afa1caa
Merge remote-tracking branch 'upstream/main' into feat/mage_helm_package
v1v f1c97c8
create helm-chart and configure the oblt-gcp oidc thing
v1v c159278
combine and copy the generated file
v1v f92db32
use a script, create metadata and start with the triggering piece
v1v 7f81d30
test new plugin version
v1v 84e9b55
trigger publish with a dynamic pipeline
v1v 30e8941
join stages
v1v ef31de9
simplify and remove dependency with the buildkite-agent metadata
v1v 819480c
avoid double quote
v1v 260bfac
set toplevel env variable
v1v 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 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,13 +1,17 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json | ||
env: | ||
HELM_REPO_ENV: ${HELM_REPO_ENV:-dev} | ||
SNAPSHOT: ${SNAPSHOT:-true} | ||
|
||
steps: | ||
|
||
- label: ":elastic-stack: Create helm chart" | ||
command: | | ||
echo "TBC" | ||
|
||
- wait: ~ | ||
|
||
- label: ":elastic-stack: Publish helm chart" | ||
command: | | ||
echo "TBC" | ||
.buildkite/scripts/steps/helm-charts.sh | ||
plugins: | ||
- elastic/oblt-google-auth#feature/support-different-projects: | ||
lifetime: 1800 # seconds | ||
project-id: "elastic-observability-ci" | ||
project-number: "911195782929" | ||
agents: | ||
provider: "gcp" | ||
machineType: "n1-standard-8" |
This file contains 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,23 @@ | ||
#!/usr/bin/env bash | ||
# This script runs the helm-charts for the given environment | ||
# uploads the package to GCS and | ||
# triggers the unified-release-publish-helm-charts pipeline. | ||
|
||
# shellcheck disable=SC1091 | ||
source .buildkite/scripts/common.sh | ||
|
||
set -euo pipefail | ||
|
||
echo "--- mage helm:package" | ||
mage helm:package | ||
|
||
echo "--- upload package tests" | ||
STORAGE=elastic-agent-helm-chart | ||
gcloud storage cp elastic-agent-*.tgz gs://"${STORAGE}" --print-created-message | ||
|
||
echo "--- load trigger pipeline" | ||
HELM_CHART_FILE=$(ls -1 elastic-agent-*.tgz) | ||
CHART_URL="https://storage.googleapis.com/${STORAGE}/${HELM_CHART_FILE}" | ||
export CHART_URL | ||
.buildkite/scripts/steps/trigger-publish-helm-charts.sh | ||
.buildkite/scripts/steps/trigger-publish-helm-charts.sh | buildkite-agent pipeline upload |
This file contains 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,28 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Create a dynamic buildkite step that triggers the | ||
# unified-release-publish-helm-charts pipeline. | ||
# | ||
# Required environment variables: | ||
# - HELM_REPO_ENV | ||
# - CHART_URL | ||
# | ||
|
||
set -eo pipefail | ||
|
||
HELM_REPO_ENV=${HELM_REPO_ENV:-"dev"} | ||
|
||
if [ -z "$CHART_URL" ] ; then | ||
echo "CHART_URL could not be found." | ||
exit 1 | ||
fi | ||
|
||
cat << EOF | ||
- label: ":elastic-stack: Publish helm chart" | ||
trigger: unified-release-publish-helm-charts | ||
build: | ||
message: "publish helm-chart for elastic-agent in ${HELM_REPO_ENV}" | ||
env: | ||
CHARTS_URL: "${CHART_URL}" | ||
HELM_REPO_ENV: ${HELM_REPO_ENV} | ||
EOF |
This file contains 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 |
---|---|---|
|
@@ -3628,10 +3628,76 @@ func updateYamlFile(path string, keyVal ...struct { | |
return nil | ||
} | ||
|
||
// BuildDependencies builds the dependencies for the Elastic-Agent Helm chart. | ||
func (Helm) BuildDependencies() error { | ||
return helm.BuildChartDependencies(helmChartPath) | ||
} | ||
|
||
// Package packages the Elastic-Agent Helm chart. Note that you need to set SNAPSHOT="false" to build a production-ready package. | ||
func (h Helm) Package() error { | ||
mg.SerialDeps(h.BuildDependencies) | ||
|
||
agentVersion := bversion.GetParsedAgentPackageVersion() | ||
agentCoreVersion := agentVersion.CoreVersion() | ||
agentImageTag := agentCoreVersion + "-SNAPSHOT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for some reason
when using is that the expected behaviour? |
||
|
||
// need to explicitly set SNAPSHOT="false" to produce a production-ready package | ||
productionPackage := os.Getenv("SNAPSHOT") == "false" | ||
|
||
agentChartVersion := agentCoreVersion + "-beta" | ||
switch { | ||
case productionPackage && agentVersion.Major() >= 9: | ||
// for 9.0.0 and later versions, elastic-agent Helm chart is GA | ||
agentChartVersion = agentCoreVersion | ||
case productionPackage && agentVersion.Major() >= 8 && agentVersion.Minor() >= 18: | ||
// for 8.18.0 and later versions, elastic-agent Helm chart is GA | ||
agentChartVersion = agentCoreVersion | ||
} | ||
|
||
for yamlFile, keyVals := range map[string][]struct { | ||
key string | ||
value string | ||
}{ | ||
// values file for elastic-agent Helm Chart | ||
filepath.Join(helmChartPath, "values.yaml"): { | ||
{"agent.version", agentCoreVersion}, | ||
// always use the SNAPSHOT version for image tag | ||
// for the chart that resides in the git repo | ||
{"agent.image.tag", agentImageTag}, | ||
}, | ||
// Chart.yaml for elastic-agent Helm Chart | ||
filepath.Join(helmChartPath, "Chart.yaml"): { | ||
{"appVersion", agentCoreVersion}, | ||
{"version", agentChartVersion}, | ||
}, | ||
} { | ||
if err := updateYamlFile(yamlFile, keyVals...); err != nil { | ||
return fmt.Errorf("failed to update agent version: %w", err) | ||
} | ||
} | ||
|
||
// lint before packaging | ||
if err := h.Lint(); err != nil { | ||
return err | ||
} | ||
|
||
settings := cli.New() // Helm CLI settings | ||
actionConfig := &action.Configuration{} | ||
|
||
err := actionConfig.Init(settings.RESTClientGetter(), "default", "", | ||
func(format string, v ...interface{}) {}) | ||
if err != nil { | ||
return fmt.Errorf("failed to init helm action config: %w", err) | ||
} | ||
|
||
packageAction := action.NewPackage() | ||
_, err = packageAction.Run(helmChartPath, nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to package helm chart: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func updateYamlNodes(rootNode *yaml.Node, value string, keys ...string) error { | ||
if len(keys) == 0 { | ||
return fmt.Errorf("no keys provided") | ||
|
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.
See