Azure / spring-cloud-deploy

GitHub Actions for deploying to Azure Spring Cloud
MIT License
5 stars 10 forks source link

Azure/spring-cloud-deploy@v1 fails to find package #13

Open ezYakaEagle442 opened 2 years ago

ezYakaEagle442 commented 2 years ago

I have a GitHub workflow with 1 Build Job and 1 Deploy Job, so I had to upload artifacts after the Build to then be able to download them at deployment time.

I have debug traces that shows the artifact is indeed there at the expected location "/github/workspace/${{ env.DISCOVERY_SERVER }}/${{ env.DISCOVERY_SERVER_JAR_ARTIFACT }}" , the Azure Spring Cloud App deployment runs fine ONLY with CLI and ONLY when setting 1 variable built on top of other variables

DISCOVERY_SERVER_ARTIFACT_FULL_PATH="/github/workspace/${{ env.DISCOVERY_SERVER }}/${{ env.DISCOVERY_SERVER_JAR_ARTIFACT }}"
az spring-cloud app deployment create --artifact-path $DISCOVERY_SERVER_ARTIFACT_FULL_PATH ......

This snippets fails :

az spring-cloud app deployment create --artifact-path "/github/workspace/${{ env.DISCOVERY_SERVER }}/${{ env.DISCOVERY_SERVER_JAR_ARTIFACT }}"

See my pipeline :

az spring-cloud app deployment create --name ${{ env.DEPLOYMENT_NAME }} --app ${{ env.DISCOVERY_SERVER }} -s ${{ env.SPRING_CLOUD_SERVICE }} --artifact-path $DISCOVERY_SERVER_ARTIFACT_FULL_PATH -g ${{ env.DEPLOYMENT_RG }} --version ${{ env.DEPLOYMENT_VERSION }} --runtime-version ${{ env.DEPLOYMENT_RUNTIME_VERSION }} --cpu ${{ env.DEPLOYMENT_CPU }} --memory ${{ env.DEPLOYMENT_MEMORY }} --instance-count ${{ env.DEPLOYMENT_INSTANCE_COUNT }} --disable-probe ${{ env.DEPLOYMENT_DISABLE_PROBE }}       

See my pipeline

    - name: Deploy DISCOVERY-SERVER
      uses:  Azure/spring-cloud-deploy@v1
      with:
        azure-subscription: ${{ secrets.AZURE_SUBSCRIPTION }}
        action: deploy
        service-name: ${{ env.SPRING_CLOUD_SERVICE }}
        app-name: ${{ env.DISCOVERY_SERVER }}
        use-staging-deployment: ${{ env.DEPLOYMENT_STAGING }}
        package: /github/workspace/${{ env.DISCOVERY_SERVER }}/${{ env.DISCOVERY_SERVER_JAR_ARTIFACT }}
        jvm-options: ${{ env.DEPLOYMENT_JVM_OPTIONS }}  
        deployment-name: ${{ env.DEPLOYMENT_NAME }}
        create-new-deployment: ${{ env.DEPLOYMENT_CREATE_NEW }}
        version: ${{ env.DEPLOYMENT_VERSION }} 
        runtime-version: ${{ env.DEPLOYMENT_RUNTIME_VERSION }}

Pipeline run failure: https://github.com/ezYakaEagle442/azure-spring-cloud-petclinic-mic-srv/runs/5742240456?check_suite_focus=true

Action failed with error: No package found with specified pattern: /github/workspace/discovery-server/spring-petclinic-discovery-server-2.6.3.jar

What would be needed as well is a GitHub action task to do the quivalent of 'az spring-cloud app deployment create'

Reading the GitHub Action Reference for Azure Spring Cloud helps as I have found this argument create-new-deployment: ==> If set to true and the deployment specified by deployment-name does not exist at execution time, it will be created. However there is no option to combine create-new-deployment setting the parameters below using Azure/spring-cloud-deploy@v1 :

--cpu ${{ env.DEPLOYMENT_CPU }} --memory ${{ env.DEPLOYMENT_MEMORY }} --instance-count ${{ env.DEPLOYMENT_INSTANCE_COUNT }} --disable-probe ${{ env.DEPLOYMENT_DISABLE_PROBE }}

Also this fails as well of course as $DISCOVERY_SERVER_ARTIFACT_FULL_PATH is not known in this context

package: $DISCOVERY_SERVER_ARTIFACT_FULL_PATH 
Action failed with error: No package found with specified pattern: $DISCOVERY_SERVER_ARTIFACT_FULL_PATH

See also :

ezYakaEagle442 commented 2 years ago

