forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves argoproj#453
- Loading branch information
Sandeep Bhojwani
committed
Jan 2, 2018
1 parent
849e916
commit 90b7f2e
Showing
8 changed files
with
240 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ dist/ | |
# delve debug binaries | ||
cmd/**/debug | ||
debug.test | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# This example demonstrates the use of artifactory as the store for artifacts. This example assumes the following: | ||
# 1. you have artifactory running in the same namespace as where this workflow will be run and you have created a repo with the name "generic-local" | ||
# 2. you have created a kubernetes secret for storing artifactory username/password. To create kubernetes secret required for this example, | ||
# run the following command: | ||
# $ kubectl create secret generic my-artifactory-credentials --from-literal=username=<YOUR-ARTIFACTORY-USERNAME> --from-literal=password=<YOUR-ARTIFACTORY-PASSWORD> | ||
|
||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: artifactory-artifact- | ||
spec: | ||
entrypoint: artifact-example | ||
templates: | ||
- name: artifact-example | ||
steps: | ||
- - name: generate-artifact | ||
template: whalesay | ||
- - name: consume-artifact | ||
template: print-message | ||
arguments: | ||
artifacts: | ||
- name: message | ||
from: "{{steps.generate-artifact.outputs.artifacts.hello-art}}" | ||
|
||
- name: whalesay | ||
container: | ||
image: docker/whalesay:latest | ||
command: [sh, -c] | ||
args: ["cowsay hello world | tee /tmp/hello_world.txt"] | ||
outputs: | ||
artifacts: | ||
- name: hello-art | ||
path: /tmp/hello_world.txt | ||
artifactory: | ||
url: http:https://artifactory:8081/artifactory/generic-local/hello_world.tgz | ||
usernameSecret: | ||
name: my-artifactory-credentials | ||
key: username | ||
passwordSecret: | ||
name: my-artifactory-credentials | ||
key: password | ||
|
||
- name: print-message | ||
inputs: | ||
artifacts: | ||
- name: message | ||
path: /tmp/message | ||
artifactory: | ||
url: http:https://artifactory:8081/artifactory/generic-local/hello_world.tgz | ||
usernameSecret: | ||
name: my-artifactory-credentials | ||
key: username | ||
passwordSecret: | ||
name: my-artifactory-credentials | ||
key: password | ||
container: | ||
image: alpine:latest | ||
command: [sh, -c] | ||
args: ["cat /tmp/message"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package artifactory | ||
|
||
import ( | ||
wfv1 "github.com/argoproj/argo/api/workflow/v1alpha1" | ||
"net/http" | ||
"os" | ||
"github.com/argoproj/argo/errors" | ||
"io" | ||
) | ||
|
||
type ArtifactoryArtifactDriver struct { | ||
Username string | ||
Password string | ||
} | ||
|
||
|
||
// Download artifact from an artifactory URL | ||
func (a *ArtifactoryArtifactDriver) Load(artifact *wfv1.Artifact, path string) error { | ||
|
||
lf, err := os.Create(path) | ||
if err != nil { | ||
return err | ||
} | ||
defer lf.Close() | ||
|
||
req,err := http.NewRequest(http.MethodGet,artifact.Artifactory.URL,nil) | ||
if err != nil { | ||
return err | ||
} | ||
req.SetBasicAuth(a.Username,a.Password) | ||
res, err := (&http.Client{}).Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer res.Body.Close() | ||
if res.StatusCode < 200 || res.StatusCode >= 300 { | ||
return errors.InternalErrorf("loading file from artifactory failed with reason:%s",res.Status) | ||
} | ||
|
||
_,err = io.Copy(lf,res.Body) | ||
|
||
return err | ||
} | ||
|
||
// UpLoad artifact to an artifactory URL | ||
func (a *ArtifactoryArtifactDriver) Save(path string, artifact *wfv1.Artifact) error { | ||
|
||
f, err := os.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
req, err := http.NewRequest(http.MethodPut,artifact.Artifactory.URL,f) | ||
if err != nil { | ||
return err | ||
} | ||
req.SetBasicAuth(a.Username,a.Password) | ||
res, err := (&http.Client{}).Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer res.Body.Close() | ||
if res.StatusCode < 200 || res.StatusCode >= 300 { | ||
return errors.InternalErrorf("saving file %s to artifactory failed with reason:%s",path,res.Status) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package artifactory_test | ||
|
||
import ( | ||
art "../artifactory" | ||
wfv1 "github.com/argoproj/argo/api/workflow/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
const ( | ||
LoadFileName string = "argo_artifactory_test_load.txt" | ||
SaveFileName string = "argo_artifactory_test_save.txt" | ||
RepoName string = "generic-local" | ||
URL string = "http:https://localhost:8081/artifactory/" + RepoName + "/" + LoadFileName | ||
Username string = "admin" | ||
Password string = "password" | ||
) | ||
|
||
func TestSaveAndLoad(t *testing.T) { | ||
|
||
t.Skip("This test is skipped since it depends on external service") | ||
fileContent := "time: " + string(time.Now().UnixNano()) | ||
|
||
// create file to test save | ||
lf, err := ioutil.TempFile("", LoadFileName) | ||
assert.Nil(t, err) | ||
defer os.Remove(lf.Name()) | ||
// load file with test content | ||
content := []byte(fileContent) | ||
_, err = lf.Write(content) | ||
assert.Nil(t, err) | ||
err = lf.Close() | ||
assert.Nil(t, err) | ||
|
||
// create file to test load | ||
sf, err := ioutil.TempFile("", SaveFileName) | ||
assert.Nil(t, err) | ||
defer os.Remove(sf.Name()) | ||
|
||
artL := &wfv1.Artifact{} | ||
artL.Artifactory = &wfv1.ArtifactoryArtifact{ | ||
URL: URL, | ||
} | ||
driver := &art.ArtifactoryArtifactDriver{ | ||
Username: Username, | ||
Password: Password, | ||
} | ||
driver.Save(lf.Name(), artL) | ||
driver.Load(artL, sf.Name()) | ||
|
||
dat, err := ioutil.ReadFile(sf.Name()) | ||
assert.Nil(t, err) | ||
assert.Equal(t, fileContent, string(dat)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters