From 72df1c5f010faa1be7748729d78f888e31ca6b96 Mon Sep 17 00:00:00 2001 From: Anupama Tuli Date: Wed, 30 Oct 2019 15:42:56 -0700 Subject: [PATCH 1/2] Adding a template for pull request workflow --- .github/workflows/pullrequest.yml.template | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/pullrequest.yml.template diff --git a/.github/workflows/pullrequest.yml.template b/.github/workflows/pullrequest.yml.template new file mode 100644 index 000000000..2dcbfaa0f --- /dev/null +++ b/.github/workflows/pullrequest.yml.template @@ -0,0 +1,76 @@ +# Name of the PlaceHolder - Description +######################################################################################################################## +# - Workflow name. example: Bikes +# - Path to the service where the developer would like to trigger the Flow/ action on pull request - Example: samples/BikeSharingApp/Bikes. +# - Path to the folder which contains the Dockerfile +# - Pass this as a parameter for multiple steps below. Lower Cased Name of the Service, for example: bikes +# - Pass this in as a parameter for the Helm Install PR step +# This is the path to the folder where the charts are present for that service. example: samples/BikeSharingApp/Bikes/charts/bikes +# - Pass this in as a parameter for the Helm Install PR step +# +# Note: This template assumes that you use Helm. If not, replace the Helm Install PR step with your own step +# Note: For the secrets below please refer to the document: http://aka.ms/devspaces/pr-flow +# + +name: PRFlow + +on: + pull_request: + branches: + - master + paths: + - /** + +jobs: + build: + runs-on: ubuntu-16.04 + steps: + + - uses: actions/checkout@master + + - uses: azure/container-actions/docker-login@master + with: + login-server: ${{ secrets.CONTAINER_REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: docker build + run: | + docker build / -t ${{ secrets.CONTAINER_REGISTRY }}/:$GITHUB_SHA + docker push ${{ secrets.CONTAINER_REGISTRY }}/:$GITHUB_SHA + + - uses: azure/k8s-actions/aks-set-context@master + with: + creds: '${{ secrets.AZURE_CREDENTIALS }}' + cluster-name: ${{ secrets.CLUSTER_NAME }} + resource-group: ${{ secrets.RESOURCE_GROUP }} + + - name: Create child namespaces and add Dev Spaces labels + run: | + if [ -n "$(kubectl get namespace $GITHUB_HEAD_REF --ignore-not-found -o name)" ]; then exit 0; fi + kubectl create namespace $GITHUB_HEAD_REF + kubectl label namespace $GITHUB_HEAD_REF azds.io/parent-space=${{ secrets.MASTER_SPACE }} + kubectl label namespace $GITHUB_HEAD_REF azds.io/space=true + kubectl label namespace $GITHUB_HEAD_REF azds.io/pull-request-space=true + + - uses: azure/k8s-actions/k8s-create-secret@master + with: + namespace: ${{ GITHUB_HEAD_REF }} + container-registry-url: ${{ secrets.CONTAINER_REGISTRY }} + container-registry-username: ${{ secrets.REGISTRY_USERNAME }} + container-registry-password: ${{ secrets.REGISTRY_PASSWORD }} + secret-name: ${{ secrets.IMAGE_PULL_SECRET }} + + - name: Helm Install PR + run: | + helm upgrade --install --namespace $GITHUB_HEAD_REF -$GITHUB_HEAD_REF \ + --set image.repository=${{ secrets.CONTAINER_REGISTRY }}/ \ + --set image.tag=$GITHUB_SHA \ + --set imagePullSecrets[0].name=${{ secrets.IMAGE_PULL_SECRET }} \ + --set ingress.hosts[0]=$GITHUB_HEAD_REF.s.${{ secrets.HOST }} \ + --set ingress.annotations.kubernetes\\.io/ingress\\.class=traefik-azds + + - uses: azure/dev-spaces/actions/add-review-url@Releases/v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + host: ${{ secrets.HOST }} \ No newline at end of file From 4aa000fe3ab5ed60f82ae41a51f54153b66c4488 Mon Sep 17 00:00:00 2001 From: Anupama Tuli Date: Sat, 2 Nov 2019 18:58:29 -0700 Subject: [PATCH 2/2] Updating the template per PR feedback - Update the names of the place-holders and their description. Also update the template to be in sync with the changes in the actual workflow for the sample - bikes.yml --- .github/workflows/pullrequest.yml.template | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/pullrequest.yml.template b/.github/workflows/pullrequest.yml.template index 2dcbfaa0f..62e41205f 100644 --- a/.github/workflows/pullrequest.yml.template +++ b/.github/workflows/pullrequest.yml.template @@ -1,25 +1,27 @@ -# Name of the PlaceHolder - Description -######################################################################################################################## -# - Workflow name. example: Bikes -# - Path to the service where the developer would like to trigger the Flow/ action on pull request - Example: samples/BikeSharingApp/Bikes. -# - Path to the folder which contains the Dockerfile -# - Pass this as a parameter for multiple steps below. Lower Cased Name of the Service, for example: bikes -# - Pass this in as a parameter for the Helm Install PR step -# This is the path to the folder where the charts are present for that service. example: samples/BikeSharingApp/Bikes/charts/bikes -# - Pass this in as a parameter for the Helm Install PR step -# # Note: This template assumes that you use Helm. If not, replace the Helm Install PR step with your own step # Note: For the secrets below please refer to the document: http://aka.ms/devspaces/pr-flow # +# Name of the PlaceHolder - Description +######################################################################################################################## +# - Workflow name. example: Bikes +# - The path to the service that must be modified in order for the workflow to trigger. - Example: samples/BikeSharingApp/Bikes. +# - Path to the directory which contains the DockerFile for the modified service. +# - Pass this as a parameter for multiple steps below. Lower Cased Name of the Service, for example: bikes +# - Pass this in as a parameter for the Helm Install PR step +# Path to the service's helm charts. example: samples/BikeSharingApp/Bikes/charts/bikes +# - Pass this in as a parameter for the Helm Install PR step +# More details at Helm documentation at https://helm.sh/docs/helm/#helm-upgrade +# This is [RELEASE] in the helm upgrade [RELEASE] [CHART] [flags] command +# helm upgrade --install command is used for: If a release by this name doesn't already exist, run an install -name: PRFlow +name: PRFlow on: pull_request: branches: - master paths: - - /** + - /** jobs: build: @@ -36,8 +38,8 @@ jobs: - name: docker build run: | - docker build / -t ${{ secrets.CONTAINER_REGISTRY }}/:$GITHUB_SHA - docker push ${{ secrets.CONTAINER_REGISTRY }}/:$GITHUB_SHA + docker build / -t ${{ secrets.CONTAINER_REGISTRY }}/:$GITHUB_SHA + docker push ${{ secrets.CONTAINER_REGISTRY }}/:$GITHUB_SHA - uses: azure/k8s-actions/aks-set-context@master with: @@ -55,7 +57,7 @@ jobs: - uses: azure/k8s-actions/k8s-create-secret@master with: - namespace: ${{ GITHUB_HEAD_REF }} + namespace: ${{ github.head_ref }} container-registry-url: ${{ secrets.CONTAINER_REGISTRY }} container-registry-username: ${{ secrets.REGISTRY_USERNAME }} container-registry-password: ${{ secrets.REGISTRY_PASSWORD }} @@ -63,12 +65,10 @@ jobs: - name: Helm Install PR run: | - helm upgrade --install --namespace $GITHUB_HEAD_REF -$GITHUB_HEAD_REF \ - --set image.repository=${{ secrets.CONTAINER_REGISTRY }}/ \ + helm upgrade --install --namespace $GITHUB_HEAD_REF -$GITHUB_HEAD_REF \ + --set image.repository=${{ secrets.CONTAINER_REGISTRY }}/ \ --set image.tag=$GITHUB_SHA \ - --set imagePullSecrets[0].name=${{ secrets.IMAGE_PULL_SECRET }} \ - --set ingress.hosts[0]=$GITHUB_HEAD_REF.s.${{ secrets.HOST }} \ - --set ingress.annotations.kubernetes\\.io/ingress\\.class=traefik-azds + --set imagePullSecrets[0].name=${{ secrets.IMAGE_PULL_SECRET }} - uses: azure/dev-spaces/actions/add-review-url@Releases/v1 with: