Skip to content

Commit b57ff02

Browse files
authored
common as default deployment size for artifactory (#3557)
1 parent c00f517 commit b57ff02

5 files changed

Lines changed: 92 additions & 44 deletions

File tree

.jfrog-pipelines/pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pipelines:
7777
description: "Forward Artifactory logs from the deployed ephemeral environment to Kibana (via Coralogix). Maps to the LOGS_TO_KIBANA parameter of the environment_setup_gen2 Jenkins job. Set 'false' to disable."
7878
allowCustom: true
7979
DEPLOYMENT_SIZING:
80-
default: "large"
80+
default: "common"
8181
description: "Artifactory deployment sizing profile."
8282
allowCustom: true
8383
MAX_RUN_RETRIES:

lifecycle_test.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func TestReleaseBundleCreationFromMultipleBuildsAndBundlesUsingCommandFlags(t *t
155155
func TestReleaseBundleCreationFromMultiBundlesUsingCommandFlagWithProject(t *testing.T) {
156156
cleanCallback := initLifecycleTest(t, minMultiSourcesArtifactoryVersion)
157157
defer cleanCallback()
158-
deleteProject := createTestProject(t)
158+
deleteProject := createTestProject(t, tests.ProjectKey2)
159159
if deleteProject != nil {
160160
defer func() {
161161
if err := deleteProject(); err != nil {
@@ -169,32 +169,32 @@ func TestReleaseBundleCreationFromMultiBundlesUsingCommandFlagWithProject(t *tes
169169
defer deleteBuilds()
170170

171171
// Create first release bundle from builds with project
172-
createRbWithFlags(t, "", "", tests.LcBuildName1, number1, tests.LcRbName1, number1, tests.ProjectKey, true, true, false)
173-
defer deleteReleaseBundleWithProject(t, lcManager, tests.LcRbName1, number1, tests.ProjectKey)
174-
assertStatusCompletedWithProject(t, lcManager, tests.LcRbName1, number1, "", tests.ProjectKey)
172+
createRbWithFlags(t, "", "", tests.LcBuildName1, number1, tests.LcRbName1, number1, tests.ProjectKey2, true, true, false)
173+
defer deleteReleaseBundleWithProject(t, lcManager, tests.LcRbName1, number1, tests.ProjectKey2)
174+
assertStatusCompletedWithProject(t, lcManager, tests.LcRbName1, number1, "", tests.ProjectKey2)
175175

176176
// Verify first release bundle exists with project
177-
isExist, err := lcManager.IsReleaseBundleExist(tests.LcRbName1, number1, tests.ProjectKey)
177+
isExist, err := lcManager.IsReleaseBundleExist(tests.LcRbName1, number1, tests.ProjectKey2)
178178
assert.NoError(t, err)
179-
assert.True(t, isExist, "Release bundle %s/%s should exist in project %s", tests.LcRbName1, number1, tests.ProjectKey)
179+
assert.True(t, isExist, "Release bundle %s/%s should exist in project %s", tests.LcRbName1, number1, tests.ProjectKey2)
180180

181181
// Create second release bundle from builds with project
182-
createRbWithFlags(t, "", "", tests.LcBuildName2, number2, tests.LcRbName2, number2, tests.ProjectKey, true, true, false)
183-
defer deleteReleaseBundleWithProject(t, lcManager, tests.LcRbName2, number2, tests.ProjectKey)
184-
assertStatusCompletedWithProject(t, lcManager, tests.LcRbName2, number2, "", tests.ProjectKey)
182+
createRbWithFlags(t, "", "", tests.LcBuildName2, number2, tests.LcRbName2, number2, tests.ProjectKey2, true, true, false)
183+
defer deleteReleaseBundleWithProject(t, lcManager, tests.LcRbName2, number2, tests.ProjectKey2)
184+
assertStatusCompletedWithProject(t, lcManager, tests.LcRbName2, number2, "", tests.ProjectKey2)
185185

186186
// Verify second release bundle exists with project
187-
isExist, err = lcManager.IsReleaseBundleExist(tests.LcRbName2, number2, tests.ProjectKey)
187+
isExist, err = lcManager.IsReleaseBundleExist(tests.LcRbName2, number2, tests.ProjectKey2)
188188
assert.NoError(t, err)
189-
assert.True(t, isExist, "Release bundle %s/%s should exist in project %s", tests.LcRbName2, number2, tests.ProjectKey)
189+
assert.True(t, isExist, "Release bundle %s/%s should exist in project %s", tests.LcRbName2, number2, tests.ProjectKey2)
190190

191191
// Wait a bit to ensure release bundles are fully indexed before using them as sources
192192
time.Sleep(5 * time.Second)
193193

194194
// Create release bundle from the two previous release bundles with project
195-
createRbFromMultiSourcesUsingCommandFlagsWithProject(t, lcManager, "", createReleaseBundlesSource(), tests.LcRbName3, number3, tests.ProjectKey, true)
196-
defer deleteReleaseBundleWithProject(t, lcManager, tests.LcRbName3, number3, tests.ProjectKey)
197-
assertStatusCompletedWithProject(t, lcManager, tests.LcRbName3, number3, "", tests.ProjectKey)
195+
createRbFromMultiSourcesUsingCommandFlagsWithProject(t, lcManager, "", createReleaseBundlesSource(), tests.LcRbName3, number3, tests.ProjectKey2, true)
196+
defer deleteReleaseBundleWithProject(t, lcManager, tests.LcRbName3, number3, tests.ProjectKey2)
197+
assertStatusCompletedWithProject(t, lcManager, tests.LcRbName3, number3, "", tests.ProjectKey2)
198198
}
199199

200200
func TestReleaseBundleCreationFromMultipleSourcesUsingSpec(t *testing.T) {
@@ -667,9 +667,9 @@ func uploadBuilds(t *testing.T) func() {
667667
}
668668

669669
func uploadBuildsWithProject(t *testing.T) func() {
670-
uploadBuildWithArtifactsAndProject(t, tests.UploadDevSpecA, tests.LcBuildName1, number1, tests.ProjectKey)
671-
uploadBuildWithArtifactsAndProject(t, tests.UploadDevSpecB, tests.LcBuildName2, number2, tests.ProjectKey)
672-
uploadBuildWithDepsAndProject(t, tests.LcBuildName3, number3, tests.ProjectKey)
670+
uploadBuildWithArtifactsAndProject(t, tests.UploadDevSpecA, tests.LcBuildName1, number1, tests.ProjectKey2)
671+
uploadBuildWithArtifactsAndProject(t, tests.UploadDevSpecB, tests.LcBuildName2, number2, tests.ProjectKey2)
672+
uploadBuildWithDepsAndProject(t, tests.LcBuildName3, number3, tests.ProjectKey2)
673673
return func() {
674674
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.LcBuildName1, artHttpDetails)
675675
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.LcBuildName2, artHttpDetails)
@@ -716,7 +716,7 @@ func TestCreateBundleWithoutSpec(t *testing.T) {
716716
func TestCreateBundleWithoutSpecAndWithProject(t *testing.T) {
717717
cleanCallback := initLifecycleTest(t, signingKeyOptionalArtifactoryMinVersion)
718718
defer cleanCallback()
719-
deleteProject := createTestProject(t)
719+
deleteProject := createTestProject(t, tests.ProjectKey2)
720720
if deleteProject != nil {
721721
defer func() {
722722
if err := deleteProject(); err != nil {
@@ -728,9 +728,9 @@ func TestCreateBundleWithoutSpecAndWithProject(t *testing.T) {
728728
deleteBuilds := uploadBuildsWithProject(t)
729729
defer deleteBuilds()
730730

731-
createRbWithFlags(t, "", "", tests.LcBuildName1, number1, tests.LcRbName1, number1, tests.ProjectKey, false, false, false)
732-
assertStatusCompletedWithProject(t, lcManager, tests.LcRbName1, number1, "", tests.ProjectKey)
733-
defer deleteReleaseBundleWithProject(t, lcManager, tests.LcRbName1, number1, tests.ProjectKey)
731+
createRbWithFlags(t, "", "", tests.LcBuildName1, number1, tests.LcRbName1, number1, tests.ProjectKey2, false, false, false)
732+
assertStatusCompletedWithProject(t, lcManager, tests.LcRbName1, number1, "", tests.ProjectKey2)
733+
defer deleteReleaseBundleWithProject(t, lcManager, tests.LcRbName1, number1, tests.ProjectKey2)
734734
}
735735

736736
func createRbWithFlags(t *testing.T, specFilePath, sourceOption, buildName, buildNumber, rbName, rbVersion, project string,
@@ -1416,7 +1416,7 @@ func TestReleaseBundlesSearchVersions(t *testing.T) {
14161416
projectVersionB := "1.0.1"
14171417

14181418
// Setup: Create test project and upload builds with project
1419-
deleteProject := createTestProject(t)
1419+
deleteProject := createTestProject(t, tests.ProjectKey2)
14201420
if deleteProject != nil {
14211421
defer func() {
14221422
if err := deleteProject(); err != nil {
@@ -1430,13 +1430,13 @@ func TestReleaseBundlesSearchVersions(t *testing.T) {
14301430

14311431
// Delete existing release bundle versions with project
14321432
for _, version := range []string{projectVersionA, projectVersionB} {
1433-
isExist, err := lcManager.IsReleaseBundleExist(projectRbName, version, tests.ProjectKey)
1433+
isExist, err := lcManager.IsReleaseBundleExist(projectRbName, version, tests.ProjectKey2)
14341434
if err == nil && isExist {
14351435
rbDetails := services.ReleaseBundleDetails{
14361436
ReleaseBundleName: projectRbName,
14371437
ReleaseBundleVersion: version,
14381438
}
1439-
err := lcManager.DeleteReleaseBundleVersion(rbDetails, services.CommonOptionalQueryParams{Async: false, ProjectKey: tests.ProjectKey})
1439+
err := lcManager.DeleteReleaseBundleVersion(rbDetails, services.CommonOptionalQueryParams{Async: false, ProjectKey: tests.ProjectKey2})
14401440
if err != nil {
14411441
if !strings.Contains(err.Error(), "404") && !strings.Contains(err.Error(), "not found") {
14421442
t.Logf("Warning: Failed to delete release bundle %s/%s: %v", projectRbName, version, err)
@@ -1448,15 +1448,15 @@ func TestReleaseBundlesSearchVersions(t *testing.T) {
14481448
}
14491449

14501450
// Create release bundles with project
1451-
createRbWithFlags(t, "", "", tests.LcBuildName1, number1, projectRbName, projectVersionA, tests.ProjectKey, true, false, false)
1452-
defer deleteReleaseBundleWithProject(t, lcManager, projectRbName, projectVersionA, tests.ProjectKey)
1453-
assertStatusCompletedWithProject(t, lcManager, projectRbName, projectVersionA, "", tests.ProjectKey)
1451+
createRbWithFlags(t, "", "", tests.LcBuildName1, number1, projectRbName, projectVersionA, tests.ProjectKey2, true, false, false)
1452+
defer deleteReleaseBundleWithProject(t, lcManager, projectRbName, projectVersionA, tests.ProjectKey2)
1453+
assertStatusCompletedWithProject(t, lcManager, projectRbName, projectVersionA, "", tests.ProjectKey2)
14541454

14551455
time.Sleep(1 * time.Second)
14561456

1457-
createRbWithFlags(t, "", "", tests.LcBuildName2, number2, projectRbName, projectVersionB, tests.ProjectKey, true, false, false)
1458-
defer deleteReleaseBundleWithProject(t, lcManager, projectRbName, projectVersionB, tests.ProjectKey)
1459-
assertStatusCompletedWithProject(t, lcManager, projectRbName, projectVersionB, "", tests.ProjectKey)
1457+
createRbWithFlags(t, "", "", tests.LcBuildName2, number2, projectRbName, projectVersionB, tests.ProjectKey2, true, false, false)
1458+
defer deleteReleaseBundleWithProject(t, lcManager, projectRbName, projectVersionB, tests.ProjectKey2)
1459+
assertStatusCompletedWithProject(t, lcManager, projectRbName, projectVersionB, "", tests.ProjectKey2)
14601460

14611461
log.Info("Created two versions for release bundle '%s' with project for search testing.", projectRbName)
14621462
time.Sleep(3 * time.Second)
@@ -1474,7 +1474,7 @@ func TestReleaseBundlesSearchVersions(t *testing.T) {
14741474
name: "Search with project",
14751475
releaseBundleName: projectRbName,
14761476
queryParams: services.GetSearchOptionalQueryParams{
1477-
Project: tests.ProjectKey,
1477+
Project: tests.ProjectKey2,
14781478
},
14791479
expectedRbVersions: []string{projectVersionA, projectVersionB},
14801480
expectedTotal: 2,

transfer_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func TestTransferConfigMerge(t *testing.T) {
422422
// The module type only exist in Artifactory 7
423423
if projectsSupported {
424424
// Create project on Source server
425-
deleteProject := createTestProject(t)
425+
deleteProject := createTestProject(t, tests.ProjectKey)
426426
if deleteProject != nil {
427427
defer func() {
428428
assert.NoError(t, deleteProject())
@@ -537,11 +537,11 @@ func validateCsvConflicts(t *testing.T, csvPath string, projectsSupported bool)
537537
}
538538
}
539539

540-
func createTestProject(t *testing.T) func() error {
540+
func createTestProject(t *testing.T, projectKey string) func() error {
541541
accessManager, err := rtUtils.CreateAccessServiceManager(serverDetails, false)
542542
assert.NoError(t, err)
543543
// Delete the project if already exists
544-
deleteProjectIfExists(t, accessManager, tests.ProjectKey)
544+
deleteProjectIfExists(t, accessManager, projectKey)
545545

546546
// Create new project
547547
adminPrivileges := accessServices.AdminPrivileges{
@@ -550,17 +550,17 @@ func createTestProject(t *testing.T) func() error {
550550
IndexResources: utils.Pointer(false),
551551
}
552552
projectDetails := accessServices.Project{
553-
DisplayName: tests.ProjectKey + "MyProject",
553+
DisplayName: projectKey + "MyProject",
554554
Description: "My Test Project",
555555
AdminPrivileges: &adminPrivileges,
556556
SoftLimit: utils.Pointer(false),
557557
StorageQuotaBytes: 1073741825,
558-
ProjectKey: tests.ProjectKey,
558+
ProjectKey: projectKey,
559559
}
560560

561561
if assert.NoError(t, accessManager.CreateProject(accessServices.ProjectParams{ProjectDetails: projectDetails})) {
562562
return func() error {
563-
return accessManager.DeleteProject(tests.ProjectKey)
563+
return accessManager.DeleteProject(projectKey)
564564
}
565565
}
566566
return nil

utils/tests/consts.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ var (
284284
Password1 = "A12356789z"
285285
UserName2 = "bob"
286286
// jfrog-ignore - not a real password
287-
Password2 = "1B234578y9"
288-
ProjectKey = "prj"
287+
Password2 = "1B234578y9"
288+
ProjectKey = "prj"
289+
ProjectKey2 = "prjlc"
289290
)
290291

291292
func GetTxtUploadExpectedRepo1() []string {

utils/tests/utils.go

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ var (
8888
timestampAdded bool
8989
)
9090

91+
// nonProjectKeyCharsRegex matches any character that isn't allowed in an Artifactory
92+
// project key (project keys allow only lowercase alphanumeric characters and hyphens).
93+
// We use this to sanitize the --ci.runId value before splicing it into resource names
94+
// whose format is constrained (project keys, GPG keypair names, etc.). Project-key
95+
// charset is a strict subset of the GPG keypair charset, so a single sanitization is
96+
// safe for both.
97+
var nonProjectKeyCharsRegex = regexp.MustCompile(`[^a-z0-9-]+`)
98+
99+
// SanitizedCiRunId returns the --ci.runId flag value lowercased with any characters
100+
// outside [a-z0-9-] collapsed to a single hyphen and surrounding hyphens trimmed.
101+
// Returns "" if the flag wasn't set. Callers that need a per-runId suffix on
102+
// resources whose name format is constrained (e.g. Artifactory project keys, GPG
103+
// keypair names) should use this so concurrent runs against a shared JPD don't
104+
// clobber each other.
105+
func SanitizedCiRunId() string {
106+
if ciRunId == nil || *ciRunId == "" {
107+
return ""
108+
}
109+
sanitized := nonProjectKeyCharsRegex.ReplaceAllString(strings.ToLower(*ciRunId), "-")
110+
return strings.Trim(sanitized, "-")
111+
}
112+
91113
func init() {
92114
JfrogUrl = flag.String("jfrog.url", "http://localhost:8081/", "JFrog platform url")
93115
JfrogUser = flag.String("jfrog.user", "admin", "JFrog platform username")
@@ -114,8 +136,8 @@ func init() {
114136
TestPip = flag.Bool("test.pip", false, "Test Pip")
115137
TestPipenv = flag.Bool("test.pipenv", false, "Test Pipenv")
116138
TestPoetry = flag.Bool("test.poetry", false, "Test Poetry")
117-
TestUv = flag.Bool("test.uv", false, "Test UV")
118-
TestNix = flag.Bool("test.nix", false, "Test Nix")
139+
TestUv = flag.Bool("test.uv", false, "Test UV")
140+
TestNix = flag.Bool("test.nix", false, "Test Nix")
119141
TestConan = flag.Bool("test.conan", false, "Test Conan")
120142
TestHelm = flag.Bool("test.helm", false, "Test Helm")
121143
TestHuggingFace = flag.Bool("test.huggingface", false, "Test HuggingFace")
@@ -645,12 +667,37 @@ func AddTimestampToGlobalVars() {
645667
Password1 += uniqueSuffix + strconv.FormatFloat(randomSequence.Float64(), 'f', 2, 32)
646668
Password2 += uniqueSuffix + strconv.FormatFloat(randomSequence.Float64(), 'f', 2, 32)
647669

648-
// Projects
649-
ProjectKey += timestamp[len(timestamp)-7:]
670+
// Projects. The artifactory and lifecycle suites use distinct base keys
671+
// (ProjectKey vs LcProjectKey) so neither can delete the other's project
672+
// when run concurrently against a shared JPD.
673+
ProjectKey = appendProjectKeySuffix(ProjectKey, timestamp)
674+
ProjectKey2 = appendProjectKeySuffix(ProjectKey2, timestamp)
650675

651676
timestampAdded = true
652677
}
653678

679+
// appendProjectKeySuffix appends a per-run suffix to an Artifactory project-key
680+
// base. Project keys must be 2-32 chars, lowercase alphanumeric or hyphen, and
681+
// start with a letter. We always include the sanitized --ci.runId (when set) so
682+
// that concurrent runs against a shared JPD don't clobber each other's project —
683+
// createTestProject calls deleteProjectIfExists(<key>) unconditionally, so a
684+
// colliding key from another concurrent suite would silently delete the project
685+
// (and every release bundle inside it) out from under us.
686+
func appendProjectKeySuffix(base, timestamp string) string {
687+
suffix := timestamp[len(timestamp)-7:]
688+
if sanitizedRunId := SanitizedCiRunId(); sanitizedRunId != "" {
689+
suffix = sanitizedRunId + "-" + suffix
690+
}
691+
// The total must be <= 32. Trim from the front so the trailing timestamp
692+
// (used for visual debuggability) is preserved and we don't end up with a
693+
// key that starts with a hyphen.
694+
const maxProjectKeyLen = 32
695+
if maxSuffixLen := maxProjectKeyLen - len(base); len(suffix) > maxSuffixLen {
696+
suffix = strings.TrimLeft(suffix[len(suffix)-maxSuffixLen:], "-")
697+
}
698+
return base + suffix
699+
}
700+
654701
// Replace all variables in the form of ${VARIABLE} in the input file, according to the substitution map (see getSubstitutionMap()).
655702
// path - Path to the input file.
656703
// destPath - Path to the output file. If empty, the output file will be under ${CWD}/tmp/.

0 commit comments

Comments
 (0)