microsoft / Oryx

Build your repo automatically.
Other
768 stars 176 forks source link

Azure + GitHub Actions oryx error: Either the value provided to the --runtime-platform argument is empty #2012

Closed philbannon closed 10 months ago

philbannon commented 1 year ago

Hi All,

I'm trying to migrate from GCP to Azure. I have a set of spring boot API's which I'm trying to deploy via GitHub Actions to my Container Apps. However I'm getting what to me is a unknown error stating that the runtime-platform arg is empty.

For context, my API's are Spring Boot running Java 17 and with Gradle and built via the JIB build tool.

Please see below my github actions yml file:

name: Trigger auto deployment for search-service-production

# When this action will be executed
on:
  # Automatically trigger it when detected changes in repo
  push:
    branches:
      [ main ]
    paths:
      - '**'
      - '.github/workflows/search-service-production-AutoDeployTrigger-b9ef6edb-c114-41e7-be4e-b7087d14ea7f.yml'

  # Allow mannually trigger 
  workflow_dispatch:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout to the branch
        uses: actions/checkout@v2

      - name: Azure Login
        uses: azure/login@v1
        with:
          creds: ${{ secrets.SEARCHSERVICEPRODUCTION_AZURE_CREDENTIALS }}

      - name: Set up JDK 17
        uses: actions/setup-java@v2
        with:
          java-version: '17'
          distribution: 'adopt'
          cache: 'gradle'

      - name: Grant execute permission for gradlew
        run: chmod +x gradlew

      - name: Build and Push ACR Image
        env:
          ACR_REGISTRY: xxxxxxcontainerregistry.azurecr.io  # Replace with your ACR login server
          ACR_REPOSITORY: tfs-search-service  # Replace with the desired ACR repository
          ACR_IMAGE_TAG: ${{ github.sha }}
        run: |
          ./gradlew jib -Djib.to.auth.username=${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_USERNAME }}\
            -Djib.to.auth.password=${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_PASSWORD }} \
            -Djib.to.image=xxxxxxcontainerregistry.azurecr.io/tfs-search-service:${{ github.sha }}

      - name: Build and Deploy to Azure Container Apps
        uses: azure/container-apps-deploy-action@v1
        with:
          appSourcePath: ${{ github.workspace }}
          registryUrl: xxxxxxcontainerregistry.azurecr.io
          registryUsername: ${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_USERNAME }}
          registryPassword: ${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_PASSWORD }}
          containerAppName: search-service-production
          resourceGroup: xxxxxx-production
          runtime-platform: linux/amd64
          imageToDeploy: xxxxxxcontainerregistry.azurecr.io/search-service-production:${{ github.sha }}

