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

fix: prevent attempt of double publishing of cosign.pub #1635

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .ci/jenkins/tools/ko.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ void install() {
private def registrySecret(String registry) {
String path
switch (registry) {
case "DockerHub": path = "keptn-jenkins/monaco/dockerhub-deploy"
case "DT": path = "keptn-jenkins/monaco/registry-deploy"
default: path = "keptn-jenkins/monaco/registry-deploy"
case "DockerHub": path = "keptn-jenkins/monaco/dockerhub-deploy"; break
case "DT": path = "keptn-jenkins/monaco/registry-deploy"; break
default: path = "keptn-jenkins/monaco/registry-deploy"; break
}

return [[path : "${path}",
Expand All @@ -37,7 +37,7 @@ private def registrySecret(String registry) {

void loginToRegistry(Map args = [registry: null]) {
withVault(vaultSecrets: registrySecret(args.registry)) {
sh(label: "sign in to container registry",
sh(label: "sign in to ${args.registry} registry",
script: 'ko login --username=$username --password=$password $registry')
}
}
Expand Down
47 changes: 24 additions & 23 deletions .ci/releasePipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,7 @@ pipeline {
stage("Build binaries") {
def tasks = [:]

tasks["Docker container"] = {
stage("for testing") {
releaseDockerContainer(ctx, "DT")
}
if (isRelease(ctx)) {
stage ("for DockerHub") {
releaseDockerContainer(ctx, "DockerHub")
}
}
}
tasks["Docker container"] = { releaseDockerContainer(ctx) }

//linux
for (arch in ["amd64", "arm64", "386"]) {
Expand Down Expand Up @@ -189,23 +180,33 @@ void releaseBinary(Context ctx, Release release) {
}
}

void releaseDockerContainer(Context ctx, String registry) {
stage("Build Docker") {
def ko = load(".ci/jenkins/tools/ko.groovy")
ko.install()
void releaseDockerContainer(Context ctx) {
createAndPublishContainer(ctx, "DT")

if (isRelease(ctx)) {
createAndPublishContainer(ctx, "DockerHub")

def cosign = load(".ci/jenkins/tools/cosign.groovy")
cosign.install("latest")
ctx.githubRelease.addToRelease(rawData: cosign.getPublicKey(), underName: "cosign.pub")
}
}

List<String> tags = [ctx.version]
if (isFinal(ctx)) {
tags << "latest"
ctx.githubRelease.addToRelease(rawData: cosign.getPublicKey(), underName: "cosign.pub")
}
void createAndPublishContainer(Context ctx, String registry) {
def ko = load(".ci/jenkins/tools/ko.groovy")
ko.install()
def cosign = load(".ci/jenkins/tools/cosign.groovy")
cosign.install("latest")

ko.loginToRegistry(registry: registry)
image = ko.buildContainer(tags: tags, registry: registry)
cosign.sign(image)
List<String> tags = [ctx.version]
if (isFinal(ctx)) {
tags << "latest"
}

ko.loginToRegistry(registry: registry)
image = ko.buildContainer(tags: tags, registry: registry)
cosign.sign(image)

echo "Created docker image ${image}"
}

void signWinBinaries(Map args = [source: null, version: null, destDir: null, projectName: null]) {
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,3 @@ IMAGE_PATH ?= $(REPO_PATH)/$(CONTAINER_NAME)
docker-container: install-ko
@echo Building docker container...
KO_DOCKER_REPO=$(IMAGE_PATH) VERSION=$(VERSION) ko build --bare --sbom=none --tags=$(TAGS) ./cmd/monaco

sign-verify-image:
@go install github.com/sigstore/cosign/v2/cmd/[email protected]
COSIGN_PASSWORD=$(COSIGN_PASSWORD) cosign sign --key env://cosign_key $(FULL_IMAGE_NAME) -y
cosign verify --key env://cosign_pub $(FULL_IMAGE_NAME)
Loading