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

ci: enable CD for commits to main #640

Merged
merged 1 commit into from
Apr 23, 2024
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
48 changes: 47 additions & 1 deletion .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,52 @@ volumes:
name: docker
---
depends_on:
- Publish development Linux alloy container
image_pull_secrets:
- dockerconfigjson
kind: pipeline
name: Deploy to deployment_tools
platform:
arch: amd64
os: linux
steps:
- commands:
- apk update && apk add git
- echo "$(sh ./tools/image-tag-docker)" > .tag-only
- echo "grafana/alloy-dev:$(sh ./tools/image-tag-docker)" > .image-tag
image: alpine
name: Create .image-tag
- image: us.gcr.io/kubernetes-dev/drone/plugins/updater
name: Update deployment_tools
settings:
config_json: |
{
"git_committer_name": "updater-for-ci[bot]",
"git_author_name": "updater-for-ci[bot]",
"git_committer_email": "119986603+updater-for-ci[bot]@users.noreply.github.com",
Copy link
Collaborator

Choose a reason for hiding this comment

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

any danger in exposing this?

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 doubt it, you still need the private key to be able to do anything and other teams have been using the same workflow with the same settings AFAIK (including grafana/agent).

"git_author_email": "119986603+updater-for-ci[bot]@users.noreply.github.com",
"destination_branch": "master",
"repo_name": "deployment_tools",
"update_jsonnet_attribute_configs": [
{
"file_path": "ksonnet/environments/grafana-agent/waves/alloy.libsonnet",
"jsonnet_key": "dev_canary",
"jsonnet_value_file": ".image-tag"
}
]
}
github_app_id:
from_secret: updater_app_id
github_app_installation_id:
from_secret: updater_app_installation_id
github_app_private_key:
from_secret: updater_private_key
trigger:
ref:
- refs/heads/main
type: docker
---
depends_on:
- Publish Linux alloy container
- Publish Windows alloy container
image_pull_secrets:
Expand Down Expand Up @@ -667,6 +713,6 @@ kind: secret
name: updater_private_key
---
kind: signature
hmac: 509bd7ed68a70f0e6930bd350dd71a7a3a48e199ac8e129b073ce32f08314c79
hmac: 478adbeda3c0ad620fbeb8eca6aa976709b6d9e71451644663a3c4362380df69

...
97 changes: 42 additions & 55 deletions .drone/pipelines/publish.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -174,63 +174,50 @@ local windows_containers_jobs = std.map(function(container) (

linux_containers_dev_jobs + windows_containers_dev_jobs +
linux_containers_jobs + windows_containers_jobs + [
// TODO(rfratto): Re-enable CD for development images.
/*
pipelines.linux('Deploy to deployment_tools') {
trigger: {
ref: ['refs/heads/main'],
pipelines.linux('Deploy to deployment_tools') {
trigger: {
ref: ['refs/heads/main'],
},
image_pull_secrets: ['dockerconfigjson'],
steps: [
{
name: 'Create .image-tag',
image: 'alpine',
commands: [
'apk update && apk add git',
'echo "$(sh ./tools/image-tag-docker)" > .tag-only',
'echo "grafana/alloy-dev:$(sh ./tools/image-tag-docker)" > .image-tag',
],
},
image_pull_secrets: ['dockerconfigjson'],
steps: [
{
name: 'Create .image-tag',
image: 'alpine',
commands: [
'apk update && apk add git',
'echo "$(sh ./tools/image-tag)" > .tag-only',
'echo "grafana/agent:$(sh ./tools/image-tag)" > .image-tag',
],
},
{
name: 'Update deployment_tools',
image: 'us.gcr.io/kubernetes-dev/drone/plugins/updater',
settings: {
config_json: |||
{
"git_committer_name": "updater-for-ci[bot]",
"git_author_name": "updater-for-ci[bot]",
"git_committer_email": "119986603+updater-for-ci[bot]@users.noreply.github.com",
"git_author_email": "119986603+updater-for-ci[bot]@users.noreply.github.com",
"destination_branch": "master",
"repo_name": "deployment_tools",
"update_jsonnet_attribute_configs": [
{
"file_path": "ksonnet/environments/kowalski/dev-us-central-0.kowalski-dev/main.jsonnet",
"jsonnet_key": "agent_image",
"jsonnet_value_file": ".image-tag"
},
{
"file_path": "ksonnet/environments/grafana-agent/waves/agent.libsonnet",
"jsonnet_key": "dev_canary",
"jsonnet_value_file": ".image-tag"
},
{
"file_path": "ksonnet/environments/pyroscope-ebpf/waves/ebpf.libsonnet",
"jsonnet_key": "dev_canary",
"jsonnet_value_file": ".image-tag"
}
]
}
|||,
github_app_id: secrets.updater_app_id.fromSecret,
github_app_installation_id: secrets.updater_app_installation_id.fromSecret,
github_app_private_key: secrets.updater_private_key.fromSecret,
},
{
name: 'Update deployment_tools',
image: 'us.gcr.io/kubernetes-dev/drone/plugins/updater',
settings: {
config_json: |||
{
"git_committer_name": "updater-for-ci[bot]",
"git_author_name": "updater-for-ci[bot]",
"git_committer_email": "119986603+updater-for-ci[bot]@users.noreply.github.com",
"git_author_email": "119986603+updater-for-ci[bot]@users.noreply.github.com",
"destination_branch": "master",
"repo_name": "deployment_tools",
"update_jsonnet_attribute_configs": [
{
"file_path": "ksonnet/environments/grafana-agent/waves/alloy.libsonnet",
"jsonnet_key": "dev_canary",
"jsonnet_value_file": ".image-tag"
}
]
}
|||,
github_app_id: secrets.updater_app_id.fromSecret,
github_app_installation_id: secrets.updater_app_installation_id.fromSecret,
github_app_private_key: secrets.updater_private_key.fromSecret,
},
],
depends_on: job_names(linux_containers_dev_jobs),
},
*/
},
],
depends_on: job_names(linux_containers_dev_jobs),
},

