Skip to content

Commit d993fac

Browse files
authored
feat: add artifactory integration (#5802)
1 parent 3348ec6 commit d993fac

File tree

82 files changed

+6949
-5110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+6949
-5110
lines changed

cli/cdsctl/workflow_run_result.go

+6
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ func toCLIRunResult(results []sdk.WorkflowRunResult) ([]RunResultCli, error) {
237237
return nil, err
238238
}
239239
name = artiResult.Name
240+
case sdk.WorkflowRunResultTypeArtifactManager:
241+
artiResult, err := r.GetArtifactManager()
242+
if err != nil {
243+
return nil, err
244+
}
245+
name = artiResult.Name
240246
}
241247

242248
cliresults = append(cliresults, RunResultCli{

contrib/grpcplugins/action/plugin-archive/go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ replace github.com/ovh/cds => ../../../../
55
go 1.16
66

77
require (
8-
github.com/dsnet/compress v0.0.1 // indirect
98
github.com/golang/protobuf v1.5.0
109
github.com/mholt/archiver v3.1.1+incompatible
1110
github.com/ovh/cds v0.0.0-00010101000000-000000000000

contrib/grpcplugins/action/plugin-archive/go.sum

+39-7
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-clair/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ require (
3636
github.com/quay/clair/v2 v2.1.4
3737
github.com/spf13/viper v1.7.0
3838
github.com/vbatts/tar-split v0.11.1 // indirect
39-
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
39+
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11
4040
)

contrib/grpcplugins/action/plugin-clair/go.sum

+45-9
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-download/go.sum

+42-5
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-group-tmpl/go.sum

+42-5
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-kafka-publish/go.sum

+44-6
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-marathon/go.sum

+44-6
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-npm-audit-parser/go.sum

+42-5
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-ssh-cmd/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ go 1.16
77
require (
88
github.com/golang/protobuf v1.5.0
99
github.com/ovh/cds v0.0.0-00010101000000-000000000000
10-
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
10+
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
1111
)

contrib/grpcplugins/action/plugin-ssh-cmd/go.sum

+44-6
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-tmpl/go.sum

+42-5
Large diffs are not rendered by default.

contrib/grpcplugins/action/plugin-venom/go.sum

+44-6
Large diffs are not rendered by default.

contrib/integrations/arsenal/arsenal.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_config:
33
host:
44
type: string
55
deployment: true
6-
deployment_default_config:
6+
additional_default_config:
77
version:
88
type: string
99
value: "{{.cds.version}}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Artifactory
2+
default_config:
3+
artifactory.url:
4+
type: string
5+
artifactory.token.name:
6+
type: string
7+
artifactory.token:
8+
type: password
9+
artifactory.cds_repository:
10+
type: string
11+
artifactory.promotion.low.maturity:
12+
type: string
13+
artifactory.promotion.high.maturity:
14+
type: string
15+
additional_default_config:
16+
build.info.path:
17+
type: string
18+
value: ""
19+
artifact_manager: true
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-download-artifact
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-download-artifact-$$GOOS-$$GOARCH.yml; \
43+
perl -pi -e s,%os%,$$GOOS,g $(TARGET_DIR)/plugin-artifactory-download-artifact-$$GOOS-$$GOARCH.yml; \
44+
perl -pi -e s,%arch%,$$GOARCH,g $(TARGET_DIR)/plugin-artifactory-download-artifact-$$GOOS-$$GOARCH.yml; \
45+
perl -pi -e s,%filename%,$$FILENAME,g $(TARGET_DIR)/plugin-artifactory-download-artifact-$$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-download-artifact-plugin $(TARGET_DIR)/$(TARGET_NAME)-$$GOOS-$$GOARCH.yml $(TARGET_DIR)/$(TARGET_NAME)-$$GOOS-$$GOARCH$$EXTENSION; \
58+
done; \
59+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"strconv"
8+
9+
"github.com/golang/protobuf/ptypes/empty"
10+
"github.com/jfrog/jfrog-client-go/artifactory"
11+
"github.com/jfrog/jfrog-client-go/artifactory/auth"
12+
"github.com/jfrog/jfrog-client-go/artifactory/services"
13+
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
14+
"github.com/jfrog/jfrog-client-go/config"
15+
"github.com/jfrog/jfrog-client-go/utils/log"
16+
17+
"github.com/ovh/cds/sdk"
18+
"github.com/ovh/cds/sdk/grpcplugin/integrationplugin"
19+
)
20+
21+
/*
22+
This plugin have to be used as a download artifact integration plugin
23+
24+
Artifactory download artifact plugin must configured as following:
25+
name: artifactory-download-artifact-plugin
26+
type: integration
27+
author: "Steven Guiheux"
28+
description: "OVH Artifactory Upload Artifact Plugin"
29+
30+
$ cdsctl admin plugins import artifactory-download-artifact-plugin.yml
31+
32+
Build the present binaries and import in CDS:
33+
os: linux
34+
arch: amd64
35+
cmd: <path-to-binary-file>
36+
37+
$ cdsctl admin plugins binary-add artifactory-download-artifact-plugin artifactory-download-artifact-plugin-bin.yml <path-to-binary-file>
38+
39+
Artifactory integration must configured as following
40+
name: Artifactory
41+
default_config:
42+
artifactory.url:
43+
type: string
44+
artifactory.token:
45+
type: password
46+
artifactory.cds_repository:
47+
type: string
48+
artifact_manager: true
49+
*/
50+
51+
type artifactoryDownloadArtifactPlugin struct {
52+
integrationplugin.Common
53+
}
54+
55+
func (e *artifactoryDownloadArtifactPlugin) Manifest(_ context.Context, _ *empty.Empty) (*integrationplugin.IntegrationPluginManifest, error) {
56+
return &integrationplugin.IntegrationPluginManifest{
57+
Name: "OVH Artifactory Download Artifact Plugin",
58+
Author: "Steven Guiheux",
59+
Description: "OVH Artifactory Download Artifact Plugin",
60+
Version: sdk.VERSION,
61+
}, nil
62+
}
63+
64+
func createArtifactoryClient(url, token string) (artifactory.ArtifactoryServicesManager, error) {
65+
rtDetails := auth.NewArtifactoryDetails()
66+
rtDetails.SetUrl(url)
67+
rtDetails.SetAccessToken(token)
68+
serviceConfig, err := config.NewConfigBuilder().
69+
SetServiceDetails(rtDetails).
70+
SetThreads(1).
71+
SetDryRun(false).
72+
Build()
73+
if err != nil {
74+
return nil, fmt.Errorf("unable to create service config: %v", err)
75+
}
76+
return artifactory.New(serviceConfig)
77+
}
78+
79+
func (e *artifactoryDownloadArtifactPlugin) Run(_ context.Context, opts *integrationplugin.RunQuery) (*integrationplugin.RunResult, error) {
80+
cdsRepo := opts.GetOptions()["cds.integration.artifact_manager.artifactory.cds_repository"]
81+
artifactoryURL := opts.GetOptions()["cds.integration.artifact_manager.artifactory.url"]
82+
token := opts.GetOptions()["cds.integration.artifact_manager.artifactory.token"]
83+
84+
filePath := opts.GetOptions()[sdk.ArtifactDownloadPluginInputFilePath]
85+
path := opts.GetOptions()[sdk.ArtifactDownloadPluginInputDestinationPath]
86+
md5 := opts.GetOptions()[sdk.ArtifactDownloadPluginInputMd5]
87+
permS := opts.GetOptions()[sdk.ArtifactDownloadPluginInputPerm]
88+
89+
perm, err := strconv.ParseUint(permS, 10, 32)
90+
if err != nil {
91+
return fail("unable to read file permission %s: %v", permS, err)
92+
}
93+
94+
artiClient, err := createArtifactoryClient(artifactoryURL, token)
95+
if err != nil {
96+
return fail("unable to create artifactory client: %v", err)
97+
}
98+
log.SetLogger(log.NewLogger(log.ERROR, os.Stdout))
99+
100+
params := services.NewDownloadParams()
101+
params.Pattern = fmt.Sprintf("%s/%s", cdsRepo, filePath)
102+
params.Target = path
103+
params.Flat = true
104+
params.Retries = 5
105+
106+
summary, err := artiClient.DownloadFilesWithSummary(params)
107+
if err != nil || summary.TotalFailed > 0 {
108+
return fail("unable to download files %s from artifactory %s: %v", filePath, params.Target, err)
109+
}
110+
defer summary.Close()
111+
for artDetails := new(utils.ArtifactDetails); summary.ArtifactsDetailsReader.NextRecord(artDetails) == nil; artDetails = new(utils.ArtifactDetails) {
112+
if md5 != artDetails.Checksums.Md5 {
113+
return fail("wrong md5 for file %s. Got %s Want %s", filePath, artDetails.Checksums.Md5, md5)
114+
}
115+
}
116+
117+
fileMode, err := os.Stat(path)
118+
if err != nil {
119+
return fail("unable to get file stat: %v", err)
120+
}
121+
currentperm := uint32(fileMode.Mode().Perm())
122+
if currentperm != uint32(perm) {
123+
if err := os.Chmod(path, os.FileMode(uint32(perm))); err != nil {
124+
return fail("unable to chmod file %s: %v", path, err)
125+
}
126+
}
127+
return &integrationplugin.RunResult{
128+
Status: sdk.StatusSuccess,
129+
}, nil
130+
}
131+
132+
func main() {
133+
e := artifactoryDownloadArtifactPlugin{}
134+
if err := integrationplugin.Start(context.Background(), &e); err != nil {
135+
panic(err)
136+
}
137+
return
138+
139+
}
140+
141+
func fail(format string, args ...interface{}) (*integrationplugin.RunResult, error) {
142+
msg := fmt.Sprintf(format, args...)
143+
fmt.Println(msg)
144+
return &integrationplugin.RunResult{
145+
Details: msg,
146+
Status: sdk.StatusFail,
147+
}, nil
148+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: artifactory-download-artifact-plugin
2+
type: integration-download_artifact
3+
integration: Artifactory
4+
author: "OVH SAS"
5+
description: "OVH Artifactory Download Artifact Plugin"
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-upload-artifact
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-upload-artifact-$$GOOS-$$GOARCH.yml; \
43+
perl -pi -e s,%os%,$$GOOS,g $(TARGET_DIR)/plugin-artifactory-upload-artifact-$$GOOS-$$GOARCH.yml; \
44+
perl -pi -e s,%arch%,$$GOARCH,g $(TARGET_DIR)/plugin-artifactory-upload-artifact-$$GOOS-$$GOARCH.yml; \
45+
perl -pi -e s,%filename%,$$FILENAME,g $(TARGET_DIR)/plugin-artifactory-upload-artifact-$$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-upload-artifact-plugin $(TARGET_DIR)/$(TARGET_NAME)-$$GOOS-$$GOARCH.yml $(TARGET_DIR)/$(TARGET_NAME)-$$GOOS-$$GOARCH$$EXTENSION; \
58+
done; \
59+
done

0 commit comments

Comments
 (0)