Skip to content

Commit 095de77

Browse files
authored
feat(engine): add release action for artifactory (#5849)
1 parent 12a4efb commit 095de77

File tree

18 files changed

+636
-56
lines changed

18 files changed

+636
-56
lines changed

cli/cdsctl/workflow_artifact.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ var workflowArtifactDownloadCmd = cli.Command{
9797
Usage: "exclude files from download - could be a regex: *.log",
9898
Default: "",
9999
},
100+
{
101+
Name: "cdn-url",
102+
Usage: "overwrite cdn url",
103+
Default: "",
104+
},
100105
},
101106
}
102107

@@ -106,10 +111,15 @@ func workflowArtifactDownloadRun(v cli.Values) error {
106111
return cli.NewError("number parameter have to be an integer")
107112
}
108113

109-
confCDN, err := client.ConfigCDN()
110-
if err != nil {
111-
return err
114+
cdnURL := v.GetString("cdn-url")
115+
if cdnURL == "" {
116+
confCDN, err := client.ConfigCDN()
117+
if err != nil {
118+
return err
119+
}
120+
cdnURL = confCDN.HTTPURL
112121
}
122+
113123
ok, err := downloadFromCDSAPI(v, number)
114124
if err != nil {
115125
return err
@@ -176,7 +186,7 @@ func workflowArtifactDownloadRun(v cli.Values) error {
176186
return err
177187
}
178188
fmt.Printf("Downloading %s...\n", artifactData.Name)
179-
r, err := client.CDNItemDownload(context.Background(), confCDN.HTTPURL, artifactData.CDNRefHash, sdk.CDNTypeItemRunResult)
189+
r, err := client.CDNItemDownload(context.Background(), cdnURL, artifactData.CDNRefHash, sdk.CDNTypeItemRunResult)
180190
if err != nil {
181191
return err
182192
}

contrib/integrations/artifactory/artifactory.go

+19
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/url"
7+
"strings"
78
"time"
89

910
"github.com/jfrog/jfrog-client-go/artifactory"
1011
"github.com/jfrog/jfrog-client-go/artifactory/auth"
1112
"github.com/jfrog/jfrog-client-go/artifactory/services"
1213
"github.com/jfrog/jfrog-client-go/config"
14+
"github.com/jfrog/jfrog-client-go/distribution"
15+
authdistrib "github.com/jfrog/jfrog-client-go/distribution/auth"
16+
1317

1418
"github.com/ovh/cds/sdk"
1519
)
@@ -43,6 +47,21 @@ type FileChildren struct {
4347
Folder bool `json:"folder"`
4448
}
4549

50+
func CreateDistributionClient(url, token string) (*distribution.DistributionServicesManager, error) {
51+
dtb := authdistrib.NewDistributionDetails()
52+
dtb.SetUrl(strings.Replace(url, "/artifactory/", "/distribution/", -1))
53+
dtb.SetAccessToken(token)
54+
serviceConfig, err := config.NewConfigBuilder().
55+
SetServiceDetails(dtb).
56+
SetThreads(1).
57+
SetDryRun(false).
58+
Build()
59+
if err != nil {
60+
return nil, fmt.Errorf("unable to create service config: %v", err)
61+
}
62+
return distribution.New(serviceConfig)
63+
}
64+
4665
func CreateArtifactoryClient(url, token string) (artifactory.ArtifactoryServicesManager, error) {
4766
rtDetails := auth.NewArtifactoryDetails()
4867
rtDetails.SetUrl(url)

contrib/integrations/artifactory/plugin-artifactory-build-info/main.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type executionContext struct {
5050
workflowName string
5151
version string
5252
lowMaturitySuffix string
53-
cdsRepo string
5453
}
5554

5655
func (e *artifactoryBuildInfoPlugin) Manifest(_ context.Context, _ *empty.Empty) (*integrationplugin.IntegrationPluginManifest, error) {
@@ -67,7 +66,6 @@ func (e *artifactoryBuildInfoPlugin) Run(_ context.Context, opts *integrationplu
6766
token := opts.GetOptions()[fmt.Sprintf("cds.integration.artifact_manager.%s", sdk.ArtifactManagerConfigToken)]
6867
tokenName := opts.GetOptions()[fmt.Sprintf("cds.integration.artifact_manager.%s", sdk.ArtifactManagerConfigTokenName)]
6968
lowMaturitySuffix := opts.GetOptions()[fmt.Sprintf("cds.integration.artifact_manager.%s", sdk.ArtifactManagerConfigPromotionLowMaturity)]
70-
cdsRepo := opts.GetOptions()[fmt.Sprintf("cds.integration.artifact_manager.%s", sdk.ArtifactManagerConfigCdsRepository)]
7169

7270
buildInfo := opts.GetOptions()[fmt.Sprintf("cds.integration.artifact_manager.%s", sdk.ArtifactManagerConfigBuildInfoPath)]
7371
version := opts.GetOptions()["cds.version"]
@@ -117,7 +115,6 @@ func (e *artifactoryBuildInfoPlugin) Run(_ context.Context, opts *integrationplu
117115
workflowName: workflowName,
118116
version: version,
119117
projectKey: projectKey,
120-
cdsRepo: cdsRepo,
121118
}
122119
modules, err := e.computeBuildInfoModules(artiClient, execContext)
123120
if err != nil {
@@ -195,9 +192,7 @@ func (e *artifactoryBuildInfoPlugin) retrieveModulesArtifacts(client artifactory
195192
props["build.number"] = execContext.version
196193
props["build.timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
197194
repoSrc := repoName
198-
if repoName != execContext.cdsRepo {
199-
repoSrc += "-" + execContext.lowMaturitySuffix
200-
}
195+
repoSrc += "-" + execContext.lowMaturitySuffix
201196
if err := art.SetProperties(client, repoSrc, path, props); err != nil {
202197
return nil, err
203198
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.PHONY: clean
2+
3+
VERSION := $(if ${CDS_SEMVER},${CDS_SEMVER},snapshot)
4+
GITHASH := $(if ${GIT_HASH},${GIT_HASH},`git log -1 --format="%H"`)
5+
BUILDTIME := `date "+%m/%d/%y-%H:%M:%S"`
6+
CDSCTL := $(if ${CDSCTL},${CDSCTL},cdsctl)
7+
8+
TARGET_DIR = ./dist
9+
TARGET_NAME = plugin-artifactory-release
10+
11+
define PLUGIN_MANIFEST_BINARY
12+
os: %os%
13+
arch: %arch%
14+
cmd: ./%filename%
15+
endef
16+
export PLUGIN_MANIFEST_BINARY
17+
18+
TARGET_LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION) -X github.com/ovh/cds/sdk.GOOS=$$GOOS -X github.com/ovh/cds/sdk.GOARCH=$$GOARCH -X github.com/ovh/cds/sdk.GITHASH=$(GITHASH) -X github.com/ovh/cds/sdk.BUILDTIME=$(BUILDTIME) -X github.com/ovh/cds/sdk.BINARY=$(TARGET_NAME)"
19+
TARGET_OS = $(if ${OS},${OS},windows darwin linux freebsd)
20+
TARGET_ARCH = $(if ${ARCH},${ARCH},amd64 arm 386 arm64)
21+
22+
GO_BUILD = go build
23+
24+
$(TARGET_DIR):
25+
$(info create $(TARGET_DIR) directory)
26+
@mkdir -p $(TARGET_DIR)
27+
28+
default: build
29+
30+
clean:
31+
@rm -rf $(TARGET_DIR)
32+
33+
build: $(TARGET_DIR)
34+
@cp $(TARGET_NAME).yml $(TARGET_DIR)/$(TARGET_NAME).yml
35+
@for GOOS in $(TARGET_OS); do \
36+
for GOARCH in $(TARGET_ARCH); do \
37+
EXTENSION=""; \
38+
if test "$$GOOS" = "windows" ; then EXTENSION=".exe"; fi; \
39+
echo Compiling $(TARGET_DIR)/$(TARGET_NAME)-$$GOOS-$$GOARCH$$EXTENSION $(VERSION); \
40+
FILENAME=$(TARGET_NAME)-$$GOOS-$$GOARCH$$EXTENSION; \
41+
GOOS=$$GOOS GOARCH=$$GOARCH CGO_ENABLED=0 $(GO_BUILD) $(TARGET_LDFLAGS) -o $(TARGET_DIR)/$$FILENAME; \
42+
echo "$$PLUGIN_MANIFEST_BINARY" > $(TARGET_DIR)/plugin-artifactory-release-$$GOOS-$$GOARCH.yml; \
43+
perl -pi -e s,%os%,$$GOOS,g $(TARGET_DIR)/plugin-artifactory-release-$$GOOS-$$GOARCH.yml; \
44+
perl -pi -e s,%arch%,$$GOARCH,g $(TARGET_DIR)/plugin-artifactory-release-$$GOOS-$$GOARCH.yml; \
45+
perl -pi -e s,%filename%,$$FILENAME,g $(TARGET_DIR)/plugin-artifactory-release-$$GOOS-$$GOARCH.yml; \
46+
done; \
47+
done
48+
49+
publish:
50+
@echo "Updating plugin..."
51+
$(CDSCTL) admin plugins import $(TARGET_DIR)/$(TARGET_NAME).yml
52+
@for GOOS in $(TARGET_OS); do \
53+
for GOARCH in $(TARGET_ARCH); do \
54+
EXTENSION=""; \
55+
if test "$$GOOS" = "windows" ; then EXTENSION=".exe"; fi; \
56+
echo "Updating plugin binary $(TARGET_NAME)-$$GOOS-$$GOARCH$$EXTENSION"; \
57+
$(CDSCTL) admin plugins binary-add artifactory-release-plugin $(TARGET_DIR)/$(TARGET_NAME)-$$GOOS-$$GOARCH.yml $(TARGET_DIR)/$(TARGET_NAME)-$$GOOS-$$GOARCH$$EXTENSION; \
58+
done; \
59+
done

0 commit comments

Comments
 (0)