pipelines.linux('Publish release') {
trigger: {
Expand Down
6 changes: 2 additions & 4 deletions tools/ci/docker-containers
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ export DEVEL_ALLOY_IMAGE=grafana/alloy-dev
if [ -n "$DRONE_TAG" ]; then
VERSION=$DRONE_TAG
else
VERSION=$(./tools/image-tag)
VERSION=$(./tools/image-tag-docker)
fi

# The TAG_VERSION is the version to use for the Docker tag. It is sanitized to
# force it to be a valid tag name; ./tools/image-tag can emit characters that
# are valid for semver but invalid for Docker tags, such as +.
# The TAG_VERSION is the version to use for the Docker tag.
TAG_VERSION=${VERSION//+/-}

# We also need to know which "branch tag" to update. Branch tags are used as a
Expand Down
8 changes: 3 additions & 5 deletions tools/ci/docker-containers-windows
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ export DEVEL_ALLOY_IMAGE=grafana/alloy-dev
if [ -n "$DRONE_TAG" ]; then
VERSION=$DRONE_TAG
else
VERSION=$(./tools/image-tag)
VERSION=$(./tools/image-tag-docker)
fi

# The VERSION_TAG is the version to use for the Docker tag. It is sanitized to
# force it to be a valid tag name; ./tools/image-tag can emit characters that
# are valid for semver but invalid for Docker tags, such as +.
VERSION_TAG=${VERSION//+/-}-nanoserver-1809
# The VERSION_TAG is the version to use for the Docker tag.
VERSION_TAG=${VERSION}-nanoserver-1809

# We also need to know which "branch tag" to update. Branch tags are used as a
# secondary tag for Docker containers. The branch tag is "latest" when being
Expand Down
2 changes: 1 addition & 1 deletion tools/image-tag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
#
Copy link
Member Author

Choose a reason for hiding this comment

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

The automation for CD uses alpine which doesn't have Bash installed, and it has always used sh. To make sure we continue to support sh I'm explicitly setting it here.

# image-tag determines which version to embed into a built image.
#
Expand Down
7 changes: 7 additions & 0 deletions tools/image-tag-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
#
# image-tag-docker runs ./tools/image-tag but sanitizes invalid characters
# for use in Docker image tags.

TAG=$(sh ./tools/image-tag)
echo ${TAG//+/-}
Copy link
Member Author

Choose a reason for hiding this comment

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

This was being done in a few different places, but also it got complicated to do in the Drone config so I extracted it out to a new script to reduce how many times we have to copy the same sanitization replacement.

Loading