CI: replace publish image step with a much simpler one that supports LATEST (#90498)

* replace publish image step with a much simpler one that supports LATEST
This commit is contained in:
Kevin Minehart
2024-07-18 10:53:47 -05:00
committed by GitHub
parent a43a538976
commit 6a2a6b0fbc
3 changed files with 212 additions and 36 deletions
+93 -24
View File
@@ -10,31 +10,80 @@ load(
"identify_runner_step",
"publish_images_step",
)
load(
"scripts/drone/utils/images.star",
"images",
)
load(
"scripts/drone/utils/utils.star",
"pipeline",
)
load(
"scripts/drone/vault.star",
"from_secret",
)
def publish_image_steps(docker_repo):
"""Generates the steps used for publising Docker images using grabpl.
Args:
docker_repo: the Docker image name.
It is combined with the 'grafana/' library prefix.
def publish_image_public_step():
"""Returns a step which publishes images
Returns:
List of Drone steps.
A drone step which publishes Docker images for a public release.
"""
steps = [
identify_runner_step(),
download_grabpl_step(),
compile_build_cmd(),
fetch_images_step(),
publish_images_step("release", docker_repo),
publish_images_step("release", "grafana-oss"),
]
command = """
debug=
if [[ -n $${DRY_RUN} ]]; then debug=echo; fi
docker login -u $${DOCKER_USER} -p $${DOCKER_PASSWORD}
return steps
# Push the grafana-image-tags images
$debug docker push grafana/grafana-image-tags:$${TAG}-amd64
$debug docker push grafana/grafana-image-tags:$${TAG}-arm64
$debug docker push grafana/grafana-image-tags:$${TAG}-armv7
$debug docker push grafana/grafana-image-tags:$${TAG}-ubuntu-amd64
$debug docker push grafana/grafana-image-tags:$${TAG}-ubuntu-arm64
$debug docker push grafana/grafana-image-tags:$${TAG}-ubuntu-armv7
# Create the grafana manifests
$debug docker manifest create grafana/grafana:${TAG} \
grafana/grafana-image-tags:$${TAG}-amd64 \
grafana/grafana-image-tags:$${TAG}-arm64 \
grafana/grafana-image-tags:$${TAG}-armv7
$debug docker manifest create grafana/grafana:${TAG}-ubuntu \
grafana/grafana-image-tags:$${TAG}-ubuntu-amd64 \
grafana/grafana-image-tags:$${TAG}-ubuntu-arm64 \
grafana/grafana-image-tags:$${TAG}-ubuntu-armv7
# Push the grafana manifests
$debug docker manifest push grafana/grafana:$${TAG}
$debug docker manifest push grafana/grafana:$${TAG}-ubuntu
# if LATEST is set, then also create & push latest
if [[ -n $${LATEST} ]]; then
$debug docker manifest create grafana/grafana:latest \
grafana/grafana-image-tags:$${TAG}-amd64 \
grafana/grafana-image-tags:$${TAG}-arm64 \
grafana/grafana-image-tags:$${TAG}-armv7
$debug docker manifest create grafana/grafana:latest-ubuntu \
grafana/grafana-image-tags:$${TAG}-ubuntu-amd64 \
grafana/grafana-image-tags:$${TAG}-ubuntu-arm64 \
grafana/grafana-image-tags:$${TAG}-ubuntu-armv7
$debug docker manifest push grafana/grafana:latest
$debug docker manifest push grafana/grafana:latest-ubuntu
fi
"""
return {
"environment": {
"DOCKER_USER": from_secret("docker_username"),
"DOCKER_PASSWORD": from_secret("docker_password"),
},
"name": "publish-images-grafana",
"image": images["docker"],
"depends_on": ["fetch-images"],
"commands": [command],
"volumes": [{"name": "docker", "path": "/var/run/docker.sock"}],
}
def publish_image_pipelines_public():
"""Generates the pipeline used for publising public Docker images.
@@ -42,16 +91,36 @@ def publish_image_pipelines_public():
Returns:
Drone pipeline
"""
mode = "public"
trigger = {
"event": ["promote"],
"target": [mode],
}
return [
pipeline(
name = "publish-docker-{}".format(mode),
trigger = trigger,
steps = publish_image_steps(docker_repo = "grafana"),
name = "publish-docker-public",
trigger = {
"event": ["promote"],
"target": ["public"],
},
steps = [
identify_runner_step(),
download_grabpl_step(),
compile_build_cmd(),
fetch_images_step(),
publish_image_public_step(),
publish_images_step("release", "grafana-oss"),
],
environment = {"EDITION": "oss"},
),
pipeline(
name = "manually-publish-docker-public",
trigger = {
"event": ["promote"],
"target": ["publish-docker-public"],
},
steps = [
identify_runner_step(),
download_grabpl_step(),
compile_build_cmd(),
fetch_images_step(),
publish_image_public_step(),
],
environment = {"EDITION": "oss"},
),
]
+1
View File
@@ -9,6 +9,7 @@ load(
)
images = {
"docker": "docker:27-cli",
"git": "alpine/git:2.40.1",
"go": "golang:{}-alpine".format(golang_version),
"node": "node:{}-alpine".format(nodejs_version),