And below is the log file of my github action:

  Logging into ***.azurecr.io...
    Login Succeeded!
    Run CA_GH_ACTION_REGISTRY_LOGIN_ARG="--registry-server ***.azurecr.io --registry-username *** --registry***"
    Run dockerfilePath=/home/runner/work/tfs-search-service/tfs-search-service/Dockerfile
    Run CA_GH_ACTION_IMAGE_TO_BUILD="***.azurecr.io/github-action/container-app:5166118098.1"
    Run CA_GH_ACTION_IMAGE_TO_DEPLOY="***.azurecr.io/search-service-production:be89eda87dbe377b7db5a8d9cc924acf38eccefe"
    Run CA_GH_ACTION_RESOURCE_GROUP="xxxxxx-production"
    Run az containerapp show \
  WARNING: The command requires the extension containerapp. It will be installed first.
  WARNING: The installed extension 'containerapp' is in preview.
    Run CA_GH_ACTION_CONTAINER_APP_ENVIRONMENT="search-service-production-env"
    Run docker run \
    docker run \
    --rm \
    -v /home/runner/work/tfs-search-service/tfs-search-service:/app \
    mcr.microsoft.com/oryx/cli:builder-debian-buster-20230208.1 \
    /bin/bash \
    -c "oryx dockerfile /app | head -n 1 | sed 's/ARG RUNTIME=//' >> /app/oryx-runtime.txt"
    CA_GH_ACTION_RUNTIME_STACK=$(head -n 1 /home/runner/work/tfs-search-service/tfs-search-service/oryx-runtime.txt)
    echo "CA_GH_ACTION_RUNTIME_STACK=${CA_GH_ACTION_RUNTIME_STACK}" >> $GITHUB_ENV
    rm /home/runner/work/tfs-search-service/tfs-search-service/oryx-runtime.txt
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    AZURE_HTTP_USER_AGENT:
    AZUREPS_HOST_ENVIRONMENT:
    JAVA_HOME: /opt/hostedtoolcache/Java_Adopt_jdk/17.0.7-7/x64
    CA_GH_ACTION_START_MILLISECONDS: 1685834549343
    CA_GH_ACTION_RESULT_ARG: --property 'result=failed'
    CA_GH_ACTION_REGISTRY_LOGIN_ARG: --registry-server ***.azurecr.io --registry-username *** --registry***
    CA_GH_ACTION_REGISTRY_URL: ***.azurecr.io
    CA_GH_ACTION_REGISTRY_USERNAME: ***
    CA_GH_ACTION_REGISTRY_PASSWORD: ***
    CA_GH_ACTION_IMAGE_TO_BUILD: ***.azurecr.io/github-action/container-app:5166118098.1
    CA_GH_ACTION_IMAGE_TO_DEPLOY: ***.azurecr.io/search-service-production:be89eda87dbe377b7db5a8d9cc924acf38eccefe
    CA_GH_ACTION_RESOURCE_GROUP: xxxxxx-production
    CA_GH_ACTION_RESOURCE_EXISTS: true
    CA_GH_ACTION_CONTAINER_APP_ENVIRONMENT: search-service-production-env
    Unable to find image 'mcr.microsoft.com/oryx/cli:builder-debian-buster-20230208.1' locally
  builder-debian-buster-20230208.1: Pulling from oryx/cli
  d42a0fb443d7: Pulling fs layer
  f390d41539fb: Pulling fs layer
  103b21370b9f: Pulling fs layer
  fddd5b6145de: Pulling fs layer
  16dfd13d3a05: Pulling fs layer
  27df7571ea34: Pulling fs layer
  99ad81e721c7: Pulling fs layer
  4136820462f5: Pulling fs layer
  6c84a682b950: Pulling fs layer
  6e38c43918bc: Pulling fs layer
  9beff6fb6da7: Pulling fs layer
  61093d47cb77: Pulling fs layer
  205ffbb9f89d: Pulling fs layer
  fddd5b6145de: Waiting
  16dfd13d3a05: Waiting
  6e38c43918bc: Waiting
  27df7571ea34: Waiting
  99ad81e721c7: Waiting
  9beff6fb6da7: Waiting
  61093d47cb77: Waiting
  205ffbb9f89d: Waiting
  4136820462f5: Waiting
  f390d41539fb: Download complete
  103b21370b9f: Verifying Checksum
  103b21370b9f: Download complete
  16dfd13d3a05: Verifying Checksum
  16dfd13d3a05: Download complete
  d42a0fb443d7: Verifying Checksum
  d42a0fb443d7: Download complete
  27df7571ea34: Verifying Checksum
  27df7571ea34: Download complete
  99ad81e721c7: Verifying Checksum
  99ad81e721c7: Download complete
  fddd5b6145de: Verifying Checksum
  fddd5b6145de: Download complete
  6e38c43918bc: Verifying Checksum
  6e38c43918bc: Download complete
  6c84a682b950: Verifying Checksum
  6c84a682b950: Download complete
  9beff6fb6da7: Verifying Checksum
  9beff6fb6da7: Download complete
  4136820462f5: Verifying Checksum
  4136820462f5: Download complete
  d42a0fb443d7: Pull complete
  205ffbb9f89d: Verifying Checksum
  205ffbb9f89d: Download complete
  f390d41539fb: Pull complete
  61093d47cb77: Verifying Checksum
  61093d47cb77: Download complete
  103b21370b9f: Pull complete
  fddd5b6145de: Pull complete
  16dfd13d3a05: Pull complete
  27df7571ea34: Pull complete
  99ad81e721c7: Pull complete
  4136820462f5: Pull complete
  6c84a682b950: Pull complete
  6e38c43918bc: Pull complete
  9beff6fb6da7: Pull complete
  61093d47cb77: Pull complete
  205ffbb9f89d: Pull complete
  Digest: sha256:2d5eaa1e75ef73b5bf461a573d8fdf40cb7bc1596be2f0b044f5eb0231a8e94c
  Status: Downloaded newer image for mcr.microsoft.com/oryx/cli:builder-debian-buster-20230208.1
  Error: Either the value provided to the --runtime-platform argument is empty, or the platform discovered by Oryx does not have any available or supported runtime images. Please view the following document for more information on runtimes supported by Oryx: https://aka.ms/oryx-runtime-images
    Run CA_GH_ACTION_INGRESS_ENABLED="true"
    Run if [[ "" == "python:"* ]]; then echo "CA_GH_ACTION_TARGET_PORT=80" >> $GITHUB_ENV; else echo "CA_GH_ACTION_TARGET_PORT=8080" >> $GITHUB_ENV; fi
    Run CA_GH_ACTION_TARGET_PORT_ARG="--target-port 8080"
    Run (curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-Linux.tgz" | sudo tar -C /usr/local/bin/ --no-same-owner -xzv pack)
    pack
    Run pack config default-builder mcr.microsoft.com/oryx/builder:20230208.1
    Builder 'mcr.microsoft.com/oryx/builder:20230208.1' is now the default builder
    Run CA_GH_ACTION_ORYX_BUILDER_TELEMETRY_ARG='--env "CALLER_ID=github-actions-v1"'
    Run pack build \
  20230208.1: Pulling from oryx/builder
  d42a0fb443d7: Already exists
  f390d41539fb: Already exists
  103b21370b9f: Already exists
  fddd5b6145de: Already exists
  16dfd13d3a05: Already exists
  27df7571ea34: Already exists
  99ad81e721c7: Already exists
  4136820462f5: Already exists
  6c84a682b950: Already exists
  6e38c43918bc: Already exists
  9beff6fb6da7: Already exists
  61093d47cb77: Already exists
  205ffbb9f89d: Already exists
  2cc11d8f0cae: Pulling fs layer
  29d8bcb2c300: Pulling fs layer
  499b474a8bc1: Pulling fs layer
  d836640b2611: Pulling fs layer
  357fefdf9bc9: Pulling fs layer
  98438d9c08b1: Pulling fs layer
  255a36beb7a5: Pulling fs layer
  944dba79f1aa: Pulling fs layer
  61be144be9f3: Pulling fs layer
  4f4fb700ef54: Pulling fs layer
  d836640b2611: Waiting
  357fefdf9bc9: Waiting
  98438d9c08b1: Waiting
  255a36beb7a5: Waiting
  944dba79f1aa: Waiting
  61be144be9f3: Waiting
  4f4fb700ef54: Waiting
  2cc11d8f0cae: Verifying Checksum
  2cc11d8f0cae: Download complete
  29d8bcb2c300: Verifying Checksum
  29d8bcb2c300: Download complete
  2cc11d8f0cae: Pull complete
  29d8bcb2c300: Pull complete
  357fefdf9bc9: Verifying Checksum
  357fefdf9bc9: Download complete
  d836640b2611: Verifying Checksum
  d836640b2611: Download complete
  255a36beb7a5: Verifying Checksum
  255a36beb7a5: Download complete
  499b474a8bc1: Verifying Checksum
  499b474a8bc1: Download complete
  499b474a8bc1: Pull complete
  944dba79f1aa: Verifying Checksum
  944dba79f1aa: Download complete
  61be144be9f3: Verifying Checksum
  61be144be9f3: Download complete
  d836640b2611: Pull complete
  98438d9c08b1: Verifying Checksum
  98438d9c08b1: Download complete
  357fefdf9bc9: Pull complete
  4f4fb700ef54: Verifying Checksum
  4f4fb700ef54: Download complete
  98438d9c08b1: Pull complete
  255a36beb7a5: Pull complete
  944dba79f1aa: Pull complete
  61be144be9f3: Pull complete
  4f4fb700ef54: Pull complete
  Digest: sha256:8b0a0c106b183828aa0024be84c245fe25ed1e4c810d80db80f2331642097d30
  Status: Downloaded newer image for mcr.microsoft.com/oryx/builder:20230208.1
  ERROR: failed to build: invalid run-image 'mcr.microsoft.com/oryx/': invalid reference format
  Error: Process completed with exit code 1.

If anyone could shed some light that would be great.

Thank you.

harryli0108 commented 1 year ago

Hi @philbannon! Thanks for opening this issue!

From first glance, it looks like a configuration issue. I'm not sure if we have runtime-platform argument for the GitHub Action task.

Meanwhile, I found this documentation file where it gives more details about the required and optional arguments for this GH task. Hopefully this would explain a little bit more.

philbannon commented 1 year ago

Thanks a million for taking the time to look at this @harryli0108 I actually added in the runtime-platform into the config just see if it would make any difference. Seems that having the config file with or without the runtime-platform arg results in the same error.

Any suggestions on what else to look at?

Many thanks

harryli0108 commented 1 year ago

@philbannon You're very welcome. I searched a little bit and seems like there are some environment variables you might need to set for Java projects. image Here's the link to this documentation.

Meanwhile, I also found this that explains how Oryx platform detection works.

Also, I think it is worth noting to see if your Java version used is within our support versions, as the error message you've got may also be triggered due to unsupported Java version.

harryli0108 commented 1 year ago

@philbannon I'm sorry for spamming you with comments here. As one of my colleagues spotted, we currently don't ship Java runtimes with this builder. And because of that, every time when the builder is trying to call oryx dockerfile to get the runtime argument, it'll prompt you with that error.

There is a workaround for your scenario. You'll either need to provide your own dockerfile to the action that builds the app, or build and publish your own runnable application image external to the action and provide the image to the imagesToDeploy argument of the action.

philbannon commented 1 year ago

Hey @harryli0108 please no need to say sorry. You're doing me a massive help here.

Just on the workaround, and this maybe a stupid question but I'm building the image in the following step:

      - name: Build and Push ACR Image
        env:
          ACR_REGISTRY: xxxx.azurecr.io  # Replace with your ACR login server
          ACR_REPOSITORY: tfs-search-service  # Replace with the desired ACR repository
          ACR_IMAGE_TAG: ${{ github.sha }}
        run: |
          ./gradlew jib -Djib.to.auth.username=${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_USERNAME }}\
            -Djib.to.auth.password=${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_PASSWORD }} \
            -Djib.to.image=xxxx.azurecr.io/tfs-search-service:${{ github.sha }}

