Skip to content

Commit 22521be

Browse files
authored
Signing using Infra pipeline (#621)
* Signing using Infra pipeline * WIP * upload call download * Fixes * Fix: perms * Fix: build elastic-package * Fix: withMageEnv * Fix: typo * Fixes * fmt * Use buildTokenTrigger * Fixes * Fix * Fix * Fix * Fix * Fix: use map * Fix * Fix * Another bug * Fix * Missing env.REPO * Use triggerRemoteJob * Fix: make install * Fix: parameters * Fix: rename * Fix: path * Fix
1 parent 3e551ed commit 22521be

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

.ci/Jenkinsfile

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
pipeline {
66
agent { label 'ubuntu-18 && immutable' }
77
environment {
8+
REPO = "elastic-package"
9+
810
BASE_DIR="src/github.com/elastic/elastic-package"
911
JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba"
1012
GITHUB_TOKEN_CREDENTIALS = "2a9602aa-ab9f-4e52-baf3-b71ca88469c7"
@@ -16,6 +18,16 @@ pipeline {
1618
JOB_GCS_BUCKET = 'beats-ci-temp'
1719
JOB_GCS_CREDENTIALS = 'beats-ci-gcs-plugin'
1820
JOB_GCS_EXT_CREDENTIALS = 'beats-ci-gcs-plugin-file-credentials'
21+
JOB_SIGNING_CREDENTIALS = 'sign-artifacts-with-gpg-job'
22+
INTERNAL_CI_JOB_GCS_CREDENTIALS = 'internal-ci-gcs-plugin'
23+
24+
INFRA_SIGNING_BUCKET_NAME = 'internal-ci-artifacts'
25+
INFRA_SIGNING_BUCKET_ARTIFACTS_SUBFOLDER = "${env.REPO}/${env.BUILD_TAG}"
26+
INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_SUBFOLDER = "${env.INFRA_SIGNING_BUCKET_ARTIFACTS_SUBFOLDER}/signed-artifacts"
27+
INFRA_SIGNING_BUCKET_ARTIFACTS_PATH = "gs://${env.INFRA_SIGNING_BUCKET_NAME}/${env.INFRA_SIGNING_BUCKET_ARTIFACTS_SUBFOLDER}"
28+
INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_PATH = "gs://${env.INFRA_SIGNING_BUCKET_NAME}/${env.INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_SUBFOLDER}"
29+
30+
INTEGRATIONS_SIGNATURES_PATH = 'build/integrations-elastic-signatures' // different path not to override signatures archived in the "build-zip" step
1931
}
2032
options {
2133
timeout(time: 1, unit: 'HOURS')
@@ -74,9 +86,7 @@ pipeline {
7486
always {
7587
dir("${BASE_DIR}") {
7688
archiveArtifacts(allowEmptyArchive: true, artifacts: 'build/test-results/*.xml')
77-
junit(allowEmptyResults: false,
78-
keepLongStdio: true,
79-
testResults: "build/test-results/*.xml")
89+
junit(allowEmptyResults: false, keepLongStdio: true, testResults: "build/test-results/*.xml")
8090
stashCoverageReport()
8191
}
8292
}
@@ -99,7 +109,8 @@ pipeline {
99109
'check-packages-with-kind': generateTestCommandStage(command: 'test-check-packages-with-kind', artifacts: ['build/test-results/*.xml', 'build/kubectl-dump.txt', 'build/elastic-stack-dump/check-*/logs/*.log', 'build/elastic-stack-dump/check-*/logs/fleet-server-internal/*'], junitArtifacts: true, publishCoverage: true),
100110
'check-packages-other': generateTestCommandStage(command: 'test-check-packages-other', artifacts: ['build/test-results/*.xml', 'build/elastic-stack-dump/check-*/logs/*.log', 'build/elastic-stack-dump/check-*/logs/fleet-server-internal/*'], junitArtifacts: true, publishCoverage: true),
101111
'build-zip': generateTestCommandStage(command: 'test-build-zip', artifacts: ['build/elastic-stack-dump/build-zip/logs/*.log', 'build/integrations/*.sig']),
102-
'profiles-command': generateTestCommandStage(command: 'test-profiles-command')
112+
'profiles-command': generateTestCommandStage(command: 'test-profiles-command'),
113+
'sign-with-elastic': generateTestSignWithElasticStage()
103114
]
104115

105116
def checkSinglePackageTasks = generateTestCheckSinglePackageStage(artifacts: ['build/test-results/*.xml', 'build/elastic-stack-dump/check-*/logs/*.log', 'build/elastic-stack-dump/check-*/logs/fleet-server-internal/*'], junitArtifacts: true, publishCoverage: true)
@@ -144,6 +155,40 @@ def cleanup(){
144155
unstash 'source'
145156
}
146157

158+
def generateTestSignWithElasticStage() {
159+
return {
160+
withNode(labels: "ubuntu-20 && immutable", sleepMax: 20, forceWorkspace: true) {
161+
cleanup()
162+
dir("${BASE_DIR}"){
163+
withMageEnv(){
164+
sh(label: 'Install elastic-package',script: "make install")
165+
sh(label: 'Prepare for tests (build zipped packages)',script: "make build-unsigned-zip-for-tests")
166+
googleStorageUpload(bucket: env.INFRA_SIGNING_BUCKET_ARTIFACTS_PATH,
167+
credentialsId: env.INTERNAL_CI_JOB_GCS_CREDENTIALS,
168+
pathPrefix: 'build/integrations/',
169+
pattern: 'build/integrations/*.zip',
170+
sharedPublicly: false,
171+
showInline: true)
172+
withCredentials([string(credentialsId: env.JOB_SIGNING_CREDENTIALS, variable: 'TOKEN')]) {
173+
triggerRemoteJob(auth: CredentialsAuth(credentials: 'local-readonly-api-token'),
174+
job: 'https://internal-ci.elastic.co/job/elastic+unified-release+master+sign-artifacts-with-gpg',
175+
token: TOKEN,
176+
parameters: "gcs_input_path=${env.INFRA_SIGNING_BUCKET_ARTIFACTS_PATH}",
177+
useCrumbCache: true,
178+
useJobInfoCache: true)
179+
}
180+
googleStorageDownload(bucketUri: "${env.INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_PATH}/*",
181+
credentialsId: env.INTERNAL_CI_JOB_GCS_CREDENTIALS,
182+
localDirectory: "${env.INTEGRATIONS_SIGNATURES_PATH}/",
183+
pathPrefix: "${env.INFRA_SIGNING_BUCKET_SIGNED_ARTIFACTS_SUBFOLDER}")
184+
sh(label: 'Rename .asc to .sig', script: 'for f in ' + "${env.INTEGRATIONS_SIGNATURES_PATH}" + '/*.asc; do mv "$f" "${f%.asc}.sig"; done')
185+
archiveArtifacts(artifacts: "${env.INTEGRATIONS_SIGNATURES_PATH}/*.sig")
186+
}
187+
}
188+
}
189+
}
190+
}
191+
147192
def generateTestCheckSinglePackageStage(Map args = [:]) {
148193
def artifacts = args.get('artifacts') ? args.get('artifacts') : []
149194
def junitArtifacts = args.get('junitArtifacts') ? args.get('junitArtifacts') : false
@@ -293,4 +338,4 @@ def withCloudTestEnv(Closure body) {
293338
withEnvMask(vars: maskedVars) {
294339
body()
295340
}
296-
}
341+
}

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ test-profiles-command:
8686

8787
test: test-go test-stack-command test-check-packages test-profiles-command test-build-zip
8888

89+
build-unsigned-zip-for-tests:
90+
./scripts/build-unsigned-zip.sh
91+
8992
check-git-clean:
9093
git update-index --really-refresh
9194
git diff-index --quiet HEAD

scripts/build-unsigned-zip.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
OLDPWD=$PWD
6+
7+
# Build packages
8+
for d in test/packages/*/*/; do
9+
(
10+
cd $d
11+
elastic-package build --zip -v
12+
)
13+
done
14+
cd -

0 commit comments

Comments
 (0)