8

I am trying to install the azure-cli in the dind:latest image based on alpine.

For context, I want to use it to connect to AKS and deploy an app to Kubernetes via Gitlab.

In my gitlab-ci.yml file I start with this

image: docker:latest
services:
  - docker:dind

and then I try to install the azure-cli

deploy-to-k8s--dev: # k8s namespace "dev"
  stage: deploy-to-k8s
#  image: microsoft/azure-cli
  script:
    # I need the azure cli in the dind:latest container
    # so install bash,curl and finally the cli
    - apk update
    - apk upgrade
    - apk add bash
    - apk add --no-cache curl

    - curl -L https://aka.ms/InstallAzureCli | bash
    - az

and I get the following error

$ curl -L https://aka.ms/InstallAzureCli | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   167  100   167    0     0    167      0  0:00:01 --:--:--  0:00:01   644

100  1367  100  1367    0     0   1367      0  0:00:01 --:--:--  0:00:01  1367
mktemp: Invalid argument
ERROR: Job failed: error executing remote command: command terminated with non-zero exit code: Error executing in Docker Container: 1

It is the first time that I try to work with Alpine Linux and I have no idea how it is built and what tools it uses...

Has anyone any suggestion?

EDIT

based on the accepted answer this is the final code that works

deploy-to-k8s--dev: # k8s namespace "dev"
  stage: deploy-to-k8s
  script:
    # I need the azure cli in the dind:latest container
    # so install bash,curl and finally the cli
    - apk update
    - apk upgrade
    - apk add bash make py-pip
    - apk add --virtual=build gcc libffi-dev musl-dev openssl-dev python2-dev
    - pip install azure-cli
    - apk del --purge build
    - az -h
Kostas Demiris
  • 3,415
  • 8
  • 47
  • 85

2 Answers2

7

This helped me in one of my alpine based image

apk update
apk add bash py-pip
apk add --virtual=build gcc libffi-dev musl-dev openssl-dev python- dev
pip install azure-cli
apk del --purge build
inquisitive
  • 3,738
  • 6
  • 30
  • 56
sanath meti
  • 5,179
  • 1
  • 21
  • 30
1

A relevantly newer version of https://stackoverflow.com/a/47699967/6319218:

apk add --no-cache --update python3 py3-pip
apk add --no-cache --update --virtual=build gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
pip3 install --no-cache-dir --prefer-binary azure-cli==${AZURE_CLI_VERSION}
apk del build

* Remove the AZURE_CLI_VERSION if you want the latest.