8000 feat(api): add APIs for getting pipeline templates and detecting repo type by zhujian7 · Pull Request #557 · caicloud/cyclone · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(api): add APIs for getting pipeline templates and detecting repo type #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
335 changes: 304 additions & 31 deletions Gopkg.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,7 @@
[[constraint]]
name = "github.com/golang/mock"
version = "1.1.1"

[[constraint]]
name = "gopkg.in/yaml.v2"
version = "2.2.1"
1 change: 1 addition & 0 deletions build/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up 10000 @@ -12,6 +12,7 @@ COPY bin/server /cyclone-server
COPY ./notify/provider /template
COPY ./node_modules /root/node_modules
COPY ./api/templates /templates
COPY ./config /config

EXPOSE 7099
EXPOSE 8000
Expand Down
111 changes: 111 additions & 0 deletions config/templates/templates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
- name: maven-3
type: Maven
builderImage: maven:3
testCommands: |
mvn test
packageCommands: |
mvn clean package -Dmaven.test.skip
customizedDockerfile: |
FROM jboss/base-jdk:8

# Copy your file from source to destination.
COPY target/<app>.jar /test-app.jar

# Expose ports.
EXPOSE 8081

# Run your app or exec your start scripts.
CMD ["java", "-jar", "/test-app.jar"]

- name: gradle-3.4.1
type: Gradle
builderImage: gradle:3.4.1
testCommands: |
gradle clean test
packageCommands: |
gradle build -x test
customizedDockerfile: |
FROM jboss/base-jdk:8

# Copy your file from source to destination.
COPY build/<app>.jar /test-app.jar

# Expose ports.
EXPOSE 8081

# Run your app or exec your start scripts.
CMD ["java", "-jar", "/test-app.jar"]

- name: golang-1.9.2
type: Go
builderImage: golang:1.9.2
testCommands: |
echo $GOPATH
# Replace the {repo-path} with your own repository path, e.g. "github.com/caicloud/cyclone".
REPO_PATH={repo-path}
WORKDIR=$GOPATH/src/$REPO_PATH
PARENT_PATH="$(dirname "$WORKDIR")"
mkdir -p $PARENT_PATH
ln -s `pwd` $WORKDIR
cd $WORKDIR
ls -la
go test -cover $(go list ./...)
packageCommands: |
# Replace the {main-method-path} with the path of directory which contains a main() function.
cd $WORKDIR/{main-method-path}
go build -i -v
customizedDockerfile: |
FROM alpine:3.6

# change path to your work dir.
WORKDIR /root

# Copy your file from source to destination.
COPY <app> /test-app

# Expose ports.
EXPOSE 7099

# Run your app or exec your start scripts.
ENTRYPOINT ["/test-app"]

- name: python-2.7
type: Python
builderImage: python:2.7-alpine
testCommands: |
# Run all the test*.py modules inside the test package.
python -m unittest discover -s test -p 'test*.py'
packageCommands: |
cus 10000 tomizedDockerfile: |
FROM python:2.7-alpine

RUN mkdir -p /usr/src/app

# Create working directory
WORKDIR /usr/src/app

# Add your uploaded file to workplace, if it's an archive file (zip, tar, tar.gz),
# it will be unpacked and added to worksapce.
ADD <uploaded-file> .

# Make sure the requirements.txt file exists and then install dependencies using it.
RUN touch requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

CMD [ "python", "./<entrypoint>.py" ]

- name: node-8.9.0
type: NodeJS
builderImage: node:8.9.0-slim
testCommands: |
packageCommands: |
npm run build
customizedDockerfile: |

- name: php-7.1.9
type: PHP
builderImage: php:7.1.9
testCommands: |
packageCommands: |
customizedDockerfile: |