Update, I have fixed the issue , the main cause was : the step that creates or updates the environment variable does not have access to the new value, but all subsequent steps in a job will have access.

  DEPLOYMENT_JVM_OPTIONS: -Dazure.keyvault.uri=https://kv-petcliasc42.vault.azure.net -Xms512m -Xmx1024m -Dspring.profiles.active=mysql,key-vault,cloud

  DEPLOYMENT_VERSION: 2.6.3
  DEPLOYMENT_RUNTIME_VERSION: Java_11
  DEPLOYMENT_CPU: 500m
  DEPLOYMENT_MEMORY: 512Mi
  DEPLOYMENT_INSTANCE_COUNT: 3
  DEPLOYMENT_DISABLE_PROBE: false

  # If set to true and the deployment specified by deployment-name does not exist at execution time, it will be created.
  DEPLOYMENT_CREATE_NEW: true

  # /!\ Deployment name can contain only lowercase letters, numbers and hyphens.
  DEPLOYMENT_NAME: blue
  DEPLOYMENT_STAGING: true
  DEPLOYMENT_ACTION: deploy

  # Choose either Blue or Green
  # DEPLOYMENT_NAME: green
  # DEPLOYMENT_STAGING: false
  # DEPLOYMENT_ACTION: set-production

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Set Base environment variables
      run: |
        echo "LOCAL_IP=$(curl whatismyip.akamai.com)" >> $GITHUB_ENV

        echo "API_GATEWAY_JAR_ARTIFACT=${{ env.PRJ_PREFIX }}-${{ env.API_GATEWAY }}-${{ env.DEPLOYMENT_VERSION }}.jar" >> $GITHUB_ENV
        echo "ADMIN_SERVER_JAR_ARTIFACT=${{ env.PRJ_PREFIX }}-${{ env.ADMIN_SERVER }}-${{ env.DEPLOYMENT_VERSION }}.jar" >> $GITHUB_ENV
        echo "CONFIG_SERVER_JAR_ARTIFACT=${{ env.PRJ_PREFIX }}-${{ env.CONFIG_SERVER }}-${{ env.DEPLOYMENT_VERSION }}.jar" >> $GITHUB_ENV
        echo "DISCOVERY_SERVER_JAR_ARTIFACT=${{ env.PRJ_PREFIX }}-${{ env.DISCOVERY_SERVER }}-${{ env.DEPLOYMENT_VERSION }}.jar" >> $GITHUB_ENV
        echo "CUSTOMERS_SERVICE_JAR_ARTIFACT=${{ env.PRJ_PREFIX }}-${{ env.CUSTOMERS_SERVICE }}-${{ env.DEPLOYMENT_VERSION }}.jar" >> $GITHUB_ENV
        echo "VETS_SERVICE_JAR_ARTIFACT=${{ env.PRJ_PREFIX }}-${{ env.VETS_SERVICE }}-${{ env.DEPLOYMENT_VERSION }}.jar" >> $GITHUB_ENV
        echo "VISITS_SERVICE_JAR_ARTIFACT=${{ env.PRJ_PREFIX }}-${{ env.VISITS_SERVICE }}-${{ env.DEPLOYMENT_VERSION }}.jar" >> $GITHUB_ENV

        echo "API_GATEWAY_DEPLOYMENT=${{ env.DEPLOYMENT_NAME }}-${{ env.API_GATEWAY }}" >> $GITHUB_ENV
        echo "ADMIN_SERVER_DEPLOYMENT=${{ env.DEPLOYMENT_NAME }}-${{ env.ADMIN_SERVER }}" >> $GITHUB_ENV
        echo "CONFIG_SERVER_DEPLOYMENT=${{ env.DEPLOYMENT_NAME }}-${{ env.CONFIG_SERVER }}" >> $GITHUB_ENV
        echo "CUSTOMERS_SERVICE_DEPLOYMENT=${{ env.DEPLOYMENT_NAME }}-${{ env.CUSTOMERS_SERVICE }}" >> $GITHUB_ENV
        echo "DISCOVERY_SERVER_DEPLOYMENT=${{ env.DEPLOYMENT_NAME }}-${{ env.DISCOVERY_SERVER }}" >> $GITHUB_ENV
        echo "VETS_SERVICE_DEPLOYMENT=${{ env.DEPLOYMENT_NAME }}-${{ env.VETS_SERVICE }}" >> $GITHUB_ENV
        echo "VISITS_SERVICE_DEPLOYMENT=${{ env.DEPLOYMENT_NAME }}-${{ env.VISITS_SERVICE }}" >> $GITHUB_ENV

        echo "GH_API=api.github.com/user/packages/maven" >> $GITHUB_ENV

        echo "ADMIN_SERVER_GROUP_ID=org.springframework.samples.petclinic.admin" >> $GITHUB_ENV
        echo "ADMIN_SERVER_ARTIFACT_ID=${{ env.PRJ_PREFIX }}-${{ env.ADMIN_SERVER }}" >> $GITHUB_ENV

        echo "API_GATEWAY_GROUP_ID=org.springframework.samples.petclinic.api" >> $GITHUB_ENV
        echo "API_GATEWAY_ARTIFACT_ID=${{ env.PRJ_PREFIX }}-${{ env.API_GATEWAY }}" >> $GITHUB_ENV

        echo "CONFIG_SERVER_GROUP_ID=org.springframework.samples.petclinic.config" >> $GITHUB_ENV
        echo "CONFIG_SERVER_ARTIFACT_ID=${{ env.PRJ_PREFIX }}-${{ env.CONFIG_SERVER }}" >> $GITHUB_ENV

        echo "CUSTOMERS_SERVICE_GROUP_ID=org.springframework.samples.petclinic.client" >> $GITHUB_ENV
        echo "CUSTOMERS_SERVICE_ARTIFACT_ID=${{ env.PRJ_PREFIX }}-${{ env.CUSTOMERS_SERVICE }}" >> $GITHUB_ENV

        echo "DISCOVERY_SERVER_GROUP_ID=org.springframework.samples.petclinic.discovery" >> $GITHUB_ENV
        echo "DISCOVERY_SERVER_ARTIFACT_ID=${{ env.PRJ_PREFIX }}-${{ env.DISCOVERY_SERVER }}" >> $GITHUB_ENV

        echo "VETS_SERVICE_GROUP_ID=org.springframework.samples.petclinic.vets" >> $GITHUB_ENV
        echo "VETS_SERVICE_ARTIFACT_ID=${{ env.PRJ_PREFIX }}-${{ env.VETS_SERVICE }}" >> $GITHUB_ENV

        echo "VISITS_SERVICE_GROUP_ID=org.springframework.samples.petclinic.visits" >> $GITHUB_ENV
        echo "VISITS_SERVICE_ARTIFACT_ID=${{ env.PRJ_PREFIX }}-${{ env.VISITS_SERVICE }}" >> $GITHUB_ENV

        echo "GH_WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV # "/github/workspace"
      shell: bash

    # Variables in the env map cannot be defined in terms of other variables in the map
    - name: Set dependent environment variables
      run: |
        # ==== JARS ====: PWD already in /home/runner/work/azure-spring-cloud-petclinic-mic-srv >> $GITHUB_ENV
        echo "API_GATEWAY_JAR=${{ env.PRJ_PREFIX }}-${{ env.API_GATEWAY }}/target/$API_GATEWAY_JAR_ARTIFACT" >> $GITHUB_ENV
        echo "ADMIN_SERVER_JAR=${{ env.PRJ_PREFIX }}-${{ env.ADMIN_SERVER }}/target/$ADMIN_SERVER_JAR_ARTIFACT" >> $GITHUB_ENV
        echo "CONFIG_SERVER_JAR=${{ env.PRJ_PREFIX }}-${{ env.CONFIG_SERVER }}/target/$CONFIG_SERVER_JAR_ARTIFACT" >> $GITHUB_ENV
        echo "CUSTOMERS_SERVICE_JAR=${{ env.PRJ_PREFIX }}-${{ env.CUSTOMERS_SERVICE }}/target/$CUSTOMERS_SERVICE_JAR_ARTIFACT" >> $GITHUB_ENV
        echo "DISCOVERY_SERVER_JAR=${{ env.PRJ_PREFIX }}-${{ env.DISCOVERY_SERVER }}/target/$DISCOVERY_SERVER_JAR_ARTIFACT" >> $GITHUB_ENV
        echo "VETS_SERVICE_JAR=${{ env.PRJ_PREFIX }}-${{ env.VETS_SERVICE }}/target/$VETS_SERVICE_JAR_ARTIFACT" >> $GITHUB_ENV
        echo "VISITS_SERVICE_JAR=${{ env.PRJ_PREFIX }}-${{ env.VISITS_SERVICE }}/target/$VISITS_SERVICE_JAR_ARTIFACT" >> $GITHUB_ENV

        echo "API_GATEWAY_PACKAGE_PATH=$GH_WORKSPACE/${{ env.API_GATEWAY }}/${{ env.API_GATEWAY_JAR_ARTIFACT }}" >> $GITHUB_ENV
        echo "ADMIN_SERVER_PACKAGE_PATH=$GH_WORKSPACE/${{ env.ADMIN_SERVER }}/${{ env.ADMIN_SERVER_JAR_ARTIFACT }}" >> $GITHUB_ENV
        echo "CONFIG_SERVER_PACKAGE_PATH=$GH_WORKSPACE/${{ env.CONFIG_SERVER }}/${{ env.CONFIG_SERVER_JAR_ARTIFACT }}" >> $GITHUB_ENV
        echo "CUSTOMERS_SERVICE_PACKAGE_PATH=$GH_WORKSPACE/${{ env.CUSTOMERS_SERVICE }}/${{ env.CUSTOMERS_SERVICE_JAR_ARTIFACT }}" >> $GITHUB_ENV
        echo "DISCOVERY_SERVER_PACKAGE_PATH=$GH_WORKSPACE/${{ env.DISCOVERY_SERVER }}/${{ env.DISCOVERY_SERVER_JAR_ARTIFACT }}" >> $GITHUB_ENV
        echo "VETS_SERVICE_PACKAGE_PATH=$GH_WORKSPACE/${{ env.VETS_SERVICE }}/${{ env.VETS_SERVICE_JAR_ARTIFACT }}" >> $GITHUB_ENV
        echo "VISITS_SERVICE_PACKAGE_PATH=$GH_WORKSPACE/${{ env.VISITS_SERVICE }}/${{ env.VISITS_SERVICE_JAR_ARTIFACT }}" >> $GITHUB_ENV

        echo "ADMIN_SERVER_API_URL=https://$GH_API/$ADMIN_SERVER_GROUP_ID.$ADMIN_SERVER_ARTIFACT_ID/versions" >> $GITHUB_ENV
        echo "API_GATEWAY_API_URL=https://$GH_API/$API_GATEWAY_GROUP_ID.$API_GATEWAY_ARTIFACT_ID/versions" >> $GITHUB_ENV
        echo "CONFIG_SERVER_API_URL=https://$GH_API/$CONFIG_SERVER_GROUP_ID.$CONFIG_SERVER_ARTIFACT_ID/versions" >> $GITHUB_ENV
        echo "CUSTOMERS_SERVICE_API_URL=https://$GH_API/$CUSTOMERS_SERVICE_GROUP_ID.$CUSTOMERS_SERVICE_ARTIFACT_ID/versions" >> $GITHUB_ENV
        echo "DISCOVERY_SERVER_API_URL=https://$GH_API/$DISCOVERY_SERVER_GROUP_ID.$DISCOVERY_SERVER_ARTIFACT_ID/versions" >> $GITHUB_ENV
        echo "VETS_SERVICE_API_URL=https://$GH_API/$VETS_SERVICE_GROUP_ID.$VETS_SERVICE_ARTIFACT_ID/versions" >> $GITHUB_ENV
        echo "VISITS_SERVICE_API_URL=https://$GH_API/$VISITS_SERVICE_GROUP_ID.$VISITS_SERVICE_ARTIFACT_ID/versions" >> $GITHUB_ENV
      shell: bash

