Skip to content

Commit 973304c

Browse files
committed
adjusted the repo structure to include azure_pipeline task
1 parent 1de7c3a commit 973304c

38 files changed

+885
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build and Release for Azure Pipeline
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Set up Node.js
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: '14'
18+
19+
- name: Install dependencies and build
20+
run: |
21+
cd ./src
22+
npm install
23+
cd ..
24+
25+
- name: Install tfx-cli
26+
run: |
27+
npm install -g tfx-cli
28+
29+
- name: Create extension
30+
run: |
31+
tfx extension create --manifest-globs vss-extension.json
32+
33+
- name: Upload VSIX file
34+
uses: actions/upload-artifact@v2
35+
with:
36+
name: VSIX file
37+
path: ./*.vsix

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
azure_pipeline/src/dist/
2+
azure_pipeline/src/node_modules/
3+
azure_pipeline/src/package-lock.json

azure_pipeline/development.md

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# Azure Pipeline task: NGINX for Azure Configuration Push (Development Guide)
2+
3+
4+
For the developing and publishing of the pipeline task, there are two ways to build and update the Azure DevOps pipeline tasks onto the market place if there are any new fixes or patches.
5+
6+
## Plan A. Manual Update
7+
8+
### Step 1. Get vss-extension.json ready for packaging
9+
10+
Vss-extension.json defines all information about your extension that will be displayed in the marketplace.
11+
12+
Please not that the name and id of this file is not finalized.
13+
14+
```
15+
16+
// vss-extension.json
17+
18+
{
19+
"manifestVersion": 1,
20+
"id": "zao-nginx-config-push",
21+
"name": "zao-nginx-config-push",
22+
"version": "0.2.6",
23+
"publisher": "zaotest",
24+
"targets": [
25+
{
26+
"id": "Microsoft.VisualStudio.Services"
27+
}
28+
],
29+
"description": "Zao's tool for uploading nginx config",
30+
"categories": [
31+
"Azure Pipelines"
32+
],
33+
"icons": {
34+
"default": "images/extension-icon.png"
35+
},
36+
"files": [
37+
{
38+
"path": "src"
39+
}
40+
],
41+
"contributions": [
42+
{
43+
"id": "custom-build-release-task",
44+
"type": "ms.vss-distributed-task.task",
45+
"targets": [
46+
"ms.vss-distributed-task.tasks"
47+
],
48+
"properties": {
49+
"name": "src"
50+
}
51+
}
52+
],
53+
"galleryFlags": [
54+
"Public"
55+
],
56+
"public": false,
57+
"tags":[
58+
"Build task",
59+
"Deploy task"
60+
]
61+
}
62+
63+
```
64+
65+
66+
If this is the first time you are publishing the extension onto the marketplace, make sure the following keys have corresponded and correct value: id, name, publisher, description, icons. Otherwise, if this is just a normal update, all you need to do is just to make sure that the version number is updated to a greater one.
67+
68+
For more details about vss-extension.json, please refer to ([Extension Manifest Reference - Azure DevOps | Microsoft Docs](https://docs.microsoft.com/en-us/azure/devops/extend/develop/manifest?view=azure-devops))
69+
70+
### Step 2. Package the extension
71+
72+
The whole project can be easily packaged by running the following single command:
73+
74+
```
75+
tfx extension create --manifest-globs vss-extension.json
76+
```
77+
78+
Now we will have a .vsix file generated automatically and ready for uploading to the marketplace portal.
79+
80+
If this is the first time you are using this command, you may need to install tfx-cli by:
81+
82+
```
83+
npm install -g tfx-cli
84+
```
85+
86+
### Step 3. Upload the .vsix file onto the marketplace
87+
88+
Sign in the Visual Studio Marketplace Publishing Portal. A normal update will be as easy as clicking the Update button of your extension and drag your .visx generated just now into it.
89+
90+
![Image](images/readme-marketplace.png)
91+
92+
93+
There will be a verification process running as soon as you uploaded the .visx file. Once the verification is completed, the Marketplace Publishing Portal will automatically update your extension to the newest version.
94+
95+
However, if this is the first time you are publishing the pipeline extension, please refer to Step 5: Publish your extension [Add a build or release task in an extension - Azure DevOps | Microsoft Docs](https://docs.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops#create-your-publisher) to learn about how to create a new publisher account.
96+
97+
98+
## Plan B. Pipelined Update
99+
100+
You can also set up an Azure pipeline to automate the updating and releasing process with the following template:
101+
102+
```
103+
# build.yml
104+
# This is an example pipeline if we need a pipeline to update the task onto the market place
105+
# If we use manual update, this will not be needed.
106+
107+
trigger:
108+
- main
109+
110+
pool:
111+
vmImage: "ubuntu-latest"
112+
113+
variables:
114+
PublisherID:
115+
ExtensionID:
116+
ExtensionName:
117+
ExtensionVersion:
118+
ArtifactStagingDirectory: './artifact'
119+
ArtifactName: 'extension_artifact'
120+
121+
122+
123+
stages:
124+
- stage: Package_extension_and_publish_build_artifacts
125+
jobs:
126+
- job:
127+
steps:
128+
- task: TfxInstaller@3
129+
inputs:
130+
version: "v0.7.x"
131+
- task: Npm@1
132+
inputs:
133+
command: 'install'
134+
workingDir: './src' # Update to the name of the directory of your task
135+
- task: Bash@3
136+
displayName: Compile Javascript
137+
inputs:
138+
targetType: "inline"
139+
script: |
140+
cd src # Update to the name of the directory of your task
141+
tsc
142+
- task: QueryAzureDevOpsExtensionVersion@3
143+
inputs:
144+
connectTo: 'VsTeam'
145+
connectedServiceName: 'release-test-connection' # Change to whatever you named the service connection
146+
publisherId: '$(PublisherID)'
147+
extensionId: '$(ExtensionID)'
148+
versionAction: 'Patch'
149+
outputVariable: 'Task.Extension.Version'
150+
- task: PackageAzureDevOpsExtension@3
151+
inputs:
152+
rootFolder: '$(System.DefaultWorkingDirectory)'
153+
publisherId: '$(PublisherID)'
154+
extensionId: '$(ExtensionID)'
155+
extensionName: '$(ExtensionName)'
156+
extensionVersion: '$(ExtensionVersion)'
157+
updateTasksVersion: true
158+
updateTasksVersionType: 'patch'
159+
extensionVisibility: 'private' # Change to public if you're publishing to the marketplace
160+
extensionPricing: 'free'
161+
- task: CopyFiles@2
162+
displayName: "Copy Files to: $(ArtifactStagingDirectory)"
163+
inputs:
164+
Contents: "**/*.vsix"
165+
TargetFolder: "$(ArtifactStagingDirectory)"
166+
- task: PublishBuildArtifacts@1
167+
inputs:
168+
PathtoPublish: '$(ArtifactStagingDirectory)'
169+
ArtifactName: '$(ArtifactName)'
170+
publishLocation: 'Container'
171+
- stage: Download_build_artifacts_and_publish_the_extension
172+
jobs:
173+
- job:
174+
steps:
175+
- task: TfxInstaller@3
176+
inputs:
177+
version: "v0.7.x"
178+
- task: DownloadBuildArtifacts@0
179+
inputs:
180+
buildType: "current"
181+
downloadType: "single"
182+
artifactName: "$(ArtifactName)"
183+
downloadPath: "$(System.DefaultWorkingDirectory)"
184+
- task: PublishAzureDevOpsExtension@3
185+
inputs:
186+
connectTo: 'VsTeam'
187+
connectedServiceName: 'release-test-connection' # Change to whatever you named the service connection
188+
fileType: 'vsix'
189+
vsixFile: '$(PublisherID).$(ExtensionName)/$(PublisherID)..vsix'
190+
publisherId: '$(PublisherID)'
191+
extensionId: '$(ExtensionID)'
192+
extensionName: '$(ExtensionName)'
193+
updateTasksVersion: false
194+
extensionVisibility: 'private' # Change to public if you're publishing to the marketplace
195+
extensionPricing: 'free'
196+
197+
```
198+
199+
200+
This will allow the pipeline automatically start building the package and update the extension onto the marketplace.
201+
202+
However, in order to enable this pipeline, you may need to:
203+
204+
### Step 1. Create an organization as well as a project on Azure DevOps.
205+
206+
See [Create a project - Azure DevOps | Microsoft Docs](https://docs.microsoft.com/en-us/azure/devops/organizations/projects/create-project?tabs=browser&view=azure-devops).
207+
208+
### Step 2. Install Azure DevOps Extension Task to your Azure DevOps organization.
209+
210+
See [Azure DevOps Extension Tasks - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=ms-devlabs.vsts-developer-tools-build-tasks&targetId=85fb3d5a-9f21-420f-8de3-fc80bf29054b&utm_source=vstsproduct&utm_medium=ExtHubManageList).
211+
212+
### Step 3. Generate a personal access token on Azure DevOps.
213+
214+
This token will be used later when we create a service connection. Configure the authorization scope for the token as follows or refer to [Azure DevOps Extension Tasks - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=ms-devlabs.vsts-developer-tools-build-tasks&targetId=85fb3d5a-9f21-420f-8de3-fc80bf29054b&utm_source=vstsproduct&utm_medium=ExtHubManageList).
215+
216+
![Image](images/readme-personal-access-token.png)
217+
218+
![Image](images/readme-token-scopes.png)
219+
220+
221+
### Step 4. Create a service connection in order to authorize the pipeline’s agent for accessing Visual Studio MarketPlace.
222+
223+
On how to create a service connection, see [Service connections in Azure Pipelines - Azure Pipelines | Microsoft Docs](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?tabs=yaml&view=azure-devops). Note that you may need to select Visual Studio Marketplace for the service connection type.
224+
225+
![Image](images/readme-service-connections.png)
226+
227+
228+
### Step 5. Compose the .yml file.
229+
230+
After all the previous steps, you are now able to create a build and release pipeline using the template we mentioned at the beginning. This task will be automatically packaged and updated to the marketplace once the pipeline is triggered.

azure_pipeline/example.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trigger:
2+
- main
3+
4+
pool:
5+
vmImage: ubuntu-latest
6+
7+
steps:
8+
- task: nginx-config-push@0
9+
inputs:
10+
serviceConnectionName: '(sercive-connection-name)'
11+
resourceGroupName: '(resource-group-name)'
12+
subscriptionId: '(subscription-id)'
13+
deploymentName: '(deployment-name)'
14+
sourceConfigFolderPath: '(config-folder-file-path)'
15+
targetConfigFolderPath: '/etc/nginx/'
16+
5.63 KB
Loading
37 KB
Loading
82.7 KB
Loading
28.5 KB
Loading
30.7 KB
Loading
71 KB
Loading
43.6 KB
Loading
Loading
Loading
117 KB
Loading

azure_pipeline/readme.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Azure Pipeline task: NGINX for Azure Configuration Push
2+
3+
## Overview
4+
5+
This is a customed Azure pipeline task that automates the process of synchronizing NGINX configuration files. With this pipeline, the configuration files that are stored and managed in Azure DevOps or GitHub repositories can now be automatically packaged and uploaded to NGINX for Azure deployments.
6+
7+
When creating and updatding the configuration of a NGINX for Azure deployment, an automated pipeline task would be very helpful. There are three main advantages of a pipeline task compared to a manual updation:
8+
9+
##### 1. Automation.
10+
11+
A pipeline task can be triggered immediately if designated NGINX coniguration files have changes. This would increase effectiveness when there are frequent modifications and updates.
12+
13+
##### 2. Version control.
14+
15+
NGINX configuration files could be stored in GitHub or Azure DevOps repositories. In this way, all configure changes would be able to be traced and rolled back if there is a mistake.
16+
17+
##### 3. Security.
18+
Pipelines are running in secured and reliable agents, where data is transmitted within Azure services, hence reduced unnecessary data distribution and delivery.
19+
20+
NGINX for Azure currently supports both <strong>GitHub Action </strong>pipeline and <strong>Azure DevOps</strong> pipeline task. While there are some authentication and repository supporting difference, the purpose and functionality of the two pipelines have no essential distinction. For details on GitHub Action pipeline, please check out NGINX for Azure Deployment Action for more details. For Azure DevOps pipeline task, please follow the instructions below.
21+
22+
### Pipeline Task Set-up Guideline
23+
24+
Basically, all that the pipeline task needed is a .yml task written as follows,
25+
26+
```
27+
# example.yml
28+
29+
trigger:
30+
- main
31+
32+
pool:
33+
vmImage: ubuntu-latest
34+
35+
steps:
36+
- task: nginx-config-push@0
37+
inputs:
38+
serviceConnectionName: '(sercive-connection-name)'
39+
resourceGroupName: '(resource-group-name)'
40+
subscriptionId: '(subscription-id)'
41+
deploymentName: '(deployment-name)'
42+
sourceConfigFolderPath: '(config-folder-file-path)'
43+
targetConfigFolderPath: '/etc/nginx/'
44+
45+
```
46+
47+
What is needed right now is to get values of the needed variables with following steps:
48+
49+
50+
##### 1. Get your NGINX configuration file ready in the repository.
51+
52+
Upload your NGINX configuration files onto any folder of your Azure DevOps repository. Then update the ‘sourceConfigFolderPath’ to the path of the configuration folder in your repository. Note that the name of the main file of the NGINX configuration folder should be “nginx.conf”, and the ‘targetConfigFolderPath’ would usually be /etc/nginx/.
53+
54+
![Image](images/readme-guidline-01.png)
55+
56+
57+
##### 2. Make sure your NGINX for Azure deployment is working properly.
58+
59+
Deploy a NGINX for Azure resource. See Deploy NGINX for Azure | NGINX for Azure Docs. Once your deployment is ready, you will be able to fill in the “resourceGroupName”, “subscriptionId” and the “deploymentName” variable from the portal overview board.
60+
61+
![Image](images/readme-guidline-02.png)
62+
63+
64+
65+
##### 3. Create a service connetion and grant permission for the pipeline.
66+
67+
This part would require a little bit more work to set up.
68+
A service connection gives you access to resources in your Azure subscription from your Azure DevOps project.
69+
1. In Azure DevOps, go to the project that contains your target pipeline. In the lower-left corner, select Project settings.
70+
2. Under Pipelines, select Service connections. In the upper-right corner, select New service connection.
71+
3. In New service connection, select Azure Resource Manager.
72+
73+
![Image](images/readme-guidline-03.png)
74+
75+
4. In the Authentication method dialog, select Service principal (automatic) to create a new service principal or select Service principal (manual) to use an existing service principal.
76+
5. Enter your subscription and resource and a name for your service connection.
77+
78+
Also, you may need to assign a proper role assignment to the service connection so that our pipeline can access NGINX for azure deployments. You can add Contributor as your role assignment to this service connection.
79+
80+
![Image](images/readme-guidline-04.png)
81+
82+
83+
Go back to the Azure DevOps project settings and click into the “service connection” tab. Remember the name displayed in the service connections list. This will be the value of ‘serciveConnectionName’ in the .yml file.
84+
85+
![Image](images/readme-guidline-05.png)
86+
87+
88+
##### 4. Install the pipeline task and fill all the needed variables into the .yml file on Azure DevOps.
89+
90+
Go to marketplace and search our pipeline task. Once you have the extension installed on your Azure DevOps organization, you will be able to create a pipeline task with the stated .yml file template and use our customized task conveniently. You can also use text editor of the pipeline to utilize a simple UI of this pipeline task.
91+
92+
<br />
93+
<br />
94+
95+
That's it! Once you have all the above settings done and a pipeline created on the Azure DevOps, your NGINX configuration will be automatically updated to your designated NGINX for Azure deployment resource once you have any changes to the files in the repository and the pipeline is triggered.

0 commit comments

Comments
 (0)