116 changes: 102 additions & 14 deletions docs/api/v1/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [Webhook API](#webhook-api)
- [Stats API](#stats-api)
- [Cloud API](#cloud-api)
- [Template API](#template-api)
- [API Common](#api-common)
- [Path Parameter Explanation](#path-parameter-explanation)
- [API Details](#api-details)
Expand Down Expand Up @@ -42,6 +43,7 @@
- [List SCM Repos](#list-scm-repos)
- [List SCM Branches](#list-scm-branches)
- [List SCM Tags](#list-scm-tags)
- [Get SCM Repotype](#get-scm-repotype)
- [Github webhook](#github-webhook)
- [Gitlab webhook](#gitlab-webhook)
- [PipelineStatusStatsObject](#pipelinestatusstatsobject)
Expand All @@ -53,7 +55,10 @@
- [Get cloud](#get-cloud)
- [Update cloud](#update-cloud)
- [Delete cloud](#delete-cloud)
- [WorkerInstance](#workerinstance)
- [List cyclone workers](#list-cyclone-workers)
- [PipelineTemplateObject](#pipelinetemplateobject)
- [List pipeline templates](#list-pipeline-templates)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -125,13 +130,14 @@

### SCM API

- [Repo Object Object](#RepoObjectObject)
- [Repo Object](#RepoObject)

| API | Path | Detail |
| --- | --- | --- |
| List | GET `/api/v1/projects/{project}/repos` | [link](#list-scm-repos) |
| List | GET `/api/v1/projects/{project}/branches?repo=` | [link](#list-scm-branches) |
| List | GET `/api/v1/projects/{project}/tags?repo=` | WIP, [link](#list-scm-tags) |
| Get | GET `/api/v1/projects/{project}/templatetype?repo=` | WIP, [link](#get-scm-templatetype) |

### Webhook API

Expand Down Expand Up @@ -161,6 +167,13 @@
| Update | PUT `/api/v1/clouds/{cloud}` | WIP, [link](#update-cloud) |
| Delete | DELETE `/api/v1/clouds/{cloud}` | WIP, [link](#delete-cloud) |

### Template API

- [PipelineTemplateObject](#pipelinetemplateobject)

| API | Path | Detail |
| --- | --- | --- |
| List | GET `/api/v1/pipelinetemplates` | WIP, [link](#list-pipeline-templates) |
## API Common

### Path Parameter Explanation
Expand Down Expand Up @@ -1184,6 +1197,33 @@ Success:
}
```

### Get SCM Templatetype

Get the template type of the specific repo.

**Request**

URL: `GET /api/v1/projects/{project}/templatetype?repo=`

Note:

| Field | Note |
9E7A | --- | --- |
| repo | Required, repo for which the template type will be get |


**Response**

Success:

```
200 OK

{
"type": <type>
}
```

### Github webhook

Trigger pipeline by Github webhook.
Expand Down Expand Up @@ -1477,6 +1517,19 @@ Success:
204 No Content
```

### WorkerInstance
```
{
"name": "cyclone-worker-5b30a4e5488571000107261f",
"status": "Running",
"creationTime": "2018-06-25T16:16:37+08:00",
"lastUpdateTime": "2018-06-25T16:16:37+08:00",
"projectName": "project1",
"pipelineName" "pipeline1",
"recordID": "abcdef"
}
```

### List cyclone workers

List all cyclone workers.
Expand All @@ -1498,18 +1551,53 @@ Success:
```
200 OK

[
{
"name": "cyclone-worker-5b30a4e5488571000107261f",
"status": "Running",
"creationTime": "2018-06-25T16:16:37+08:00",
"lastUpdateTime": "2018-06-25T16:16:37+08:00"
{
"metadata": {
"total": 0, // number, always
},
{
"name": "cyclone-worker-5b31e3f1a482aa0001ae96ef",
"status": "Running",
"creationTime": "2018-06-26T14:57:53+08:00",
"lastUpdateTime": "2018-06-26T14:57:53+08:00"
}
]
"items": [ <WorkerInstance>, ... ]
}
```

### PipelineTemplateObject

```
{
"name": "python2.7", // string, required.
"type": "maven", // string, required.
"builderImage": "python:2.7-alpine", // string, required.
"testCommands": "", // string
"packageCommands": "2016-04-26T05:21:13.140Z", // string
"customizedDockerfile": "Dockerfile contents" // string
}
```


Note:

| Field | Note |
| --- | --- |
| type | Required, pipeline template type, Go, Maven, Gradle, NodeJS, Python and PHP. |

### List pipeline templates

List all cyclone pipeline templates.

**Request**

URL: `GET /api/v1/pipelinetemplates`

**Response**

Success:

```
200 OK

{
"metadata": {
"total": 0, // number, always
},
"items": [ <PipelineTemplateObject>, ... ]
}
```
32 changes: 32 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,35 @@ type WorkerInstance struct {
PipelineName string `bson:"pipelineName,omitempty" json:"pipelineName,omitempty" description:"name of the pipeline"`
RecordID string `bson:"recordID,omitempty" json:"recordID,omitempty" description:"id of the pipeline record"`
}

// Template contains some configurations of creating pipeline.
type Template struct {
Name string `yaml:"name,omitempty" json:"name,omitempty" description:"name of the template, should be unique"`
Type string `yaml:"type,omitempty" json:"type,omitempty" description:"type of the template"`
BuilderImage string `yaml:"builderImage,omitempty" json:"builderImage,omitempty" description:"image information of the builder"`
TestCommands string `yaml:"testCommands,omitempty" json:"testCommands,omitempty" description:"sample commands of unit test stage"`
PackageCommands string `yaml:"packageCommands,omitempty" json:"packageCommands,omitempty" description:"sample commands of package stage"`
CustomizedDockerfile string `yaml:"customizedDockerfile,omitempty" json:"customizedDockerfile,omitempty" description:"sample Dockerfile"`
}

// TemplateType represents the type of the template
type TemplateType struct {
Type string `yaml:"type,omitempty" json:"type,omitempty" description:"type of the template"`
}

const (
// JavaScriptRepoType represents the language type JavaScript.
JavaScriptRepoType string = "JavaScript"

// JavaRepoType represents the language type Java.
JavaRepoType string = "Java"

// MavenRepoType represents the repository type Maven.
MavenRepoType string = "Maven"

// GradleRepoType represents the repository type Gradle.
GradleRepoType string = "Gradle"

// NodeRepoType represents the repository type NodeJS.
NodeRepoType string = "NodeJS"
)
2 changes: 1 addition & 1 deletion pkg/docker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func TestRemoveContainer(t *testing.T) {
for d, tc := range testCases {
err := dm.RemoveContainer(tc.cid)
if !reflect.DeepEqual(err, tc.err) {
t.Errorf("Fail to remove container %d: expect err as %v, but got %v", d, tc.err, err)
t.Errorf("Fail to remove container %s: expect err as %v, but got %v", d, tc.err, err)
}
}
}
Expand Down
Loading
0