Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which docker image can I use to run the github action #104

Open
wenwenchenbosch opened this issue Apr 17, 2024 · 2 comments
Open

Which docker image can I use to run the github action #104

wenwenchenbosch opened this issue Apr 17, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@wenwenchenbosch
Copy link

wenwenchenbosch commented Apr 17, 2024

I want to use this github action to run inlineScript. The github should be running in a docker container, but I can not find any official image for this purpose.

My workflow file looks similar to the one in README. I only added container:

on: [push]

name: AzurePowerShellSample

jobs:

  build:
    runs-on: ubuntu-latest
    container:
      image: ???
    steps:
    
    - name: Login via Az module
      uses: azure/login@v2
      with:
        creds: ${{secrets.AZURE_CREDENTIALS}}
        enable-AzPSSession: true 
        
    - name: Run Azure PowerShell inline script
      uses: azure/powershell@v2
      with:
        inlineScript: |
          Get-AzVM -ResourceGroupName "ResourceGroup11"
        azPSVersion: "latest"

With image: mcr.microsoft.com/azure-powershell:latest I get error Error: Login failed with Error: Unable to locate executable file: az. in the login step.
With image:mcr.microsoft.com/azure-cli:latest I get error Error: Unable to locate executable file: pwsh. in the running script step.

Can someone help me? Or I need a customer docker image for running this simple workflow?

@YanaXu
Copy link
Collaborator

YanaXu commented Apr 26, 2024

Hi @wenwenchenbosch , it's the limitation that if you want to use Azure Login Action, Azure cli and Azure PowerShell should be installed on your runner.
May I ask why you need run the Azure PowerShell script in a docker container? It's not a suggested way to run it. You know many softwares are not installed in many docker images.

The images you have tried are only with Azure Cli or Azure PowerShell, not both of them. That's why it failes.

If you do need to run a docker image (only with Azure PowerShell but without Azure Cli) to run Azure PowerShell script in GitHub actions, I suggest you to login with Azure PowerShell directly instead of using Azure Login Action.
For example

    - name: GetFederatedToken
      uses: actions/github-script@v4
      with:
        script: |
          const idToken = await core.getIDToken('api://AzureADTokenExchange')
          core.exportVariable('idToken', idToken)

    - name: OIDCLoginAndRunAzurePowerShell
      shell: pwsh
      env: 
        tenantId: ${{secrets.tenantId }}
        subscriptionId: ${{secrets.subscriptionId }}
        clientId: ${{secrets.clientId}}
      run: |
        Connect-AzAccount -ServicePrincipal -ApplicationId $env:clientId -Tenant $env:tenantId -SubscriptionId $env:subscriptionId -FederatedToken $env:idToken
        # run your azure powershell cmdlets
        # ...

@YanaXu YanaXu added question Further information is requested and removed need-to-triage labels Apr 26, 2024
@wenwenchenbosch
Copy link
Author

Thanks for the reply. We use self-hosted runner for our project. The runners are shared for multiple projects, therefore, it is not possible to install software by myself.

Now I am using PowerShell command for login and it works, and I still need to figure out how to do deployment using PowerShell command. because azure/arm-deploy@v2 also requires az-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants