Skip to content

Commit f429646

Browse files
dw511214992Wei Dong
andauthored
clone sdk repo in grow up scenario (#3667)
* save * clone sdk repo in grow up scenario * lint fix * doc fix * clone spec repo in grow up * add skip-generation param in rerunning task * update doc * mute output * add new param --is-public-repo * lint * result change * fix test Co-authored-by: Wei Dong <[email protected]>
1 parent 3aa6382 commit f429646

File tree

19 files changed

+254
-54
lines changed

19 files changed

+254
-54
lines changed

tools/sdk-generation-pipeline/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ RUN apt-get install -y dotnet-sdk-6.0
4646
# install git
4747
RUN add-apt-repository ppa:git-core/ppa -y && apt update && apt upgrade -y && apt install git -y
4848
RUN git config --global credential.helper store && git config --global core.fileMode false
49-
5049
# install depended packages
5150
RUN pip3 install --upgrade wheel PyYAML requests
5251
RUN npm install -g typescript

tools/sdk-generation-pipeline/documents/docker/README.md

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The docker image will be used in different scenarios:
2121
Command
2222

2323
```shell
24-
docker run -it --privileged -v {local_spec_repo_path}:/spec-repo -v {local_work_folder}:/work-dir -v {local_autorest_config}:/autorest.md docker.image:latest --readme={relative_readme} --sdk={sdk_to_generate}
24+
docker run -it --privileged -v {local_spec_repo_path}:/spec-repo -v {local_work_folder}:/work-dir -v {local_autorest_config}:/autorest.md sdkgeneration.azurecr.io/sdk-generation:latest --readme={relative_readme} --sdk={sdk_to_generate}
2525
```
2626

2727
Parameter description:
@@ -36,13 +36,13 @@ Parameter description:
3636

3737
Example Command:
3838
```shell
39-
docker run -it --privileged -v /home/test/azure-rest-api-specs:/spec-repo -v /home/test/work-dir:/work-dir docker.image:latest --readme="specification/agrifood/resource-manager/readme.md" --sdk=js,java
39+
docker run -it --privileged -v /home/test/azure-rest-api-specs:/spec-repo -v /home/test/work-dir:/work-dir sdkgeneration.azurecr.io/sdk-generation:latest --readme="specification/agrifood/resource-manager/readme.md" --sdk=js,java
4040
```
4141

42-
After running command, docker container generates SDKs. When SDKs are generated, the docker container doesn't exit, and you can open your browser and request `http://127.0.0.1:8080/?folder=/work-dir` for further grow up development.
42+
After running command, docker container generates SDKs. When SDKs are generated, the docker container doesn't exit, and you can [open your local vscode and connect to docker container](./vscode-connect-docker-container.md) for further grow up development.
4343
If you want to re-generate codes after grow up development or changing swagger, please run command in docker container:
4444
```shell
45-
rerun-tasks -readme={relative_readme} --sdk={sdk_to_generate}
45+
rerun-tasks --readme={relative_readme} --sdk={sdk_to_generate}
4646
```
4747
rerun-tasks is a script, which invokes task engine to re-run tasks.
4848

@@ -53,41 +53,36 @@ There are two scenarios here:
5353
1. Service team has generated codes locally by using docker image and has exited the docker container. But they want to do grow up development now.
5454
2. Service team has generated codes by using sdk generation pipeline, and sdk generation pipeline creates a work branch. Service team hope to do grow up based on the work branch.
5555

56-
Compared to scenario 1, scenario 2 needs user to clone and checkout the work branch by themselves. It’s very simple with git:
56+
Run docker commands to do grow up development:
5757
```shell
58-
cd {local_work_folder}
59-
git clone -b {work-branch} {repo-url}
58+
docker run -it --privileged -v {local_spec_repo_path}:/spec-repo -v {local_work_folder}:/work-dir -v {local_autorest_config}:/autorest.md sdkgeneration.azurecr.io/sdk-generation:latest --readme={relative_readme} --spec-link={spec-link} --sdk-work-branch={sdk-work-branch-link}
6059
```
6160
Parameter description:
6261

63-
| Parameter | Description | Example |
64-
|-----------------------|-----------------------------------------------------------------------------------------|-----------------------------------------------|
65-
| { local_work_folder } | Required. It's used to point to the work folder, which stores all sdk repositories. | /home/test/work-dir |
66-
| {work_branch } | Required. It's used to point the work branch name generated by SDK generation pipeline. | sdkAuto/workbranch |
67-
| {repo_url} | Required. It's used to point the repository url that work branch is in. | https://github.com/Azure/azure-sdk-for-js.git |
62+
| Parameter | Description | Example |
63+
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
64+
| { local_spec_repo_path } | Optional. If you want to change the swagger and re-generate codes, you need to mount the swagger repo. If you only want to do grow up development, no need to mount it. If you input a the link by parameter {spec-link}, docker container helps clone it. | /home/test/azure-rest-api-specs |
65+
| { local_work_folder } | Required. It's used to point to the work folder, which stores all sdk repositories. | /home/test/work-dir |
66+
| { local_autorest_config } | Optional. When you generate data-plane sdk, and there is no autorest configuration in sdk repository or you want to change the autorest configuration, you can set new autorest config in a file and mount it to the docker container. About the content of file, please refer to [document](https://github.com/Azure/azure-rest-api-specs/blob/dpg-doc/documentation/onboard-dpg-in-sdkautomation/add-autorest-configuration-in-spec-comment.md) | /home/test/autorest.md ([Example file](./autorest-config-file-sample.md)) |
67+
| { relative_readme } | Optional. It's used to specify the readme.md file and docker image uses it to start mock server. it's the relative path from {path_to_local_spec_repo}. If not specified, mock server will not start. | specification/agrifood/resource-manager/readme.md |
68+
| { sdk-work-branch-link } | **Only Required in Scenario 2**. It's used to specify the link to sdk work branch generated by sdk generation pipeline, and docker container will use it to clone sdk repo and checkout the work branch. **In scenario 2, please make sure there is no corresponding sdk repo under {local_work_folder}.** | specification/agrifood/resource-manager/readme.md |
69+
| { spec-link } | **Only Required in Scenario 2 and no local repo mounted**. It's used to specify the link to spec repo, which can be PR link, repo Link or branch link. Then docker container will use it to clone spec repo and checkout the properly branch. **In scenario 2, please make sure there is no corresponding spec repo with path '/spec-repo' in docker container.** | specification/agrifood/resource-manager/readme.md |
6870

69-
Then run docker commands to do grow up development:
71+
Example Command:
72+
Scenario 1:
7073
```shell
71-
docker run -it --privileged -v {local_spec_repo_path}:/spec-repo -v {local_work_folder}:/work-dir -v {local_autorest_config}:/autorest.md docker.image:latest --readme={relative_readme}
74+
docker run -it --privileged -v /home/test/azure-rest-api-specs:/spec-repo -v /home/test/work-dir:/work-dir sdkgeneration.azurecr.io/sdk-generation:latest --readme="specification/agrifood/resource-manager/readme.md"
7275
```
73-
Parameter description:
7476

75-
| Parameter | Description | Example |
76-
|----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
77-
| { local_spec_repo_path } | Optional. If you want to change the swagger and re-generate codes, you need to mount the swagger repo. If you only want to do grow up development, no need to mount it. | /home/test/azure-rest-api-specs |
78-
| { local_work_folder } | Required. It's used to point to the work folder, which stores all sdk repositories. | /home/test/work-dir |
79-
| { local_autorest_config } | Optional. When you generate data-plane sdk, and there is no autorest configuration in sdk repository or you want to change the autorest configuration, you can set new autorest config in a file and mount it to the docker container. About the content of file, please refer to [document](https://github.com/Azure/azure-rest-api-specs/blob/dpg-doc/documentation/onboard-dpg-in-sdkautomation/add-autorest-configuration-in-spec-comment.md) | /home/test/autorest.md ([Example file](./autorest-config-file-sample.md)) |
80-
| { relative_readme } | Optional. It's used to specify the readme.md file and docker image uses it to start mock server. it's the relative path from {path_to_local_spec_repo}. If not specified, mock server will not start. | specification/agrifood/resource-manager/readme.md |
81-
82-
Example Command:
77+
Scenario 2:
8378
```shell
84-
docker run -it --privileged -v /home/test/azure-rest-api-specs:/spec-repo -v /home/test/work-dir:/work-dir docker.image:latest
79+
docker run -it --privileged -v /home/test/work-dir:/work-dir sdkgeneration.azurecr.io/sdk-generation:latest --readme="specification/agrifood/resource-manager/readme.md" --spec-link="https://github.com/Azure/azure-rest-api-specs/pull/19850" --sdk-work-branch="https://github.com/Azure/azure-sdk-for-js/tree/agrifood/dev/branch"
8580
```
8681

87-
After running command, docker container generates SDKs. When SDKs are generated, the docker container doesn't exit, and you can open your browser and request `http://127.0.0.1:8080/?folder=/work-dir` for further grow up development.
82+
After running command, docker container generates SDKs. When SDKs are generated, the docker container doesn't exit, and you can [open your local vscode and connect to docker container](./vscode-connect-docker-container.md) for further grow up development.
8883
If you want to re-generate codes after grow up development or changing swagger, please run command in docker container:
8984
```shell
90-
rerun-tasks -readme={relative_readme} --sdk={sdk_to_generate}
85+
rerun-tasks --readme={relative_readme} --sdk={sdk_to_generate}
9186
```
9287
rerun-tasks is a script, which invokes task engine to re-run tasks.
9388

@@ -101,7 +96,7 @@ Before running docker command, pipeline must prepare the spec repo and sdk repo.
10196
Command:
10297

10398
```shell
104-
docker run --privileged -v {spec_repo_path}:/spec-repo -v {sdk_repo_path}:/sdk-repo -v {local_autorest_config}:/autorest.md -v {output_folder_path}:/tmp/output docker.image:latest --readme={relative_readme}
99+
docker run --privileged -v {spec_repo_path}:/spec-repo -v {sdk_repo_path}:/sdk-repo -v {local_autorest_config}:/autorest.md -v {output_folder_path}:/tmp/output sdkgeneration.azurecr.io/sdk-generation:latest --readme={relative_readme}
105100
```
106101

107102
Parameter description:
@@ -115,7 +110,7 @@ Parameter description:
115110

116111
Example Command:
117112
```shell
118-
docker run --privileged -v /home/vsts/work/azure-rest-api-specs:/spec-repo -v /home/vsts/work/azure-sdk-for-js:/sdk-repo -v /home/vsts/work/output:/tmp/output docker.image:latest --readme=specification/agrifood/resource-manager/readme.md
113+
docker run --privileged -v /home/vsts/work/azure-rest-api-specs:/spec-repo -v /home/vsts/work/azure-sdk-for-js:/sdk-repo -v /home/vsts/work/output:/tmp/output sdkgeneration.azurecr.io/sdk-generation:latest --readme=specification/agrifood/resource-manager/readme.md
119114
```
120115

121116
After running the command in pipeline, docker will execute tasks automatically. Also, there will be output files generated, which will be used by pipeline's other job, such as upload codes, parsing logs.

tools/sdk-generation-pipeline/documents/task-engine/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ Input file for generate and build script.
7272
"headRef": "refs/pull/1234/merge",
7373
"repoHttpsUrl": "https://github.com/Azure/azure-rest-api-specs.git",
7474
"relatedReadmeMdFile": "compute/resource-manager/readme.md"
75-
"serviceType": "resource-manager"
75+
"serviceType": "resource-manager",
76+
"skipGeneration": "false"
7677
}
7778
```
7879

tools/sdk-generation-pipeline/documents/task-engine/schema/GenerateAndBuildInputSchema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
// The type of related swagger: resource-manager or data-plane
2828
"type": "string",
2929
"enum": ["resource-manager", "data-plane"]
30+
},
31+
"autorestConfig": {
32+
// The autorest config got from /autorest.md, which is mounted by user
33+
"type": "string"
34+
},
35+
"skipGeneration": {
36+
// Whether skip generation
37+
"type": "boolean"
3038
}
3139
},
3240
"required": ["specFolder", "headSha", "headRef", "repoHttpsUrl", "relatedReadmeMdFile"]

tools/sdk-generation-pipeline/packages/sdk-generation-cli/src/cli/dockerCli/core/DockerContext.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export class DockerContext {
1717
sdkRepo?: string;
1818
resultOutputFolder?: string;
1919
autorestConfigFilePath?: string;
20+
specLink?: string;
21+
sdkWorkBranchLink?: string;
22+
skipGeneration: boolean;
23+
isPublicRepo: boolean;
2024
logger: Logger;
2125

2226
/*
@@ -34,22 +38,40 @@ export class DockerContext {
3438
this.sdkRepo = inputParams.sdkRepo;
3539
this.resultOutputFolder = inputParams.resultOutputFolder;
3640
this.autorestConfigFilePath = inputParams.autorestConfigFilePath;
41+
this.specLink = inputParams.specLink;
42+
this.sdkWorkBranchLink = inputParams.sdkWorkBranchLink;
43+
this.skipGeneration = inputParams.skipGeneration;
3744
this.logger = initializeLogger(path.join(inputParams.resultOutputFolder, inputParams.dockerLogger), 'docker');
3845

3946
if (this.sdkList?.length === 0 && fs.existsSync(this.workDir)) {
4047
this.logger.info('Preparing environment to do grow up development');
4148
this.mode = DockerRunningModel.GrowUp;
42-
this.validateSpecRepo();
49+
this.isPublicRepo = false;
50+
if (!this.specLink) {
51+
try {
52+
this.validateSpecRepo();
53+
} catch (e) {
54+
throw new Error(`Cannot get spec repo link by parameter --spec-link, or get mounted swagger repo.`);
55+
}
56+
} else {
57+
this.validateSpecLink();
58+
}
59+
4360
this.validateWorkDir();
61+
if (!!this.sdkWorkBranchLink) {
62+
this.validateWorkBranchLink();
63+
}
4464
} else if (fs.existsSync(this.workDir)) {
4565
this.logger.info('Preparing environment to generate codes and do grow up development in local');
4666
this.mode = DockerRunningModel.CodeGenAndGrowUp;
67+
this.isPublicRepo = false;
4768
this.validateSpecRepo();
4869
this.validateReadmeMdPath();
4970
this.validateSdk();
5071
} else {
5172
this.logger.info('Preparing environment to generate codes in pipeline');
5273
this.mode = DockerRunningModel.Pipeline;
74+
this.isPublicRepo = inputParams.isPublicRepo;
5375
this.validateSdkRepo();
5476
this.validateSpecRepo();
5577
this.validateReadmeMdPath();
@@ -102,4 +124,18 @@ export class DockerContext {
102124
throw new Error(`Cannot find ${this.resultOutputFolder}, please mount it to docker container`);
103125
}
104126
}
127+
128+
private validateWorkBranchLink() {
129+
const match = this.sdkWorkBranchLink.match(/(https.*\/([^\/]*))\/tree\/(.*)/);
130+
if (match?.length !== 4) {
131+
throw new Error(`Get invalid sdk work branch link: ${this.sdkWorkBranchLink}`);
132+
}
133+
}
134+
135+
private validateSpecLink() {
136+
const match = this.specLink.match(/http.*/);
137+
if (!match) {
138+
throw new Error(`Get invalid sdk work branch link: ${this.specLink}`);
139+
}
140+
}
105141
}

0 commit comments

Comments
 (0)