From fa68df5a34d5e703f10248f5ee6db8cc9b4d33b3 Mon Sep 17 00:00:00 2001 From: cavivie Date: Thu, 28 Mar 2024 21:10:13 +0800 Subject: [PATCH] feat: support dockerfile with multi openssl version --- .github/actions/docker-build-push/action.yml | 52 ++++++++++++++++++++ .github/workflows/docker-publish.yml | 40 ++++++++++----- chocolatey/Dockerfile | 4 -- rsxe-windows/Dockerfile | 14 ------ rust-windows/Dockerfile | 4 -- win-alrd-rsxe/Dockerfile | 17 +++++++ win-dev-base/Dockerfile | 18 +++++++ win-dev-rust/Dockerfile | 3 ++ 8 files changed, 117 insertions(+), 35 deletions(-) create mode 100644 .github/actions/docker-build-push/action.yml delete mode 100644 chocolatey/Dockerfile delete mode 100644 rsxe-windows/Dockerfile delete mode 100644 rust-windows/Dockerfile create mode 100644 win-alrd-rsxe/Dockerfile create mode 100644 win-dev-base/Dockerfile create mode 100644 win-dev-rust/Dockerfile diff --git a/.github/actions/docker-build-push/action.yml b/.github/actions/docker-build-push/action.yml new file mode 100644 index 0000000..a7f91e7 --- /dev/null +++ b/.github/actions/docker-build-push/action.yml @@ -0,0 +1,52 @@ +name: 'Docker image build and push' +description: 'Docker image build and push' +inputs: + push: + description: 'Docker push after build' + default: true + registry: + description: 'Docker image registry' + default: 'ghcr.io' + image: + description: 'Docker image name' + # github.repository as / + default: '${{ github.repository }}' + tag: + description: 'Docker image tag' + required: true + context: + description: 'Docker build context' + default: '.' + file: + description: 'Dockerfile in context' + default: 'Dockerfile' + shell: + description: 'Shell to execute command' + default: 'bash' +runs: + using: "composite" + steps: + # Export required GitHub Actions envrionment variables, + # vcpkg will now upload or restore packages from the actions cache. + - name: Export GitHub Actions cache environment variables + uses: actions/github-script@v6 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + + # Build docker image with vcpkg cache options: (x-gha: github-cache-token). + - name: Build docker image ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} + run: | + docker build \ + --build-arg VCPKG_BINARY_SOURCES="clear;x-gha,readwrite" \ + --build-arg ACTIONS_CACHE_URL="${{ env.ACTIONS_CACHE_URL }}" \ + --build-arg ACTIONS_CACHE_URL="${{ env.ACTIONS_RUNTIME_TOKEN }}" \ + -t "${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }}" ${{ inputs.context }} + shell: ${{ inputs.shell }} + + # Push docker image to registry if the current github event is not pull request. + - name: Push docker image ${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }} + if: ${{ inputs.push == true || inputs.push == 'true' }} + run: docker push "${{ inputs.registry }}/${{ inputs.image }}:${{ inputs.tag }}" + shell: ${{ inputs.shell }} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 869a887..239c11e 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -11,12 +11,6 @@ on: pull_request: branches: [ "main" ] -env: - REGISTRY: ghcr.io - # github.repository as / - IMAGE_NAME: ${{ github.repository }} - - jobs: build: runs-on: windows-2022 @@ -35,7 +29,7 @@ jobs: # https://github.com/sigstore/cosign-installer - name: Install cosign if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1 + uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3.1.1 with: cosign-release: 'v2.1.1' @@ -55,10 +49,30 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - run: docker build -t "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:chocolatey" chocolatey - - run: docker build -t "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:rust-windows" rust-windows - - run: docker build -t "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:rsxe-windows" rsxe-windows - - run: docker push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:rsxe-windows" - - run: docker push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:rust-windows" - - run: docker push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:chocolatey" + - name: Build and push docker image for win-dev-base + uses: ./.github/actions/docker-build-push + with: + push: ${{ github.event_name != 'pull_request' }} + tag: win-dev-base + context: win-dev-base + + - name: Build and push docker image for win-dev-rust + uses: ./.github/actions/docker-build-push + with: + push: ${{ github.event_name != 'pull_request' }} + tag: win-dev-rust + context: win-dev-rust + + - name: Build and push docker image for alrd-windows + uses: ./.github/actions/docker-build-push + with: + push: ${{ github.event_name != 'pull_request' }} + tag: alrd-windows + context: win-alrd-rsxe + - name: Build and push docker image for rsxe-windows + uses: ./.github/actions/docker-build-push + with: + push: ${{ github.event_name != 'pull_request' }} + tag: rsxe-windows + context: win-alrd-rsxe diff --git a/chocolatey/Dockerfile b/chocolatey/Dockerfile deleted file mode 100644 index 8e88349..0000000 --- a/chocolatey/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM mcr.microsoft.com/windows/servercore:ltsc2022 - -SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] -RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) diff --git a/rsxe-windows/Dockerfile b/rsxe-windows/Dockerfile deleted file mode 100644 index 2d3becb..0000000 --- a/rsxe-windows/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM ghcr.io/automesh-network/dockerfiles:rust-windows - -RUN choco install openssl git strawberryperl just -y - -ENV OPENSSL_DIR "C:\\Program Files\\OpenSSL-Win64" -ENV OPENSSL_LIB_DIR "C:\\Program Files\\OpenSSL-Win64\\lib\\VC\\x64\\MD" -RUN '[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Users\ContainerAdministrator\.cargo\bin", [EnvironmentVariableTarget]::Machine)' - -RUN rustup.exe install 1.75 nightly-2023-12-30 -RUN rustup.exe default 1.75 - -ADD https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.ps1 /install-from-binstall-release.ps1 -RUN C:\install-from-binstall-release.ps1 -RUN cargo binstall --secure --no-confirm cargo-tarpaulin cargo-audit cargo-nextest diff --git a/rust-windows/Dockerfile b/rust-windows/Dockerfile deleted file mode 100644 index 34a8a3d..0000000 --- a/rust-windows/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM ghcr.io/automesh-network/dockerfiles:chocolatey - -RUN choco install rustup.install -y -RUN choco install visualstudio2022buildtools -y --package-parameters '--quiet --wait --norestart --add Microsoft.Component.MSBuild --add Microsoft.VisualStudio.Component.Windows11SDK.22621 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64' diff --git a/win-alrd-rsxe/Dockerfile b/win-alrd-rsxe/Dockerfile new file mode 100644 index 0000000..ddc7825 --- /dev/null +++ b/win-alrd-rsxe/Dockerfile @@ -0,0 +1,17 @@ +FROM ghcr.io/automesh-network/dockerfiles:win-dev-rust + +RUN vcpkg install openssl:x64-windows openssl:x64-windows-static openssl:x64-windows-static-md +RUN vcpkg install openssl:x86-windows openssl:x86-windows-static openssl:x86-windows-static-md +RUN vcpkg install openssl:arm64-windows openssl:arm64-windows-static openssl:arm64-windows-static-md + +RUN choco install git strawberryperl just -y + +ARG RUST_STABLE_VERSION=1.76 +ARG RUST_NIGHTLY_VERSION=2024-02-08 +RUN rustup install $env:RUST_STABLE_VERSION +RUN rustup default $env:RUST_STABLE_VERSION +RUN rustup install nightly-$env:RUST_NIGHTLY_VERSION + +ADD https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.ps1 /install-from-binstall-release.ps1 +RUN C:\install-from-binstall-release.ps1 +RUN cargo binstall --secure --no-confirm cargo-tarpaulin cargo-audit cargo-nextest diff --git a/win-dev-base/Dockerfile b/win-dev-base/Dockerfile new file mode 100644 index 0000000..abc842b --- /dev/null +++ b/win-dev-base/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"] +RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + +RUN choco install visualstudio2022buildtools -y --package-parameters '--quiet --wait --norestart --add Microsoft.Component.MSBuild --add Microsoft.VisualStudio.Component.Windows11SDK.22621 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.VC.Tools.ARM64' +RUN choco install git -y + +ARG VCPKG_BINARY_SOURCES= +ARG ACTIONS_CACHE_URL= +ARG ACTIONS_RUNTIME_TOKEN= +ARG VCPKG_ROOT="C:\\vcpkg" +ARG VCPKG_VERSION=2024.03.25 +RUN git clone https://github.com/microsoft/vcpkg.git $env:VCPKG_ROOT +RUN git -C $env:VCPKG_ROOT checkout $env:VCPKG_VERSION +RUN & "$env:VCPKG_ROOT\bootstrap-vcpkg.bat -disableMetrics" +RUN [Environment]::SetEnvironmentVariable('VCPKG_ROOT', $env:VCPKG_ROOT, [EnvironmentVariableTarget]::Machine) +RUN [Environment]::SetEnvironmentVariable('PATH', $env:PATH + ';' + $env:VCPKG_ROOT, [EnvironmentVariableTarget]::Machine) diff --git a/win-dev-rust/Dockerfile b/win-dev-rust/Dockerfile new file mode 100644 index 0000000..9283344 --- /dev/null +++ b/win-dev-rust/Dockerfile @@ -0,0 +1,3 @@ +FROM ghcr.io/automesh-network/dockerfiles:win-dev-base + +RUN choco install rustup.install -y