Skip to content

Commit

Permalink
Build Extension in Template (#110)
Browse files Browse the repository at this point in the history
* Build extension using a template

* Update build template in run test
  • Loading branch information
jonathan-innis authored Mar 17, 2022
1 parent 3be9ccb commit 0fbfcd5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 84 deletions.
58 changes: 5 additions & 53 deletions testing/pipeline/k8s-custom-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ stages:
RESOURCE_GROUP: "K8sPartnerExtensionTest"
BASE_CLUSTER_NAME: "k8s-extension-cluster"
IS_PRIVATE_BRANCH: $[or(eq(variables['Build.SourceBranch'], 'refs/heads/k8s-extension/private'), eq(variables['System.PullRequest.TargetBranch'], 'k8s-extension/private'))]

EXTENSION_NAME: "k8s-extension"
EXTENSION_FILE_NAME: "k8s_extension"
jobs:
- template: ./templates/run-test.yml
parameters:
Expand Down Expand Up @@ -54,58 +51,13 @@ stages:
displayName: "Build and Publish the Extension Artifact"
variables:
CLI_REPO_PATH: $(Agent.BuildDirectory)/s
steps:
- bash: |
echo "Using the private preview of k8s-extension to build..."
cp $(CLI_REPO_PATH)/src/k8s-extension $(CLI_REPO_PATH)/src/k8s-extension-private -r
mv $(CLI_REPO_PATH)/src/k8s-extension-private/azext_k8s_extension $(CLI_REPO_PATH)/src/k8s-extension-private/azext_k8s_extension_private
cp $(CLI_REPO_PATH)/src/k8s-extension-private/setup_private.py $(CLI_REPO_PATH)/src/k8s-extension-private/setup.py
cp $(CLI_REPO_PATH)/src/k8s-extension-private/azext_k8s_extension_private/consts_private.py $(CLI_REPO_PATH)/src/k8s-extension-private/azext_k8s_extension_private/consts.py
EXTENSION_NAME="k8s-extension-private"
EXTENSION_FILE_NAME="k8s_extension_private"
echo "##vso[task.setvariable variable=EXTENSION_NAME]$EXTENSION_NAME"
echo "##vso[task.setvariable variable=EXTENSION_FILE_NAME]$EXTENSION_FILE_NAME"
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'True'))
displayName: "Copy Files, Set Variables for k8s-extension-private"
- bash: |
echo "Using the public version of k8s-extension to build..."
EXTENSION_NAME="k8s-extension"
EXTENSION_FILE_NAME="k8s_extension"
echo "##vso[task.setvariable variable=EXTENSION_NAME]$EXTENSION_NAME"
echo "##vso[task.setvariable variable=EXTENSION_FILE_NAME]$EXTENSION_FILE_NAME"
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'False'))
displayName: "Copy Files, Set Variables for k8s-extension"
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
echo "Building extension ${EXTENSION_NAME}..."
# prepare and activate virtualenv
pip install virtualenv
python3 -m venv env/
source env/bin/activate
# clone azure-cli
git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install -q azdev
ls $(CLI_REPO_PATH)
azdev --version
azdev setup -c ../azure-cli -r $(CLI_REPO_PATH) -e $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
workingDirectory: $(CLI_REPO_PATH)
displayName: "Setup and Build Extension with azdev"
steps:
- template: ./templates/build-extension.yml
parameters:
CLI_REPO_PATH: $(CLI_REPO_PATH)
IS_PRIVATE_BRANCH: $(IS_PRIVATE_BRANCH)
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(CLI_REPO_PATH)/dist
Expand Down
52 changes: 52 additions & 0 deletions testing/pipeline/templates/build-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
parameters:
CLI_REPO_PATH: ""
steps:
- bash: |
echo "Using the private preview of k8s-extension to build..."
cp ${{ parameters.CLI_REPO_PATH }}/src/k8s-extension ${{ parameters.CLI_REPO_PATH }}/src/k8s-extension-private -r
mv ${{ parameters.CLI_REPO_PATH }}/src/k8s-extension-private/azext_k8s_extension ${{ parameters.CLI_REPO_PATH }}/src/k8s-extension-private/azext_k8s_extension_private
cp ${{ parameters.CLI_REPO_PATH }}/src/k8s-extension-private/setup_private.py ${{ parameters.CLI_REPO_PATH }}/src/k8s-extension-private/setup.py
cp ${{ parameters.CLI_REPO_PATH }}/src/k8s-extension-private/azext_k8s_extension_private/consts_private.py ${{ parameters.CLI_REPO_PATH }}/src/k8s-extension-private/azext_k8s_extension_private/consts.py
EXTENSION_NAME="k8s-extension-private"
EXTENSION_FILE_NAME="k8s_extension_private"
echo "##vso[task.setvariable variable=EXTENSION_NAME]$EXTENSION_NAME"
echo "##vso[task.setvariable variable=EXTENSION_FILE_NAME]$EXTENSION_FILE_NAME"
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'True'))
displayName: "Copy Files, Set Variables for k8s-extension-private"
- bash: |
echo "Using the public version of k8s-extension to build..."
EXTENSION_NAME="k8s-extension"
EXTENSION_FILE_NAME="k8s_extension"
echo "##vso[task.setvariable variable=EXTENSION_NAME]$EXTENSION_NAME"
echo "##vso[task.setvariable variable=EXTENSION_FILE_NAME]$EXTENSION_FILE_NAME"
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'False'))
displayName: "Copy Files, Set Variables for k8s-extension"
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
echo "Building extension ${EXTENSION_NAME}..."
# prepare and activate virtualenv
pip install virtualenv
python3 -m venv env/
source env/bin/activate
# clone azure-cli
git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install -q azdev
ls ${{ parameters.CLI_REPO_PATH }}
azdev --version
azdev setup -c ../azure-cli -r ${{ parameters.CLI_REPO_PATH }} -e $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
44 changes: 13 additions & 31 deletions testing/pipeline/templates/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ jobs:
- job: ${{ parameters.jobName}}
pool:
vmImage: 'ubuntu-latest'
variables:
${{ if eq(variables['IS_PRIVATE_BRANCH'], 'False') }}:
EXTENSION_NAME: "k8s-extension"
EXTENSION_FILE_NAME: "k8s_extension"
${{ if ne(variables['IS_PRIVATE_BRANCH'], 'False') }}:
EXTENSION_NAME: "k8s-extension-private"
EXTENSION_FILE_NAME: "k8s_extension_private"
steps:
- bash: |
echo "Installing helm3"
Expand All @@ -19,33 +26,9 @@ jobs:
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
displayName: "Setup the VM with helm3 and kubectl"
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.6
- bash: |
set -ev
echo "Building extension ${EXTENSION_NAME}..."
# prepare and activate virtualenv
pip install virtualenv
python3 -m venv env/
source env/bin/activate
# clone azure-cli
git clone -q --single-branch -b dev https://github.com/Azure/azure-cli.git ../azure-cli
pip install --upgrade pip
pip install -q azdev
ls $(CLI_REPO_PATH)
azdev --version
azdev setup -c ../azure-cli -r $(CLI_REPO_PATH) -e $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
workingDirectory: $(CLI_REPO_PATH)
displayName: "Setup and Build Extension with azdev"
- template: ./build-extension.yml
parameters:
CLI_REPO_PATH: $(CLI_REPO_PATH)
- bash: |
K8S_EXTENSION_VERSION=$(ls ${EXTENSION_FILE_NAME}* | cut -d "-" -f2)
echo "##vso[task.setvariable variable=K8S_EXTENSION_VERSION]$K8S_EXTENSION_VERSION"
Expand All @@ -64,11 +47,11 @@ jobs:
--arg AKS_CLUSTER_NAME "$AKS_CLUSTER_NAME" \
--arg ARC_CLUSTER_NAME "$ARC_CLUSTER_NAME" \
--arg K8S_EXTENSION_VERSION "$K8S_EXTENSION_VERSION" \
'{subscriptionId: $SUB_ID, resourceGroup: $RG, aksClusterName: $AKS_CLUSTER_NAME, arcClusterName: $ARC_CLUSTER_NAME, extensionVersion: {"k8s-extension": $K8S_EXTENSION_VERSION, connectedk8s: "1.0.0"}}')
'{subscriptionId: $SUB_ID, resourceGroup: $RG, aksClusterName: $AKS_CLUSTER_NAME, arcClusterName: $ARC_CLUSTER_NAME, extensionVersion: {"k8s-extension": $K8S_EXTENSION_VERSION, "k8s-extension-private": $K8S_EXTENSION_VERSION, connectedk8s: "1.0.0"}}')
echo $JSON_STRING > settings.json
cat settings.json
workingDirectory: $(TEST_PATH)
displayName: "Generate a settings.json file"
displayName: "Generate a settings.json file"
- bash : |
echo "Downloading the kind script"
Expand Down Expand Up @@ -98,10 +81,9 @@ jobs:
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
.\Test.ps1 -CI -Path ${{ parameters.path }} -Type k8s-extension
.\Test.ps1 -CI -Path ${{ parameters.path }} -Type $(EXTENSION_NAME)
workingDirectory: $(TEST_PATH)
continueOnError: true
condition: and(succeeded(), eq(variables['IS_PRIVATE_BRANCH'], 'False'))

- task: PublishTestResults@2
inputs:
Expand Down

0 comments on commit 0fbfcd5

Please sign in to comment.