[azure-cli] Update docker image with latest azure-cli version #1544
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "[azure-cli] Update docker image with latest azure-cli version" | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'azure-cli/*' | |
- '.github/workflows/azure-cli-update-docker-image.yaml' | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
update-version: | |
runs-on: ubuntu-latest | |
outputs: | |
modified: ${{ steps.check.outputs.modified }} | |
commit_sha: ${{ steps.commit.outputs.commit_sha }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Detect workflow trigger event type | |
run: echo "GITHUB_EVENT_NAME=$GITHUB_EVENT_NAME" | |
- name: Fetch current version of azure cli | |
run: echo "CURRENT_AZURECLI_VERSION=$(cat azure-cli/versions.json | jq -r '.azurecli')" >> $GITHUB_ENV | |
- name: Fetch latest version of azure cli | |
run: | | |
latest_azurecli_version=$(curl -sL https://api.github.com/repos/Azure/azure-cli/releases/latest | jq -r '.tag_name' | sed -e 's/^azure-cli-//g') | |
echo "LATEST_AZURECLI_VERSION=$latest_azurecli_version" >> $GITHUB_ENV | |
- name: Fetch latest version of kubectl | |
run: | | |
latest_kubectl_version=$(curl -sL https://dl.k8s.io/release/stable.txt | sed -e 's/^v//g') | |
echo "LATEST_KUBECTL_VERSION=$latest_kubectl_version" >> $GITHUB_ENV | |
- name: Fetch latest version of helm | |
run: | | |
latest_helm_version=$(curl -sL https://api.github.com/repos/helm/helm/releases?page=1 | jq -rc '.[] | select(.name | startswith("Helm v3")) | select(.prerelease!=true) | .tag_name' | head -1 | sed -e 's/^v//g') | |
echo "LATEST_HELM_VERSION=$latest_helm_version" >> $GITHUB_ENV | |
- name: Fetch latest version of azbrowse | |
run: | | |
latest_azbrowse_version=$(curl -sL https://api.github.com/repos/lawrencegripper/azbrowse/releases/latest | jq -r '.tag_name' | sed -e 's/^v//g') | |
echo "LATEST_AZBROWSE_VERSION=$latest_azbrowse_version" >> $GITHUB_ENV | |
- name: Update all versions if azure cli version is newer | |
if: env.CURRENT_AZURECLI_VERSION != env.LATEST_AZURECLI_VERSION | |
run: | | |
cat azure-cli/versions.json | jq ".azurecli=\"$LATEST_AZURECLI_VERSION\"" > tmp && mv tmp azure-cli/versions.json | |
cat azure-cli/versions.json | jq ".kubectl=\"$LATEST_KUBECTL_VERSION\"" > tmp && mv tmp azure-cli/versions.json | |
cat azure-cli/versions.json | jq ".helm=\"$LATEST_HELM_VERSION\"" > tmp && mv tmp azure-cli/versions.json | |
cat azure-cli/versions.json | jq ".azbrowse=\"$LATEST_AZBROWSE_VERSION\"" > tmp && mv tmp azure-cli/versions.json | |
- name: Check for modified versions.json file | |
id: check | |
run: | | |
modified_versions_file=$([ -z "`git status --porcelain azure-cli/versions.json`" ] && echo "false" || echo "true") | |
echo "modified=$modified_versions_file" >> "$GITHUB_OUTPUT" | |
- name: Commit latest versions.json file | |
if: steps.check.outputs.modified == 'true' | |
run: | | |
git config --global user.name "${{ secrets.COMMITTER_NAME }}" | |
git config --global user.email "${{ secrets.COMMITTER_EMAIL }}" | |
git add azure-cli/versions.json | |
git commit -m "Update versions - azure-cli $LATEST_AZURECLI_VERSION" | |
git push | |
- name: Obtain commit SHA for versions.json file | |
id: commit | |
if: steps.check.outputs.modified == 'true' | |
run: echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" | |
build-and-push: | |
runs-on: ubuntu-latest | |
needs: update-version | |
if: needs.update-version.outputs.modified == 'true' || github.event_name == 'push' | |
env: | |
DOCKER_IMAGE: paulbouwer/azure-cli | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ needs.update-version.outputs.commit_sha }} | |
- name: Fetch versions | |
run: | | |
echo "AZURECLI_VERSION=$(cat azure-cli/versions.json | jq -r '.azurecli')" >> $GITHUB_ENV | |
echo "KUBECTL_VERSION=$(cat azure-cli/versions.json | jq -r '.kubectl')" >> $GITHUB_ENV | |
echo "HELM_VERSION=$(cat azure-cli/versions.json | jq -r '.helm')" >> $GITHUB_ENV | |
echo "AZBROWSE_VERSION=$(cat azure-cli/versions.json | jq -r '.azbrowse')" >> $GITHUB_ENV | |
- name: Build image | |
run: | | |
docker build -t $DOCKER_IMAGE:$AZURECLI_VERSION \ | |
--build-arg AZURECLI_VERSION="$AZURECLI_VERSION" \ | |
--build-arg KUBECTL_VERSION="$KUBECTL_VERSION" \ | |
--build-arg HELM_VERSION="$HELM_VERSION" \ | |
--build-arg AZBROWSE_VERSION="$AZBROWSE_VERSION" \ | |
--file ./azure-cli/Dockerfile ./azure-cli | |
- name: Log into registry | |
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
- name: Push image to registry | |
run: | | |
docker push $DOCKER_IMAGE:$AZURECLI_VERSION |