From 8c7ace7729eb1cd2700410b5033d0b643eb38070 Mon Sep 17 00:00:00 2001 From: Lili Deng Date: Fri, 13 Dec 2024 14:59:10 +0800 Subject: [PATCH] support for making windows and linux docker images --- .github/workflows/docker-image.yml | 56 ++++++++++++++++++++++++++---- Dockerfile => Dockerfile.linux | 3 +- Dockerfile.windows | 26 ++++++++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) rename Dockerfile => Dockerfile.linux (86%) create mode 100644 Dockerfile.windows diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 100b94fd22..173f309332 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -7,13 +7,50 @@ on: - main jobs: - build: + build-windows: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to Azure Container Registry + run: | + echo ${{ secrets.ACR_PASSWORD }} | docker login ${{ secrets.ACR_LOGIN_SERVER }} -u ${{ secrets.ACR_USERNAME }} --password-stdin + + - name: Build and Push Windows Docker Image + run: | + docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_INTERNAL_REPOSITORY }}:${{ github.event.release.tag_name }}-windows -f Dockerfile.windows . + docker push ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_INTERNAL_REPOSITORY }}:${{ github.event.release.tag_name }}-windows + + - name: Log out from ACR + run: docker logout ${{ secrets.ACR_LOGIN_SERVER }} + + build-linux: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 + - name: Log in to Azure Container Registry + run: | + echo ${{ secrets.ACR_PASSWORD }} | docker login ${{ secrets.ACR_LOGIN_SERVER }} -u ${{ secrets.ACR_USERNAME }} --password-stdin + + - name: Build and Push Linux Docker Image + run: | + docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_INTERNAL_REPOSITORY }}:${{ github.event.release.tag_name }}-linux -f Dockerfile.linux . + docker push ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_INTERNAL_REPOSITORY }}:${{ github.event.release.tag_name }}-linux + + - name: Log out from ACR + run: | + docker logout ${{ secrets.ACR_LOGIN_SERVER }} + + build-multi-platforms: + runs-on: ubuntu-latest + needs: [build-windows, build-linux] + + steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -21,12 +58,19 @@ jobs: run: | echo ${{ secrets.ACR_PASSWORD }} | docker login ${{ secrets.ACR_LOGIN_SERVER }} -u ${{ secrets.ACR_USERNAME }} --password-stdin - - name: Build and Push Docker Image + - name: Create Multi-Platforms Image + run: | + docker buildx imagetools create --tag ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_REPOSITORY }}:${{ github.event.release.tag_name }} \ + ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_INTERNAL_REPOSITORY }}:${{ github.event.release.tag_name }}-windows \ + ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_INTERNAL_REPOSITORY }}:${{ github.event.release.tag_name }}-linux + docker buildx imagetools create --tag ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_REPOSITORY }}:latest \ + ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_INTERNAL_REPOSITORY }}:${{ github.event.release.tag_name }}-windows \ + ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_INTERNAL_REPOSITORY }}:${{ github.event.release.tag_name }}-linux + + - name: Delete Docker Tags run: | - docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_REPOSITORY }}:${{ github.event.release.tag_name }} . - docker tag ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_REPOSITORY }}:${{ github.event.release.tag_name }} ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_REPOSITORY }}:latest - docker push ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_REPOSITORY }}:${{ github.event.release.tag_name }} - docker push ${{ secrets.ACR_LOGIN_SERVER }}/${{ secrets.ACR_REPOSITORY }}:latest + curl -X DELETE -u "${{ secrets.ACR_USERNAME }}:${{ secrets.ACR_PASSWORD }}" https://${{ secrets.ACR_LOGIN_SERVER }}/acr/v1/${{ secrets.ACR_INTERNAL_REPOSITORY }}/_tags/${{ github.event.release.tag_name }}-windows + curl -X DELETE -u "${{ secrets.ACR_USERNAME }}:${{ secrets.ACR_PASSWORD }}" https://${{ secrets.ACR_LOGIN_SERVER }}/acr/v1/${{ secrets.ACR_INTERNAL_REPOSITORY }}/_tags/${{ github.event.release.tag_name }}-linux - name: Log out from ACR run: | diff --git a/Dockerfile b/Dockerfile.linux similarity index 86% rename from Dockerfile rename to Dockerfile.linux index 166e24dac7..d0b78a2845 100644 --- a/Dockerfile +++ b/Dockerfile.linux @@ -28,5 +28,4 @@ RUN git clone --depth 1 --branch $(curl --silent "https://api.github.com/repos/m WORKDIR /app/lisa RUN python3 -m pip install --no-cache-dir --upgrade pip && \ - python3 -m pip install --no-cache-dir --editable .[azure,libvirt,baremetal] --config-settings editable_mode=compat - + python3 -m pip install --no-cache-dir --editable .[ado,azure,libvirt,baremetal] --config-settings editable_mode=compat diff --git a/Dockerfile.windows b/Dockerfile.windows new file mode 100644 index 0000000000..ac99549bda --- /dev/null +++ b/Dockerfile.windows @@ -0,0 +1,26 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +SHELL ["powershell", "-Command"] + +WORKDIR C:\\app\\ + +ENV PYTHON_VERSION=3.11.6 + +RUN Invoke-WebRequest -Uri "https://www.python.org/ftp/python/$Env:PYTHON_VERSION/python-$Env:PYTHON_VERSION-amd64.exe" -OutFile "C:\\python-installer.exe" -UseBasicParsing; \ + $gitRelease = Invoke-RestMethod -Uri "https://api.github.com/repos/git-for-windows/git/releases/latest" -Headers @{ 'User-Agent' = 'Docker Build' }; \ + $gitInstallerUrl = $gitRelease.assets | Where-Object { $_.name -like '*64-bit.exe' } | Select-Object -ExpandProperty browser_download_url; \ + Invoke-WebRequest -Uri $gitInstallerUrl -OutFile "C:\\git-installer.exe" -UseBasicParsing; + +RUN Start-Process -FilePath "C:\\python-installer.exe" -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1 TargetDir=C:\\Python' -Wait; \ + Start-Process -FilePath "C:\\git-installer.exe" -ArgumentList '/VERYSILENT /NORESTART /SP-' -Wait; \ + Remove-Item -Force "C:\\python-installer.exe", "C:\\git-installer.exe"; \ + if (!(Test-Path 'C:\\Python')) { throw 'Python installation failed!' }; \ + $env:PATH = [Environment]::GetEnvironmentVariable('PATH', [EnvironmentVariableTarget]::Machine) + +RUN $latestRelease = (Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/lisa/releases/latest").tag_name; \ + git clone --depth 1 --branch $latestRelease https://github.com/microsoft/lisa.git C:\\app\\lisa + +WORKDIR C:\\app\\lisa + +RUN python -m pip install --no-cache-dir --upgrade pip; \ + python -m pip install --no-cache-dir --editable .[ado,azure,libvirt,baremetal] --config-settings editable_mode=compat