I now have 1 Build Job in 1 Workflow + 1 Deploy Job in another Workflow. The Build Job uses Maven to deploy the Artifacts to GitHub packages

    - name:  Publish the package
      run: |
        mkdir -p ~/.m2
        echo "<settings><servers><server><id>github-asc</id><username>$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $1}')</username><password>\${env.GITHUB_TOKEN}</password></server></servers></settings>" > ~/.m2/settings.xml
        REPO="github-asc::default::https://maven.pkg.github.com/${GITHUB_REPOSITORY}"

        mvn deploy -DaltReleaseDeploymentRepository="${REPO}" -DaltSnapshotDeploymentRepository="${REPO}" --batch-mode -DskipTests -Dmaven.install.skip=true
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Now in the deploy Workflow

    - name: Deploy DISCOVERY-SERVER
      uses:  Azure/spring-cloud-deploy@v1
      with:
        azure-subscription: ${{ secrets.AZURE_SUBSCRIPTION }}
        action: deploy
        service-name: ${{ env.SPRING_CLOUD_SERVICE }}
        app-name: ${{ env.DISCOVERY_SERVER }}
        use-staging-deployment: ${{ env.DEPLOYMENT_STAGING }}
        package: ${{ env.DISCOVERY_SERVER_PACKAGE_PATH }}
        jvm-options: ${{ env.DEPLOYMENT_JVM_OPTIONS }}  
        deployment-name:  ${{ env.DISCOVERY_SERVER_DEPLOYMENT }}
        create-new-deployment: ${{ env.DEPLOYMENT_CREATE_NEW }}
        version: ${{ env.DEPLOYMENT_VERSION }} 
        runtime-version: ${{ env.DEPLOYMENT_RUNTIME_VERSION }}

this argument create-new-deployment: ==> If set to true and the deployment specified by deployment-name does not exist at execution time, it will be created. However it does not provide all the options offered by the CLI : az spring-cloud app deployment create --cpu 500m --memory 512Mi --instance-count 3 --disable-probe false

CONCLUSION: bascially we need a GitHub Action to create a deployment with all the options offered by the CLI , including --cpu --memory --instance-count --disable-probe