And also then trying to use imagesToDeploy

- name: Build and Deploy to Azure Container Apps
        uses: azure/container-apps-deploy-action@v1
        with:
          appSourcePath: ${{ github.workspace }}
          registryUrl: xxxxxxcontainerregistry.azurecr.io
          registryUsername: ${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_USERNAME }}
          registryPassword: ${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_PASSWORD }}
          containerAppName: search-service-production
          resourceGroup: xxxxxx-production
          imageToDeploy: xxxxxxcontainerregistry.azurecr.io/search-service-production:${{ github.sha }}

Is this what you mean? If so I'm still getting the same error

Thanks again for all the time.

harryli0108 commented 1 year ago

@philbannon Thanks for the info! In your case, if you use the argument imageToDeploy, you'll need to build the image first outside of the Github Action using docker or your choice of image builder. Since the builder doesn't support Java, the auto detection and building is not going to work here. The workflow yaml file would look something like this:

steps:

  - name: Log in to Azure
    uses: azure/login@v1
    with:
      creds: ${{ secrets.AZURE_CREDENTIALS }}

  - name: Build and deploy Container App
    uses: azure/container-apps-deploy-action@v1
    with:
      registryUrl: xxxxxxcontainerregistry.azurecr.io
      registryUsername: ${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_USERNAME }}
      registryPassword: ${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_PASSWORD }}
      imageToDeploy: xxxxxxcontainerregistry.azurecr.io/search-service-production:xxxxxxxxxx

But if you prefer to use GH Action to build the image for you rather building locally, you can have a Dockerfile with the building steps and layers provided to the task. This would look something like this:

steps:

  - name: Log in to Azure
    uses: azure/login@v1
    with:
      creds: ${{ secrets.AZURE_CREDENTIALS }}

  - name: Build and deploy Container App
    uses: azure/container-apps-deploy-action@v1
    with:
      appSourcePath: ${{ github.workspace }}
      registryUrl: xxxxxxcontainerregistry.azurecr.io
      registryUsername: ${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_USERNAME }}
      registryPassword: ${{ secrets.SEARCHSERVICEPRODUCTION_REGISTRY_PASSWORD }}
      dockerfilePath: Dockerfile-Path

And for more details of the arguments used for this task, I would suggest to take a look on the task documentation.

simonjj commented 10 months ago

This issue seems resolved. Will be closing this issue. If this is still relevant and impacting you please open a new issue and link back to this issue for reference.