From 8596b711ffab7e30d0e520af52e57a375451fa73 Mon Sep 17 00:00:00 2001 From: hanif Date: Fri, 8 Dec 2017 09:57:17 +0600 Subject: [PATCH 1/2] Fix compile --- .../a8uhnf/test-yml/nginx-deployment.yaml | 22 ----- .../a8uhnf/test-yml1/nginx-deployment.yaml | 28 ------ .../a8uhnf/test-yml/crd/apiext.yaml | 41 --------- .../github.com/a8uhnf/test-yml/crd/p1.yaml | 29 ------- .../a8uhnf/test-yml/dyn-hostpath/aws.yaml | 17 ---- .../a8uhnf/test-yml/dyn-hostpath/pv-pod.yaml | 16 ---- .../a8uhnf/test-yml/dyn-hostpath/pv.yaml | 14 --- .../a8uhnf/test-yml/dyn-hostpath/ss.yaml | 46 ---------- .../github.com/a8uhnf/test-yml/manifest.yaml | 7 -- .../a8uhnf/test-yml/nginx-deployment.yaml | 22 ----- .../github.com/a8uhnf/test-yml/nginx-dm.yaml | 21 ----- .../a8uhnf/test-yml/test-manifest.yaml | 7 -- .../a8uhnf/test-yml1/crd/apiext.yaml | 41 --------- .../github.com/a8uhnf/test-yml1/crd/p1.yaml | 29 ------- .../a8uhnf/test-yml1/dyn-hostpath/aws.yaml | 17 ---- .../a8uhnf/test-yml1/dyn-hostpath/pv-pod.yaml | 16 ---- .../a8uhnf/test-yml1/dyn-hostpath/pv.yaml | 14 --- .../a8uhnf/test-yml1/dyn-hostpath/ss.yaml | 46 ---------- .../github.com/a8uhnf/test-yml1/manifest.yaml | 7 -- .../a8uhnf/test-yml1/nginx-deployment.yaml | 22 ----- .../github.com/a8uhnf/test-yml1/nginx-dm.yaml | 21 ----- .../github.com/a8uhnf/test-yml1/test-dep.yaml | 7 -- dep/cmd/compile.go | 87 +++++++++++-------- dep/cmd/dep.go | 39 +++++---- dep/copy/copy.go | 2 +- dep/main.go | 2 +- manifest.yaml | 6 +- 27 files changed, 82 insertions(+), 544 deletions(-) delete mode 100644 _outlook/github.com/a8uhnf/test-yml/nginx-deployment.yaml delete mode 100644 _outlook/github.com/a8uhnf/test-yml1/nginx-deployment.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/crd/apiext.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/crd/p1.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/dyn-hostpath/aws.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/dyn-hostpath/pv-pod.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/dyn-hostpath/pv.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/dyn-hostpath/ss.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/manifest.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/nginx-deployment.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/nginx-dm.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml/test-manifest.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/crd/apiext.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/crd/p1.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/aws.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/pv-pod.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/pv.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/ss.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/manifest.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/nginx-deployment.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/nginx-dm.yaml delete mode 100644 _vendor/github.com/a8uhnf/test-yml1/test-dep.yaml diff --git a/_outlook/github.com/a8uhnf/test-yml/nginx-deployment.yaml b/_outlook/github.com/a8uhnf/test-yml/nginx-deployment.yaml deleted file mode 100644 index 83a9efda..00000000 --- a/_outlook/github.com/a8uhnf/test-yml/nginx-deployment.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - name: nginx -spec: - replicas: 2 - template: - metadata: - annotations: - app: nginx - labels: - app: nginx1 - name: nginx - spec: - containers: - - image: nginx - name: nginx - ports: - - containerPort: 80 - resources: - limits: - cpu: 10m diff --git a/_outlook/github.com/a8uhnf/test-yml1/nginx-deployment.yaml b/_outlook/github.com/a8uhnf/test-yml1/nginx-deployment.yaml deleted file mode 100644 index ba955a22..00000000 --- a/_outlook/github.com/a8uhnf/test-yml1/nginx-deployment.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: apps/v1beta2 -kind: Deployment -metadata: - annotations: - git-commit-hash: 3271e70906a49bb3cbcd7882fefd33a0f0031135 - creationTimestamp: null - name: nginx -spec: - replicas: 1 - strategy: {} - template: - metadata: - annotations: - app: nginx - creationTimestamp: null - labels: - app: nginx - name: nginx - spec: - containers: - - image: nginx - name: nginx - ports: - - containerPort: 80 - resources: - limits: - cpu: 10m -status: {} diff --git a/_vendor/github.com/a8uhnf/test-yml/crd/apiext.yaml b/_vendor/github.com/a8uhnf/test-yml/crd/apiext.yaml deleted file mode 100644 index 77386d1e..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/crd/apiext.yaml +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - creationTimestamp: 2017-09-20T06:38:18Z - labels: - app: kubedb - name: postgreses.kubedb.com - resourceVersion: "193" - selfLink: /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/postgreses.kubedb.com - uid: 49ce4e1a-9dce-11e7-8b3f-08002709c846 -spec: - group: kubedb.com - names: - kind: Postgres - listKind: PostgresList - plural: postgreses - shortNames: - - pg - singular: postgres - scope: Namespaced - version: v1alpha1 -status: - acceptedNames: - kind: Postgres - listKind: PostgresList - plural: postgreses - shortNames: - - pg - singular: postgres - conditions: - - lastTransitionTime: null - message: no conflicts found - reason: NoConflicts - status: "True" - type: NamesAccepted - - lastTransitionTime: 2017-09-20T06:38:18Z - message: the initial names have been accepted - reason: InitialNamesAccepted - status: "True" - type: Established - diff --git a/_vendor/github.com/a8uhnf/test-yml/crd/p1.yaml b/_vendor/github.com/a8uhnf/test-yml/crd/p1.yaml deleted file mode 100644 index cb91b055..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/crd/p1.yaml +++ /dev/null @@ -1,29 +0,0 @@ -apiVersion: kubedb.com/v1alpha1 -kind: Postgres -metadata: - annotations: - creationTimestamp: 2017-09-20T07:19:17Z - deletionGracePeriodSeconds: null - deletionTimestamp: null - generation: 0 - name: p1 - namespace: demo - resourceVersion: "3637" - selfLink: /apis/kubedb.com/v1alpha1/namespaces/demo/postgreses/p1 - uid: 039baa9d-9dd4-11e7-8b3f-08002709c846 -spec: - doNotPause: false - init: - scriptSource: - gitRepo: - repository: https://github.com/k8sdb/postgres-init-scripts.git - scriptPath: postgres-init-scripts/run.sh - storage: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 50Mi - storageClassName: standard - version: 9.5 - diff --git a/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/aws.yaml b/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/aws.yaml deleted file mode 100644 index 20422ead..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/aws.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: test-ebs -spec: - containers: - - image: gcr.io/google_containers/test-webserver - name: test-container - volumeMounts: - - mountPath: /test-ebs - name: test-volume - volumes: - - name: test-volume - # This AWS EBS volume must already exist. - awsElasticBlockStore: - volumeID: vol-02dcd863d6b09b41c - fsType: ext4 diff --git a/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/pv-pod.yaml b/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/pv-pod.yaml deleted file mode 100644 index 2fca254d..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/pv-pod.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: test-pd -spec: - containers: - - image: gcr.io/google_containers/test-webserver - name: test-container - volumeMounts: - - mountPath: /test-pd - name: test-volume - volumes: - - name: test-volume - hostPath: - # directory location on host - path: /tmp diff --git a/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/pv.yaml b/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/pv.yaml deleted file mode 100644 index 87398e9f..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/pv.yaml +++ /dev/null @@ -1,14 +0,0 @@ - apiVersion: v1 - kind: PersistentVolume - metadata: - name: pv0003 - annotations: - volume.beta.kubernetes.io/storage-class: "slow" - spec: - capacity: - storage: 5Gi - accessModes: - - ReadWriteOnce - persistentVolumeReclaimPolicy: Recycle - hostPath: - path: /tmp diff --git a/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/ss.yaml b/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/ss.yaml deleted file mode 100644 index 79db8592..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/dyn-hostpath/ss.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - name: nginx - labels: - app: nginx -spec: - ports: - - port: 80 - name: web - clusterIP: None - selector: - app: nginx ---- -apiVersion: apps/v1beta1 -kind: StatefulSet -metadata: - name: web -spec: - serviceName: "nginx" - replicas: 2 - template: - metadata: - labels: - app: nginx - spec: - containers: - - name: nginx - image: gcr.io/google_containers/nginx-slim:0.8 - ports: - - containerPort: 80 - name: web - volumeMounts: - - name: www - mountPath: /usr/share/nginx/html - volumeClaimTemplates: - - metadata: - name: www - annotations: - volume.alpha.kubernetes.io/storage-class: gp2 - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi diff --git a/_vendor/github.com/a8uhnf/test-yml/manifest.yaml b/_vendor/github.com/a8uhnf/test-yml/manifest.yaml deleted file mode 100644 index e68fe72c..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/manifest.yaml +++ /dev/null @@ -1,7 +0,0 @@ -package: github.com/packsh/tasty-kube -owners: -- name: Appscode - email: team@appscode.com -dependencies: -- package: github.com/a8uhnf/test-yml1 - branch: test-dep1 diff --git a/_vendor/github.com/a8uhnf/test-yml/nginx-deployment.yaml b/_vendor/github.com/a8uhnf/test-yml/nginx-deployment.yaml deleted file mode 100644 index 9b6b5ad6..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/nginx-deployment.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: apps/v1beta1 -kind: Deployment -metadata: - name: nginx -spec: - replicas: 1 - template: - metadata: - name: nginx - labels: - app: nginx - annotations: - app: nginx - spec: - containers: - - name: nginx - image: nginx - ports: - - containerPort: 80 - resources: - limits: - cpu: '10m' diff --git a/_vendor/github.com/a8uhnf/test-yml/nginx-dm.yaml b/_vendor/github.com/a8uhnf/test-yml/nginx-dm.yaml deleted file mode 100644 index e0ea3b67..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/nginx-dm.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: DaemonSet -metadata: - name: nginx-dm - namespace: default - labels: - app: nginx-dm -spec: - template: - metadata: - labels: - name: busy-dm - spec: - containers: - - name: nginx - image: nginx - ports: - - containerPort: 80 - resources: - limits: - cpu: '10m' diff --git a/_vendor/github.com/a8uhnf/test-yml/test-manifest.yaml b/_vendor/github.com/a8uhnf/test-yml/test-manifest.yaml deleted file mode 100644 index 32e84599..00000000 --- a/_vendor/github.com/a8uhnf/test-yml/test-manifest.yaml +++ /dev/null @@ -1,7 +0,0 @@ -package: github.com/packsh/tasty-kube -owners: -- name: Appscode - email: team@appscode.com -dependencies: -- package: github.com/a8uhnf/test-yml1 - branch: master diff --git a/_vendor/github.com/a8uhnf/test-yml1/crd/apiext.yaml b/_vendor/github.com/a8uhnf/test-yml1/crd/apiext.yaml deleted file mode 100644 index 77386d1e..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/crd/apiext.yaml +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - creationTimestamp: 2017-09-20T06:38:18Z - labels: - app: kubedb - name: postgreses.kubedb.com - resourceVersion: "193" - selfLink: /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/postgreses.kubedb.com - uid: 49ce4e1a-9dce-11e7-8b3f-08002709c846 -spec: - group: kubedb.com - names: - kind: Postgres - listKind: PostgresList - plural: postgreses - shortNames: - - pg - singular: postgres - scope: Namespaced - version: v1alpha1 -status: - acceptedNames: - kind: Postgres - listKind: PostgresList - plural: postgreses - shortNames: - - pg - singular: postgres - conditions: - - lastTransitionTime: null - message: no conflicts found - reason: NoConflicts - status: "True" - type: NamesAccepted - - lastTransitionTime: 2017-09-20T06:38:18Z - message: the initial names have been accepted - reason: InitialNamesAccepted - status: "True" - type: Established - diff --git a/_vendor/github.com/a8uhnf/test-yml1/crd/p1.yaml b/_vendor/github.com/a8uhnf/test-yml1/crd/p1.yaml deleted file mode 100644 index cb91b055..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/crd/p1.yaml +++ /dev/null @@ -1,29 +0,0 @@ -apiVersion: kubedb.com/v1alpha1 -kind: Postgres -metadata: - annotations: - creationTimestamp: 2017-09-20T07:19:17Z - deletionGracePeriodSeconds: null - deletionTimestamp: null - generation: 0 - name: p1 - namespace: demo - resourceVersion: "3637" - selfLink: /apis/kubedb.com/v1alpha1/namespaces/demo/postgreses/p1 - uid: 039baa9d-9dd4-11e7-8b3f-08002709c846 -spec: - doNotPause: false - init: - scriptSource: - gitRepo: - repository: https://github.com/k8sdb/postgres-init-scripts.git - scriptPath: postgres-init-scripts/run.sh - storage: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 50Mi - storageClassName: standard - version: 9.5 - diff --git a/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/aws.yaml b/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/aws.yaml deleted file mode 100644 index 20422ead..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/aws.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: test-ebs -spec: - containers: - - image: gcr.io/google_containers/test-webserver - name: test-container - volumeMounts: - - mountPath: /test-ebs - name: test-volume - volumes: - - name: test-volume - # This AWS EBS volume must already exist. - awsElasticBlockStore: - volumeID: vol-02dcd863d6b09b41c - fsType: ext4 diff --git a/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/pv-pod.yaml b/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/pv-pod.yaml deleted file mode 100644 index 2fca254d..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/pv-pod.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: test-pd -spec: - containers: - - image: gcr.io/google_containers/test-webserver - name: test-container - volumeMounts: - - mountPath: /test-pd - name: test-volume - volumes: - - name: test-volume - hostPath: - # directory location on host - path: /tmp diff --git a/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/pv.yaml b/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/pv.yaml deleted file mode 100644 index 87398e9f..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/pv.yaml +++ /dev/null @@ -1,14 +0,0 @@ - apiVersion: v1 - kind: PersistentVolume - metadata: - name: pv0003 - annotations: - volume.beta.kubernetes.io/storage-class: "slow" - spec: - capacity: - storage: 5Gi - accessModes: - - ReadWriteOnce - persistentVolumeReclaimPolicy: Recycle - hostPath: - path: /tmp diff --git a/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/ss.yaml b/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/ss.yaml deleted file mode 100644 index 79db8592..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/dyn-hostpath/ss.yaml +++ /dev/null @@ -1,46 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - name: nginx - labels: - app: nginx -spec: - ports: - - port: 80 - name: web - clusterIP: None - selector: - app: nginx ---- -apiVersion: apps/v1beta1 -kind: StatefulSet -metadata: - name: web -spec: - serviceName: "nginx" - replicas: 2 - template: - metadata: - labels: - app: nginx - spec: - containers: - - name: nginx - image: gcr.io/google_containers/nginx-slim:0.8 - ports: - - containerPort: 80 - name: web - volumeMounts: - - name: www - mountPath: /usr/share/nginx/html - volumeClaimTemplates: - - metadata: - name: www - annotations: - volume.alpha.kubernetes.io/storage-class: gp2 - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi diff --git a/_vendor/github.com/a8uhnf/test-yml1/manifest.yaml b/_vendor/github.com/a8uhnf/test-yml1/manifest.yaml deleted file mode 100644 index 04d1059d..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/manifest.yaml +++ /dev/null @@ -1,7 +0,0 @@ -package: github.com/packsh/tasty-kube -owners: -- name: Appscode - email: team@appscode.com -dependencies: -- package: github.com/a8uhnf/test-yml - version: master diff --git a/_vendor/github.com/a8uhnf/test-yml1/nginx-deployment.yaml b/_vendor/github.com/a8uhnf/test-yml1/nginx-deployment.yaml deleted file mode 100644 index 9b6b5ad6..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/nginx-deployment.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: apps/v1beta1 -kind: Deployment -metadata: - name: nginx -spec: - replicas: 1 - template: - metadata: - name: nginx - labels: - app: nginx - annotations: - app: nginx - spec: - containers: - - name: nginx - image: nginx - ports: - - containerPort: 80 - resources: - limits: - cpu: '10m' diff --git a/_vendor/github.com/a8uhnf/test-yml1/nginx-dm.yaml b/_vendor/github.com/a8uhnf/test-yml1/nginx-dm.yaml deleted file mode 100644 index e0ea3b67..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/nginx-dm.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: DaemonSet -metadata: - name: nginx-dm - namespace: default - labels: - app: nginx-dm -spec: - template: - metadata: - labels: - name: busy-dm - spec: - containers: - - name: nginx - image: nginx - ports: - - containerPort: 80 - resources: - limits: - cpu: '10m' diff --git a/_vendor/github.com/a8uhnf/test-yml1/test-dep.yaml b/_vendor/github.com/a8uhnf/test-yml1/test-dep.yaml deleted file mode 100644 index 8e10260c..00000000 --- a/_vendor/github.com/a8uhnf/test-yml1/test-dep.yaml +++ /dev/null @@ -1,7 +0,0 @@ -package: github.com/packsh/tasty-kube -owners: -- name: Appscode - email: team@appscode.com -dependencies: -- package: github.com/packsh/tasty-kube - branch: master diff --git a/dep/cmd/compile.go b/dep/cmd/compile.go index 1bf6d96a..7fdc3121 100644 --- a/dep/cmd/compile.go +++ b/dep/cmd/compile.go @@ -28,12 +28,23 @@ func NewCompileCommand() *cobra.Command { Use: "compile", Short: "Compile with patch.", Run: func(cmd *cobra.Command, args []string) { - compiledYaml, err := CompileWithPatch() + /*compiledYaml, err := CompileWithPatch() if err != nil { log.Fatalln(err) } // fmt.Println("yaml", string(compiledYaml)) - DumpCompiledFile(compiledYaml) + DumpCompiledFile(compiledYaml)*/ + rootPath,err := os.Getwd() + if err != nil { + log.Fatalln(err) + } + + fmt.Println("Hello rootpath", rootPath) + + err = filepath.Walk(filepath.Join(rootPath, PatchFolder), visitPatchAndDump) + if err != nil { + log.Fatalln(err) + } }, } @@ -43,40 +54,48 @@ func NewCompileCommand() *cobra.Command { return cmd } -func CompileWithPatch() ([]byte, error) { - root, err := os.Getwd() +func visitPatchAndDump(path string, fileInfo os.FileInfo, err error) error { + if fileInfo.IsDir() { + return nil + } + patchByte, err := ioutil.ReadFile(path) if err != nil { - return nil, err + return err } - srcDir := filepath.Join(root, src) - _, err = os.Stat(srcDir) - if err != nil { - return nil, err + fmt.Println("hello path-----", string(patchByte)) + + srcFilepath := strings.Replace(path, PatchFolder, _VendorFolder, 1) + + fmt.Println("------------------", filepath.Dir(srcFilepath)) + if _, err := os.Stat(srcFilepath); err != nil { + return err } - srcFile, err := ioutil.ReadFile(srcDir) + srcYamlByte, err := ioutil.ReadFile(srcFilepath) if err != nil { - return nil, err + return err } - jsonSrc, err := yaml.YAMLToJSON(srcFile) + mergedPatchYaml, err := CompileWithPatch(srcYamlByte, patchByte) if err != nil { - return nil, err + return err } - patchDir := filepath.Join(root, patch) - patchFileInfo, err = os.Stat(patchDir) + err = DumpCompiledFile(mergedPatchYaml, strings.Replace(path, PatchFolder, CompileDirectory, 1)) if err != nil { - return nil, err + return err } + return nil +} - patchFile, err := ioutil.ReadFile(patchDir) +func CompileWithPatch(srcByte, patchByte []byte) ([]byte, error) { + jsonSrc, err := yaml.YAMLToJSON(srcByte) if err != nil { return nil, err } - jsonPatch, err := yaml.YAMLToJSON(patchFile) + jsonPatch, err := yaml.YAMLToJSON(patchByte) if err != nil { return nil, err } @@ -85,16 +104,16 @@ func CompileWithPatch() ([]byte, error) { if err != nil { return nil, err } + yaml, err := yaml.JSONToYAML(compiled) if err != nil { - log.Println(err) return nil, err } - fmt.Println(string(yaml)) return yaml, err } -func DumpCompiledFile(compiledYaml []byte) error { +func DumpCompiledFile(compiledYaml []byte, outlookPath string) error { + fmt.Println("hello Dump Compiled File------------", outlookPath) root, err := os.Getwd() if err != nil { return err @@ -105,26 +124,26 @@ func DumpCompiledFile(compiledYaml []byte) error { return err } - outlookDir := strings.Replace(patch, PatchFolder, CompileDirectory, 1) - lstIndexOfSlash := strings.LastIndex(outlookDir, "/") - if err != nil { - return err - } - dstPath := filepath.Join(root, outlookDir[0:lstIndexOfSlash]) - err = os.MkdirAll(dstPath, 0755) - if err != nil { - return err + // If not exists mkdir the folder + outlookDir := filepath.Dir(outlookPath) + if _, err := os.Stat(outlookDir); err != nil { + if os.IsNotExist(err) { + err := os.MkdirAll(outlookDir, 0755) + if err != nil { + return err + } + } } - outLookFilePath := filepath.Join(dstPath, patchFileInfo.Name()) - fmt.Println("file name-----", outLookFilePath) - _, err = os.Create(outLookFilePath) + // outLookFilePath := filepath.Join(dstPath, patchFileInfo.Name()) + fmt.Println("file name-----", outlookPath) + _, err = os.Create(outlookPath) if err != nil { return err } - err = ioutil.WriteFile(outLookFilePath, annotateYaml, 0755) + err = ioutil.WriteFile(outlookPath, annotateYaml, 0755) if err != nil { return err } diff --git a/dep/cmd/dep.go b/dep/cmd/dep.go index ba5711e7..166d9811 100644 --- a/dep/cmd/dep.go +++ b/dep/cmd/dep.go @@ -8,7 +8,7 @@ import ( "io/ioutil" "github.com/ghodss/yaml" "log" - typ "github.com/packsh/demo-dep/type" + typ "github.com/kubepack/pack/type" "github.com/golang/dep/gps/pkgtree" "github.com/golang/dep/gps" "strings" @@ -17,28 +17,39 @@ import ( "fmt" ) +var ( + verboseMode bool +) + func NewDepCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "dep", + Use: "dep", Short: "Command for get non go file(especially yaml files).", Run: func(cmd *cobra.Command, args []string) { - DepRun() + err := DepRun() + if err != nil { + log.Fatalln(err) + } }, } - + cmd.Flags().BoolVarP(&verboseMode, "verbose", "v", verboseMode, "Use this flag for verbose output when install dependencies.") return cmd } -func DepRun() { +func DepRun() error { // Assume the current directory is correctly placed on a GOPATH, and that it's the // root of the project. + logger := log.New(ioutil.Discard, "", 0) + if verboseMode { + logger = log.New(os.Stdout, "", 0) + } root, _ := os.Getwd() - man := filepath.Join(root, "manifest.yaml") + man := filepath.Join(root, typ.ManifestFile) byt, err := ioutil.ReadFile(man) manStruc := typ.ManifestDefinition{} err = yaml.Unmarshal(byt, &manStruc) if err != nil { - log.Fatalln("Error Occuered-----", err) + return err } imports := make([]string, len(manStruc.Dependencies)) @@ -63,7 +74,7 @@ func DepRun() { } params := gps.SolveParameters{ RootDir: root, - TraceLogger: log.New(os.Stdout, "", 0), + TraceLogger: logger, ProjectAnalyzer: NaiveAnalyzer{}, Manifest: manifestYaml, RootPackageTree: pkgtree.PackageTree{ @@ -75,7 +86,7 @@ func DepRun() { tempdir, _ := ioutil.TempDir("", "gps-repocache") srcManagerConfig := gps.SourceManagerConfig{ Cachedir: filepath.Join(tempdir), - Logger: log.New(os.Stdout, "", 0), + Logger: logger, DisableLocking: true, } log.Println("Tempdir: ", tempdir) @@ -87,20 +98,19 @@ func DepRun() { // Prep and run the solver solver, err := gps.Prepare(params, sourcemgr) if err != nil { - log.Fatalln("Prepare error occurred..", err) - return + return err } solution, err := solver.Solve(ctx) if err != nil { - log.Fatalln("Solve error occurred..", err) - return + return err } if err == nil { // If no failure, blow away the vendor dir and write a new one out, // stripping nested vendor directories as we go. os.RemoveAll(filepath.Join(root, "_vendor")) - gps.WriteDepTree(filepath.Join(root, "_vendor"), solution, sourcemgr, true, log.New(os.Stdout, "Hello:-----", 4)) + gps.WriteDepTree(filepath.Join(root, "_vendor"), solution, sourcemgr, true, logger) } + return nil } type NaiveAnalyzer struct { @@ -271,4 +281,3 @@ func (a NaiveAnalyzer) lookForManifest(root string) (gps.Manifest, gps.Lock, err lck.root = root return man, lck, nil } - diff --git a/dep/copy/copy.go b/dep/copy/copy.go index 3f365d71..4e5d75c9 100644 --- a/dep/copy/copy.go +++ b/dep/copy/copy.go @@ -3,7 +3,7 @@ package copy import ( "fmt" "github.com/ghodss/yaml" - typ "github.com/packsh/demo-dep/type" + typ "github.com/kubepack/pack/type" "io/ioutil" "io" "log" diff --git a/dep/main.go b/dep/main.go index 90c25fb4..a732d45c 100644 --- a/dep/main.go +++ b/dep/main.go @@ -16,7 +16,7 @@ import ( "github.com/golang/dep/gps" "github.com/golang/dep/gps/pkgtree" // "github.com/packsh/demo-dep/dep/copy" - typ "github.com/packsh/demo-dep/type" + typ "github.com/kubepack/pack/type" ) // This is probably the simplest possible implementation of gps. It does the diff --git a/manifest.yaml b/manifest.yaml index 905c0ada..be91abcd 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -1,7 +1,7 @@ -package: github.com/sdboyer/gps +package: github.com/kubepack/pack owners: -- name: Sam Boyer - email: tech@samboyer.org +- name: Appscode Inc. + email: admin@appscode.com dependencies: - package: github.com/a8uhnf/test-yml version: 0.0.1 \ No newline at end of file From cccbf5dcd97a42d77ab7cbac516c8f8bfd0a7995 Mon Sep 17 00:00:00 2001 From: hanif Date: Fri, 8 Dec 2017 10:27:19 +0600 Subject: [PATCH 2/2] Fix root main.go file --- main.go | 303 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 246 insertions(+), 57 deletions(-) diff --git a/main.go b/main.go index 5f85cfe5..a732d45c 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,3 @@ -// +build ignore - package main import ( @@ -11,9 +9,14 @@ import ( "path/filepath" "strings" - "github.com/sdboyer/gps" - "github.com/sdboyer/gps/pkgtree" + "context" + "time" + "github.com/ghodss/yaml" + "github.com/golang/dep/gps" + "github.com/golang/dep/gps/pkgtree" + // "github.com/packsh/demo-dep/dep/copy" + typ "github.com/kubepack/pack/type" ) // This is probably the simplest possible implementation of gps. It does the @@ -24,27 +27,14 @@ import ( // // This will compile and work...and then blow away any vendor directory present // in the cwd. Be careful! -type ManifestDef struct { - Package string `json:"package"` - Owners []struct { - Name string `json:"name"` - Email string `json:"email"` - } `json:"owners"` - Dependencies []struct { - Package string `json:"package"` - Version string `json:"version,omitempty"` - Repo string `json:"repo,omitempty"` - Branch string `json:"branch,omitempty"` - } `json:"dependencies"` -} func main() { // Assume the current directory is correctly placed on a GOPATH, and that it's the // root of the project. root, _ := os.Getwd() - man := root + "/manifest.yaml" + man := filepath.Join(root, "manifest.yaml") byt, err := ioutil.ReadFile(man) - manStruc := ManifestDef{} + manStruc := typ.ManifestDefinition{} err = yaml.Unmarshal(byt, &manStruc) if err != nil { log.Fatalln("Error Occuered-----", err) @@ -59,70 +49,172 @@ func main() { srcprefix := filepath.Join(build.Default.GOPATH, "src") + string(filepath.Separator) importroot := filepath.ToSlash(strings.TrimPrefix(root, srcprefix)) + manifestYaml := ManifestYaml{} + manifestYaml.root = root + pkgTree := map[string]pkgtree.PackageOrErr{ + "github.com/sdboyer/gps": { + P: pkgtree.Package{ + // Name: "github.com/a8uhnf/go_stack", + // ImportPath: "github.com/packsh/demo-dep", + Imports: imports, + }, + }, + } params := gps.SolveParameters{ RootDir: root, - Trace: false, TraceLogger: log.New(os.Stdout, "", 0), ProjectAnalyzer: NaiveAnalyzer{}, - Manifest: ManifestYaml{}, + Manifest: manifestYaml, RootPackageTree: pkgtree.PackageTree{ ImportRoot: importroot, - Packages: map[string]pkgtree.PackageOrErr{ - "github.com/sdboyer/gps": pkgtree.PackageOrErr{ - P: pkgtree.Package{ - // Name: "github.com/a8uhnf/go_stack", - // ImportPath: "github.com/packsh/demo-dep", - Imports: imports, - }, - }, - }, + Packages: pkgTree, }, } + // Set up a SourceManager. This manages interaction with sources (repositories). + tempdir, _ := ioutil.TempDir("", "gps-repocache") + srcManagerConfig := gps.SourceManagerConfig{ + Cachedir: filepath.Join(tempdir), + Logger: log.New(os.Stdout, "", 0), + DisableLocking: true, + } + log.Println("hello tempdir", tempdir) + sourcemgr, _ := gps.NewSourceManager(srcManagerConfig) + defer sourcemgr.Release() + + ctx, cancel := context.WithTimeout(context.Background(), 50*time.Minute) + defer cancel() + // Prep and run the solver + solver, err := gps.Prepare(params, sourcemgr) + if err != nil { + fmt.Println("Prepare error occurred..", err) + return + } + solution, err := solver.Solve(ctx) + if err != nil { + fmt.Println("Solve error occurred..", err) + return + } + if err == nil { + // If no failure, blow away the vendor dir and write a new one out, + // stripping nested vendor directories as we go. + os.RemoveAll(filepath.Join(root, "_vendor")) + gps.WriteDepTree(filepath.Join(root, "_vendor"), solution, sourcemgr, true, log.New(os.Stdout, "Hello:-----", 4)) + } +} + +func DepRun() { + // Assume the current directory is correctly placed on a GOPATH, and that it's the + // root of the project. + root, _ := os.Getwd() + man := filepath.Join(root, "manifest.yaml") + byt, err := ioutil.ReadFile(man) + manStruc := typ.ManifestDefinition{} + err = yaml.Unmarshal(byt, &manStruc) + if err != nil { + log.Fatalln("Error Occuered-----", err) + } + + imports := make([]string, len(manStruc.Dependencies)) + + for key, value := range manStruc.Dependencies { + imports[key] = value.Package + } + + srcprefix := filepath.Join(build.Default.GOPATH, "src") + string(filepath.Separator) + importroot := filepath.ToSlash(strings.TrimPrefix(root, srcprefix)) + manifestYaml := ManifestYaml{} + manifestYaml.root = root + pkgTree := map[string]pkgtree.PackageOrErr{ + "github.com/sdboyer/gps": { + P: pkgtree.Package{ + // Name: "github.com/a8uhnf/go_stack", + // ImportPath: "github.com/packsh/demo-dep", + Imports: imports, + }, + }, + } + params := gps.SolveParameters{ + RootDir: root, + TraceLogger: log.New(os.Stdout, "", 0), + ProjectAnalyzer: NaiveAnalyzer{}, + Manifest: manifestYaml, + RootPackageTree: pkgtree.PackageTree{ + ImportRoot: importroot, + Packages: pkgTree, + }, + } // Set up a SourceManager. This manages interaction with sources (repositories). tempdir, _ := ioutil.TempDir("", "gps-repocache") - sourcemgr, _ := gps.NewSourceManager(filepath.Join(tempdir)) + srcManagerConfig := gps.SourceManagerConfig{ + Cachedir: filepath.Join(tempdir), + Logger: log.New(os.Stdout, "", 0), + DisableLocking: true, + } + log.Println("hello tempdir", tempdir) + sourcemgr, _ := gps.NewSourceManager(srcManagerConfig) defer sourcemgr.Release() + ctx, cancel := context.WithTimeout(context.Background(), 50*time.Minute) + defer cancel() // Prep and run the solver solver, err := gps.Prepare(params, sourcemgr) - solution, err := solver.Solve() - fmt.Println("Hello Error", err) + if err != nil { + fmt.Println("Prepare error occurred..", err) + return + } + solution, err := solver.Solve(ctx) + if err != nil { + fmt.Println("Solve error occurred..", err) + return + } if err == nil { // If no failure, blow away the vendor dir and write a new one out, // stripping nested vendor directories as we go. - os.RemoveAll(filepath.Join(root, "vendor")) - gps.WriteDepTree(filepath.Join(root, "vendor"), solution, sourcemgr, true) + os.RemoveAll(filepath.Join(root, "_vendor")) + gps.WriteDepTree(filepath.Join(root, "_vendor"), solution, sourcemgr, true, log.New(os.Stdout, "Hello:-----", 4)) } } -type NaiveAnalyzer struct{} +type NaiveAnalyzer struct { + // lookForManifest(root string) (gps.) +} // DeriveManifestAndLock is called when the solver needs manifest/lock data // for a particular dependency project (identified by the gps.ProjectRoot // parameter) at a particular version. That version will be checked out in a // directory rooted at path. func (a NaiveAnalyzer) DeriveManifestAndLock(path string, n gps.ProjectRoot) (gps.Manifest, gps.Lock, error) { - fmt.Println("Hello path", path) - fmt.Println("Hello n", n) - + // man := filepath.Join(filepath.Join(path, "manifest.yaml")) + // return nil, nil, nil // this check should be unnecessary, but keeping it for now as a canary if _, err := os.Lstat(path); err != nil { return nil, nil, fmt.Errorf("No directory exists at %s; cannot produce ProjectInfo", path) } - return nil, nil, nil + m, l, err := a.lookForManifest(path) + if err == nil { + // TODO verify project name is same as what SourceManager passed in? + return m, l, nil + } else { + return nil, nil, err + } } // Reports the name and version of the analyzer. This is used internally as part // of gps' hashing memoization scheme. -func (a NaiveAnalyzer) Info() (name string, version int) { - return "example-analyzer", 1 +func (a NaiveAnalyzer) Info() gps.ProjectAnalyzerInfo { + return gps.ProjectAnalyzerInfo{ + Name: "example-analyzer", + Version: 1, + } } -type ManifestYaml struct{} +type ManifestYaml struct { + root string +} -func (a ManifestYaml) IgnoredPackages() map[string]bool { +func (a ManifestYaml) IgnoredPackages() *pkgtree.IgnoredRuleset { return nil } @@ -131,28 +223,125 @@ func (a ManifestYaml) RequiredPackages() map[string]bool { } func (a ManifestYaml) Overrides() gps.ProjectConstraints { - // return nil + fmt.Println("Hello world!!!!--------", a.root) + ovrr := gps.ProjectConstraints{} + + mpath := filepath.Join(a.root, typ.ManifestFile) + byt, err := ioutil.ReadFile(mpath) + manStruc := typ.ManifestDefinition{} + err = yaml.Unmarshal(byt, &manStruc) + if err != nil { + log.Fatalln("Error Occuered-----", err) + } + + for _, value := range manStruc.Dependencies { + properties := gps.ProjectProperties{} + if value.Repo != "" { + properties.Source = value.Repo + } else { + properties.Source = value.Package + } + if value.Branch != "" { + properties.Constraint = gps.NewBranch(value.Branch) + } else if value.Version != "" { + properties.Constraint = gps.Revision(value.Version) + } + ovrr[gps.ProjectRoot(value.Package)] = properties + } + return ovrr return gps.ProjectConstraints{ - "github.com/Masterminds/semver": gps.ProjectProperties{ - Source: "github.com/Masterminds/semver", - Constraint: gps.NewBranch("2.x"), + gps.ProjectRoot("github.com/a8uhnf/test-yml"): gps.ProjectProperties{ + Source: "github.com/a8uhnf/test-yml", + Constraint: gps.NewVersion("0.0.1"), }, } + return nil } func (a ManifestYaml) DependencyConstraints() gps.ProjectConstraints { - return gps.ProjectConstraints{ - "github.com/appscode/go": gps.ProjectProperties{ - Source: "github.com/appscode/go", - Constraint: gps.NewBranch("master"), - }, - "github.com/Masterminds/semver": gps.ProjectProperties{ - Source: "github.com/Masterminds/semver", - Constraint: gps.NewBranch("2.x"), - }, + projectConstraints := make(gps.ProjectConstraints) + + man := filepath.Join(a.root, typ.ManifestFile) + byt, err := ioutil.ReadFile(man) + manStruc := typ.ManifestDefinition{} + err = yaml.Unmarshal(byt, &manStruc) + if err != nil { + log.Fatalln("Error Occuered-----", err) + } + + for _, value := range manStruc.Dependencies { + properties := gps.ProjectProperties{} + if value.Repo != "" { + properties.Source = value.Repo + } else { + properties.Source = value.Package + } + if value.Branch != "" { + properties.Constraint = gps.NewBranch(value.Branch) + } else if value.Version != "" { + properties.Constraint = gps.Revision(value.Version) + } + projectConstraints[gps.ProjectRoot(value.Package)] = properties } + return projectConstraints } func (a ManifestYaml) TestDependencyConstraints() gps.ProjectConstraints { return nil } + +type InternalManifest struct { + root string +} + +func (a InternalManifest) DependencyConstraints() gps.ProjectConstraints { + projectConstraints := make(gps.ProjectConstraints) + + man := filepath.Join(a.root, typ.ManifestFile) + byt, err := ioutil.ReadFile(man) + manStruc := typ.ManifestDefinition{} + err = yaml.Unmarshal(byt, &manStruc) + if err != nil { + log.Fatalln("Error Occuered-----", err) + } + + for _, value := range manStruc.Dependencies { + properties := gps.ProjectProperties{} + if value.Repo != "" { + properties.Source = value.Repo + } else { + properties.Source = value.Package + } + if value.Branch != "" { + properties.Constraint = gps.NewBranch(value.Branch) + } else if value.Version != "" { + properties.Constraint = gps.Revision(value.Version) + } + projectConstraints[gps.ProjectRoot(value.Package)] = properties + } + return projectConstraints +} + +type InternalLock struct { + root string +} + +func (a InternalLock) Projects() []gps.LockedProject { + return nil +} + +func (a InternalLock) InputsDigest() []byte { + return nil +} + +func (a NaiveAnalyzer) lookForManifest(root string) (gps.Manifest, gps.Lock, error) { + mpath := filepath.Join(root, typ.ManifestFile) + if _, err := os.Lstat(mpath); err != nil { + return nil, nil, err + } + man := &InternalManifest{} + man.root = root + lck := &InternalLock{} + lck.root = root + return man, lck, nil +}