From 0ac4dfda35c4e1a44e91d67fdd62505f8edb73a5 Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 18:46:18 +0100 Subject: [PATCH 01/11] Disable zip and artifact upload if the `release` job is not executed for the run to speed up CI in PRs --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fb8e55f..9e54da5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -167,11 +167,13 @@ jobs: run: dotnet publish -c Release container-desktop/Installer/Installer.csproj -o dist-installer - name: Zip ContainerDesktop Installer + if: startsWith(github.ref, 'refs/tags/v') shell: bash working-directory: dist-installer run: 7z a -bd -mx9 -tzip ContainerDesktopInstaller.zip ContainerDesktopInstaller.exe - name: Upload artifacts + if: startsWith(github.ref, 'refs/tags/v') uses: actions/upload-artifact@v4 with: name: dist-installer From bb48988ebd368d1d72afedb8279a27a8b56dff3e Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 20:12:24 +0100 Subject: [PATCH 02/11] Add nuget cache --- .github/workflows/main.yml | 458 +++++++++++++++++++------------------ 1 file changed, 237 insertions(+), 221 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9e54da5..cd92da7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,221 +1,237 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - paths-ignore: - - "/docs/**" - tags: - - v* - pull_request: - paths-ignore: - - "/docs/**" - branches: - - main - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -env: - DOCKER_VERSION: "26.1.4" - DOCKER_COMPOSE_VERSION: "v2.27.1" - DOCKER_BUILDX_VERSION: "v0.15.0" - GO_VERSION: "1.22" - - # A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build-linux: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: dotnet/nbgv@v0.4.2 - id: nbgv - - - name: Clear dist - run: | - rm -rf dist/* - mkdir -p dist - - - name: Build tools image - run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ - - - name: Download and extract docker cli - run: | - curl -LO https://download.docker.com/win/static/stable/x86_64/docker-$DOCKER_VERSION.zip - unzip -o docker-$DOCKER_VERSION.zip -x docker/dockerd.exe -d dist - - - name: Extract Linux docker cli and plugins - run: | - docker run --rm -v $PWD:/src container-desktop-tools:build sh -c "mkdir /src/dist/docker/linux && cp -R /usr/libexec/docker/cli-plugins /src/dist/docker/linux" - - - name: Download docker compose - run: | - curl -L -o dist/docker/docker-compose.exe https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-Windows-x86_64.exe - curl -L -o dist/docker/docker-compose https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-linux-x86_64 - - - name: Download buildx - run: | - mkdir -p dist/docker/cli-plugins - curl -L -o dist/docker/cli-plugins/docker-buildx.exe https://github.com/docker/buildx/releases/download/$DOCKER_BUILDX_VERSION/buildx-$DOCKER_BUILDX_VERSION.windows-amd64.exe - - - name: Download WSL Kernel MSI - run: | - curl -L -o dist/wsl_update_x64.msi https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi - - - name: Download dns-forwarder (go-dnsmasq) - run: | - mkdir dist/bin/ - curl -L -o dist/bin/dns-forwarder https://github.com/janeczku/go-dnsmasq/releases/download/1.0.7/go-dnsmasq-min_linux-amd64 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: '${{ github.workspace }}/go.mod' - - - name: Build proxy for Windows - run: | - cd cmd/container-desktop-proxy/ - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o ../../dist/container-desktop-proxy-windows-amd64.exe - - - name: Build proxy for Linux - run: | - cd cmd/container-desktop-proxy/ - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o ../../dist/container-desktop-proxy-linux-amd64 - - - name: build port-forwarder for Windows and copy to /dist - run: | - cd cmd/container-desktop-port-forwarder/ - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o ../../dist/container-desktop-port-forwarder.exe - - - name: Build distro image - run: docker build -t container-desktop:build --build-arg DOCKER_VERSION=$DOCKER_VERSION . - - - name: Create WSL distro from the distro image - run: | - sha=$(docker create container-desktop:build) - docker export $sha | gzip > dist/container-desktop-distro.tar.gz - docker rm $sha - - - name: Build Data distro image - run: | - docker build -t container-desktop-data:build --build-arg DOCKER_VERSION=$DOCKER_VERSION deployment/container-desktop-data - - - name: Create WSL Data distro from the data distro image - run: | - sha=$(docker create container-desktop-data:build) - docker export $sha | gzip > dist/container-desktop-data-distro.tar.gz - docker rm $sha - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: dist-base - path: dist - - build-windows: - runs-on: windows-latest - needs: build-linux - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - # Action need to be updated due deprecation of Node.js 12 https://github.com/dotnet/nbgv/issues when available. - - uses: dotnet/nbgv@v0.4.2 - id: nbgv - - - name: Clear dist - shell: bash - run: | - rm -rf dist/* - mkdir -p dist - - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - pattern: dist-* - path: dist - merge-multiple: true - - - name: Setup dotnet SDK - uses: actions/setup-dotnet@v4 - with: - dotnet-version: "8.0" - include-prerelease: false - - - name: Publish ContainerDesktop - shell: bash - run: dotnet publish -c Release container-desktop/ContainerDesktop/ContainerDesktop.csproj - - - name: Package ContainerDesktop - shell: bash - working-directory: ./container-desktop/ContainerDesktop/bin/Release/net8.0-windows10.0.18362.0/win-x64/publish - run: 7z a -r -bd -mx9 -tzip $GITHUB_WORKSPACE/dist/container-desktop.zip . - - - name: Publish ContainerDesktop Installer - shell: bash - run: dotnet publish -c Release container-desktop/Installer/Installer.csproj -o dist-installer - - - name: Zip ContainerDesktop Installer - if: startsWith(github.ref, 'refs/tags/v') - shell: bash - working-directory: dist-installer - run: 7z a -bd -mx9 -tzip ContainerDesktopInstaller.zip ContainerDesktopInstaller.exe - - - name: Upload artifacts - if: startsWith(github.ref, 'refs/tags/v') - uses: actions/upload-artifact@v4 - with: - name: dist-installer - path: dist-installer - - release: - runs-on: ubuntu-latest - needs: build-windows - if: startsWith(github.ref, 'refs/tags/v') - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: dotnet/nbgv@v0.4.2 - id: nbgv - - - name: Clear dist - shell: bash - run: | - rm -rf dist/* - mkdir -p dist - - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - pattern: dist-* - path: dist - merge-multiple: true - - - name: Create hashes - shell: bash - working-directory: dist - run: | - sha256sum ContainerDesktopInstaller.exe > sha256sum.txt - sha256sum ContainerDesktopInstaller.zip >> sha256sum.txt - - - name: release - uses: softprops/action-gh-release@v1 - with: - prerelease: ${{ steps.nbgv.outputs.PrereleaseVersion }} - files: | - dist/ContainerDesktopInstaller.exe - dist/ContainerDesktopInstaller.zip - dist/sha256sum.txt +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + paths-ignore: + - "/docs/**" + tags: + - v* + pull_request: + paths-ignore: + - "/docs/**" + branches: + - main + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + DOCKER_VERSION: "26.1.4" + DOCKER_COMPOSE_VERSION: "v2.27.1" + DOCKER_BUILDX_VERSION: "v0.15.0" + GO_VERSION: "1.22" + + # A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build-linux: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: dotnet/nbgv@v0.4.2 + id: nbgv + + - name: Clear dist + run: | + rm -rf dist/* + mkdir -p dist + + - name: Build tools image + run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ + + - name: Download and extract docker cli + run: | + curl -LO https://download.docker.com/win/static/stable/x86_64/docker-$DOCKER_VERSION.zip + unzip -o docker-$DOCKER_VERSION.zip -x docker/dockerd.exe -d dist + + - name: Extract Linux docker cli and plugins + run: | + docker run --rm -v $PWD:/src container-desktop-tools:build sh -c "mkdir /src/dist/docker/linux && cp -R /usr/libexec/docker/cli-plugins /src/dist/docker/linux" + + - name: Download docker compose + run: | + curl -L -o dist/docker/docker-compose.exe https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-Windows-x86_64.exe + curl -L -o dist/docker/docker-compose https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-linux-x86_64 + + - name: Download buildx + run: | + mkdir -p dist/docker/cli-plugins + curl -L -o dist/docker/cli-plugins/docker-buildx.exe https://github.com/docker/buildx/releases/download/$DOCKER_BUILDX_VERSION/buildx-$DOCKER_BUILDX_VERSION.windows-amd64.exe + + - name: Download WSL Kernel MSI + run: | + curl -L -o dist/wsl_update_x64.msi https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi + + - name: Download dns-forwarder (go-dnsmasq) + run: | + mkdir dist/bin/ + curl -L -o dist/bin/dns-forwarder https://github.com/janeczku/go-dnsmasq/releases/download/1.0.7/go-dnsmasq-min_linux-amd64 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: '${{ github.workspace }}/go.mod' + + - name: Build proxy for Windows + run: | + cd cmd/container-desktop-proxy/ + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o ../../dist/container-desktop-proxy-windows-amd64.exe + + - name: Build proxy for Linux + run: | + cd cmd/container-desktop-proxy/ + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o ../../dist/container-desktop-proxy-linux-amd64 + + - name: build port-forwarder for Windows and copy to /dist + run: | + cd cmd/container-desktop-port-forwarder/ + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o ../../dist/container-desktop-port-forwarder.exe + + - name: Build distro image + run: docker build -t container-desktop:build --build-arg DOCKER_VERSION=$DOCKER_VERSION . + + - name: Create WSL distro from the distro image + run: | + sha=$(docker create container-desktop:build) + docker export $sha | gzip > dist/container-desktop-distro.tar.gz + docker rm $sha + + - name: Build Data distro image + run: | + docker build -t container-desktop-data:build --build-arg DOCKER_VERSION=$DOCKER_VERSION deployment/container-desktop-data + + - name: Create WSL Data distro from the data distro image + run: | + sha=$(docker create container-desktop-data:build) + docker export $sha | gzip > dist/container-desktop-data-distro.tar.gz + docker rm $sha + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: dist-base + path: dist + + build-windows: + runs-on: windows-latest + needs: build-linux + env: + NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + # Action need to be updated due deprecation of Node.js 12 https://github.com/dotnet/nbgv/issues when available. + - uses: dotnet/nbgv@v0.4.2 + id: nbgv + + - name: Clear dist + shell: bash + run: | + rm -rf dist/* + mkdir -p dist + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + pattern: dist-* + path: dist + merge-multiple: true + + - name: Setup dotnet SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "8.0" + dotnet-quality: 'ga' + # This requires a lock file. + # We explicitly manage a global nuget package cache instead as + # packages should be immutable anyway. + cache: false + + - name: Cache NuGet Packages + id: nuget-packages + uses: actions/cache@v4 + env: + cache-name: nuget-package-cache + with: + path: ${{ env.NUGET_PACKAGES }} + key: ${{ runner.os }}-${{ env.cache-name }} + enableCrossOsArchive: true + + - name: Publish ContainerDesktop + shell: bash + run: dotnet publish -c Release container-desktop/ContainerDesktop/ContainerDesktop.csproj + + - name: Package ContainerDesktop + shell: bash + working-directory: ./container-desktop/ContainerDesktop/bin/Release/net8.0-windows10.0.18362.0/win-x64/publish + run: 7z a -r -bd -mx9 -tzip $GITHUB_WORKSPACE/dist/container-desktop.zip . + + - name: Publish ContainerDesktop Installer + shell: bash + run: dotnet publish -c Release container-desktop/Installer/Installer.csproj -o dist-installer + + - name: Zip ContainerDesktop Installer + if: startsWith(github.ref, 'refs/tags/v') + shell: bash + working-directory: dist-installer + run: 7z a -bd -mx9 -tzip ContainerDesktopInstaller.zip ContainerDesktopInstaller.exe + + - name: Upload artifacts + if: startsWith(github.ref, 'refs/tags/v') + uses: actions/upload-artifact@v4 + with: + name: dist-installer + path: dist-installer + + release: + runs-on: ubuntu-latest + needs: build-windows + if: startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: dotnet/nbgv@v0.4.2 + id: nbgv + + - name: Clear dist + shell: bash + run: | + rm -rf dist/* + mkdir -p dist + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + pattern: dist-* + path: dist + merge-multiple: true + + - name: Create hashes + shell: bash + working-directory: dist + run: | + sha256sum ContainerDesktopInstaller.exe > sha256sum.txt + sha256sum ContainerDesktopInstaller.zip >> sha256sum.txt + + - name: release + uses: softprops/action-gh-release@v1 + with: + prerelease: ${{ steps.nbgv.outputs.PrereleaseVersion }} + files: | + dist/ContainerDesktopInstaller.exe + dist/ContainerDesktopInstaller.zip + dist/sha256sum.txt From 155a7e6c10ac72e5b0c571cbabd2d43d60d6bec3 Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 20:31:13 +0100 Subject: [PATCH 03/11] Cache external resources that have versioned urls using in the github cache --- .github/workflows/main.yml | 64 +++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd92da7..dd06c17 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,6 +24,7 @@ env: DOCKER_COMPOSE_VERSION: "v2.27.1" DOCKER_BUILDX_VERSION: "v0.15.0" GO_VERSION: "1.22" + GO_DNSMASQ: "1.0.7" # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -47,37 +48,56 @@ jobs: rm -rf dist/* mkdir -p dist - - name: Build tools image - run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ + ################################################# DOWNLOADS ################################################### - - name: Download and extract docker cli - run: | - curl -LO https://download.docker.com/win/static/stable/x86_64/docker-$DOCKER_VERSION.zip - unzip -o docker-$DOCKER_VERSION.zip -x docker/dockerd.exe -d dist - - - name: Extract Linux docker cli and plugins - run: | - docker run --rm -v $PWD:/src container-desktop-tools:build sh -c "mkdir /src/dist/docker/linux && cp -R /usr/libexec/docker/cli-plugins /src/dist/docker/linux" + - name: Download docker cli + uses: ethanjli/cached-download-action@v0.1.0 + with: + url: https://download.docker.com/win/static/stable/x86_64/docker-$DOCKER_VERSION.zip + destination: docker-$DOCKER_VERSION.zip - - name: Download docker compose - run: | - curl -L -o dist/docker/docker-compose.exe https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-Windows-x86_64.exe - curl -L -o dist/docker/docker-compose https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-linux-x86_64 + - name: Download docker compose (windows) + uses: ethanjli/cached-download-action@v0.1.0 + with: + url: https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-Windows-x86_64.exe + destination: dist/docker/docker-compose.exe - - name: Download buildx - run: | - mkdir -p dist/docker/cli-plugins - curl -L -o dist/docker/cli-plugins/docker-buildx.exe https://github.com/docker/buildx/releases/download/$DOCKER_BUILDX_VERSION/buildx-$DOCKER_BUILDX_VERSION.windows-amd64.exe + - name: Download docker compose (linux) + uses: ethanjli/cached-download-action@v0.1.0 + with: + url: https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-linux-x86_64 + destination: dist/docker/docker-compose + + - name: Download buildx (windows) + uses: ethanjli/cached-download-action@v0.1.0 + with: + url: https://github.com/docker/buildx/releases/download/$DOCKER_BUILDX_VERSION/buildx-$DOCKER_BUILDX_VERSION.windows-amd64.exe + destination: dist/docker/cli-plugins/docker-buildx.exe + - name: Download dns-forwarder (go-dnsmasq) + uses: ethanjli/cached-download-action@v0.1.0 + with: + url: https://github.com/janeczku/go-dnsmasq/releases/download/$GO_DNSMASQ/go-dnsmasq-min_linux-amd64 + destination: dist/bin/dns-forwarder + + # This does not have a versioned url - name: Download WSL Kernel MSI run: | curl -L -o dist/wsl_update_x64.msi https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi - - name: Download dns-forwarder (go-dnsmasq) - run: | - mkdir dist/bin/ - curl -L -o dist/bin/dns-forwarder https://github.com/janeczku/go-dnsmasq/releases/download/1.0.7/go-dnsmasq-min_linux-amd64 + ################################################# DOWNLOADS ################################################### + + - name: Build tools image + run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ + - name: Extract docker cli + run: | + unzip -o docker-$DOCKER_VERSION.zip -x docker/dockerd.exe -d dist + + - name: Extract Linux docker cli and plugins + run: | + docker run --rm -v $PWD:/src container-desktop-tools:build sh -c "mkdir /src/dist/docker/linux && cp -R /usr/libexec/docker/cli-plugins /src/dist/docker/linux" + - name: Setup Go uses: actions/setup-go@v5 with: From 878a31e9e432ec9c35ff187f7a2b3a5d25cea14a Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 20:40:05 +0100 Subject: [PATCH 04/11] `ethanjli/cached-download-action` does not resolve environment variables in inputs. Use yaml template placeholders instead. --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd06c17..d778398 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,31 +53,31 @@ jobs: - name: Download docker cli uses: ethanjli/cached-download-action@v0.1.0 with: - url: https://download.docker.com/win/static/stable/x86_64/docker-$DOCKER_VERSION.zip - destination: docker-$DOCKER_VERSION.zip + url: https://download.docker.com/win/static/stable/x86_64/docker-${{ env.DOCKER_VERSION }}.zip + destination: docker-${{ env.DOCKER_VERSION }}.zip - name: Download docker compose (windows) uses: ethanjli/cached-download-action@v0.1.0 with: - url: https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-Windows-x86_64.exe + url: https://github.com/docker/compose/releases/download/${{ env.DOCKER_COMPOSE_VERSION }}/docker-compose-Windows-x86_64.exe destination: dist/docker/docker-compose.exe - name: Download docker compose (linux) uses: ethanjli/cached-download-action@v0.1.0 with: - url: https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-linux-x86_64 + url: https://github.com/docker/compose/releases/download/${{ env.DOCKER_COMPOSE_VERSION }}/docker-compose-linux-x86_64 destination: dist/docker/docker-compose - name: Download buildx (windows) uses: ethanjli/cached-download-action@v0.1.0 with: - url: https://github.com/docker/buildx/releases/download/$DOCKER_BUILDX_VERSION/buildx-$DOCKER_BUILDX_VERSION.windows-amd64.exe + url: https://github.com/docker/buildx/releases/download/${{ env.DOCKER_BUILDX_VERSION }}/buildx-${{ env.DOCKER_BUILDX_VERSION }}.windows-amd64.exe destination: dist/docker/cli-plugins/docker-buildx.exe - name: Download dns-forwarder (go-dnsmasq) uses: ethanjli/cached-download-action@v0.1.0 with: - url: https://github.com/janeczku/go-dnsmasq/releases/download/$GO_DNSMASQ/go-dnsmasq-min_linux-amd64 + url: https://github.com/janeczku/go-dnsmasq/releases/download/${{ env.GO_DNSMASQ }}/go-dnsmasq-min_linux-amd64 destination: dist/bin/dns-forwarder # This does not have a versioned url From b2676968106293e750439c6432de85751273c9e9 Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 20:46:22 +0100 Subject: [PATCH 05/11] Bump `ethanjli/cached-download-action` to `0.1.2` to follow url redirects --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d778398..981a663 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,31 +51,31 @@ jobs: ################################################# DOWNLOADS ################################################### - name: Download docker cli - uses: ethanjli/cached-download-action@v0.1.0 + uses: ethanjli/cached-download-action@v0.1.2 with: url: https://download.docker.com/win/static/stable/x86_64/docker-${{ env.DOCKER_VERSION }}.zip destination: docker-${{ env.DOCKER_VERSION }}.zip - name: Download docker compose (windows) - uses: ethanjli/cached-download-action@v0.1.0 + uses: ethanjli/cached-download-action@v0.1.2 with: url: https://github.com/docker/compose/releases/download/${{ env.DOCKER_COMPOSE_VERSION }}/docker-compose-Windows-x86_64.exe destination: dist/docker/docker-compose.exe - name: Download docker compose (linux) - uses: ethanjli/cached-download-action@v0.1.0 + uses: ethanjli/cached-download-action@v0.1.2 with: url: https://github.com/docker/compose/releases/download/${{ env.DOCKER_COMPOSE_VERSION }}/docker-compose-linux-x86_64 destination: dist/docker/docker-compose - name: Download buildx (windows) - uses: ethanjli/cached-download-action@v0.1.0 + uses: ethanjli/cached-download-action@v0.1.2 with: url: https://github.com/docker/buildx/releases/download/${{ env.DOCKER_BUILDX_VERSION }}/buildx-${{ env.DOCKER_BUILDX_VERSION }}.windows-amd64.exe destination: dist/docker/cli-plugins/docker-buildx.exe - name: Download dns-forwarder (go-dnsmasq) - uses: ethanjli/cached-download-action@v0.1.0 + uses: ethanjli/cached-download-action@v0.1.2 with: url: https://github.com/janeczku/go-dnsmasq/releases/download/${{ env.GO_DNSMASQ }}/go-dnsmasq-min_linux-amd64 destination: dist/bin/dns-forwarder From 9007d80d7550642b6582254c5b2a0e90b53df89e Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 21:26:48 +0100 Subject: [PATCH 06/11] Try to leverage the gh registry as a intermediate image cache --- .github/workflows/main.yml | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 981a663..147ec7b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ env: DOCKER_BUILDX_VERSION: "v0.15.0" GO_VERSION: "1.22" GO_DNSMASQ: "1.0.7" - + REGISTRY: ghcr.io # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" @@ -86,9 +86,32 @@ jobs: curl -L -o dist/wsl_update_x64.msi https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi ################################################# DOWNLOADS ################################################### + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Build tools image - run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ + uses: docker/build-push-action@v6 + with: + context: 'tools/container-desktop-tools/' + build-args: | + "DOCKER_VERSION=${{ env.DOCKER_VERSION }}" + load: true + push: false + tags: container-desktop-tools:build + cache-from: type=registry,ref=container-desktop-tools:buildcache + cache-to: type=registry,ref=container-desktop-tools:buildcache,mode=max,compression=zstd,compression-level=9 + + # - name: Build tools image + # run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ - name: Extract docker cli run: | From 0ff7715a78e1e19d74ce1cfe7d2e6344020ba077 Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 21:30:08 +0100 Subject: [PATCH 07/11] Fully qualify image in cache refs --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 147ec7b..0581e98 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -107,8 +107,8 @@ jobs: load: true push: false tags: container-desktop-tools:build - cache-from: type=registry,ref=container-desktop-tools:buildcache - cache-to: type=registry,ref=container-desktop-tools:buildcache,mode=max,compression=zstd,compression-level=9 + cache-from: type=registry,ref=${{ env.REGISTRY }}/container-desktop-tools:buildcache + cache-to: type=registry,ref=${{ env.REGISTRY }}/container-desktop-tools:buildcache,mode=max,compression=zstd,compression-level=9 # - name: Build tools image # run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ From 9d3e43bbd2debb779eca48886e0c97cd6c408c8c Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 21:39:59 +0100 Subject: [PATCH 08/11] Add `packages: write` to `GITHUB_TOKEN` --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0581e98..b34165e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,9 @@ jobs: build-linux: # The type of runner that the job will run on runs-on: ubuntu-latest - + permissions: + # required to push image cache layers to the ghcr + packages: write # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it From 5a872649076b3de6fd38c07ac16433f719ef3430 Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 21:54:11 +0100 Subject: [PATCH 09/11] Attempt to fix issue with ghcr access by making the image name in the cache refs match the repository name --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b34165e..e545080 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -109,8 +109,8 @@ jobs: load: true push: false tags: container-desktop-tools:build - cache-from: type=registry,ref=${{ env.REGISTRY }}/container-desktop-tools:buildcache - cache-to: type=registry,ref=${{ env.REGISTRY }}/container-desktop-tools:buildcache,mode=max,compression=zstd,compression-level=9 + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:tools-buildcache + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:tools-buildcache,mode=max,compression=zstd,compression-level=9 # - name: Build tools image # run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ From 62662f4483584a835c6c0d3e70a987c9d11b951a Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 22:22:55 +0100 Subject: [PATCH 10/11] Ensure all components that compose the image name are lowercase. --- .github/workflows/main.yml | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e545080..02f72dc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,6 +26,17 @@ env: GO_VERSION: "1.22" GO_DNSMASQ: "1.0.7" REGISTRY: ghcr.io + # Need to be resolved dynamically as there is no lowercase function + # for templated expressions! + # See also: https://github.com/orgs/community/discussions/25768 + # org + GITHUB_REPOSITORY_OWNER_LC: + # org/repo + GITHUB_REPOSITORY_LC: + # registry/org + REGISTRY_BASE_IMAGE_PATH: + # registry/org/repo + DEFAULT_FULL_IMAGE_NAME: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" @@ -37,6 +48,21 @@ jobs: packages: write # Steps represent a sequence of tasks that will be executed as part of the job steps: + - name: lowercase github.repository + run: | + github_repo_owner_lc="${GITHUB_REPOSITORY_OWNER@L}" + github_repo_lc="${GITHUB_REPOSITORY@L}" + github_cr_base_name="$REGISTRY/$github_repo_owner_lc" + + # org + echo "GITHUB_REPOSITORY_OWNER_LC=$github_repo_owner_lc" >> ${GITHUB_ENV} + # org/repo + echo "GITHUB_REPOSITORY_LC=$github_repo_lc" >> ${GITHUB_ENV} + # registry/org + echo "REGISTRY_BASE_IMAGE_PATH=$github_cr_base_name" >> ${GITHUB_ENV} + # registry/org/repo + echo "DEFAULT_FULL_IMAGE_NAME=$REGISTRY/$github_repo_lowercase" >> ${GITHUB_ENV} + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v4 with: @@ -102,6 +128,8 @@ jobs: - name: Build tools image uses: docker/build-push-action@v6 + env: + IMAGE_NAME: container-desktop-tools with: context: 'tools/container-desktop-tools/' build-args: | @@ -109,8 +137,8 @@ jobs: load: true push: false tags: container-desktop-tools:build - cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:tools-buildcache - cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository }}:tools-buildcache,mode=max,compression=zstd,compression-level=9 + cache-from: type=registry,ref=${{ env.DEFAULT_FULL_IMAGE_NAME }}:buildcache + cache-to: type=registry,ref=${{ env.DEFAULT_FULL_IMAGE_NAME }}:buildcache,mode=max,compression=zstd,compression-level=9 # - name: Build tools image # run: docker build -t container-desktop-tools:build --build-arg "DOCKER_VERSION=$DOCKER_VERSION" tools/container-desktop-tools/ From 6eaa37280818925ac4304afb7a9f8950682f14a8 Mon Sep 17 00:00:00 2001 From: Luca Piombino Date: Sat, 15 Feb 2025 22:29:51 +0100 Subject: [PATCH 11/11] Ensure all components that compose the image name are lowercase. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 02f72dc..a8d01fc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -61,7 +61,7 @@ jobs: # registry/org echo "REGISTRY_BASE_IMAGE_PATH=$github_cr_base_name" >> ${GITHUB_ENV} # registry/org/repo - echo "DEFAULT_FULL_IMAGE_NAME=$REGISTRY/$github_repo_lowercase" >> ${GITHUB_ENV} + echo "DEFAULT_FULL_IMAGE_NAME=$REGISTRY/$github_repo_lc" >> ${GITHUB_ENV} # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v4