From ebdeb41eb3b73199a3a3c4edf700c01c59b0fe71 Mon Sep 17 00:00:00 2001 From: Johan Van de Wauw Date: Sun, 11 Oct 2020 18:25:15 +0200 Subject: [PATCH 1/5] Add lfs support on windows Tested using 1809 --- docker/Dockerfile.windows.1803 | 3 +++ docker/Dockerfile.windows.1809 | 3 +++ docker/Dockerfile.windows.1903 | 3 +++ docker/Dockerfile.windows.1909 | 3 +++ windows/clone.ps1 | 4 ++-- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile.windows.1803 b/docker/Dockerfile.windows.1803 index cbd58a7..888dbea 100644 --- a/docker/Dockerfile.windows.1803 +++ b/docker/Dockerfile.windows.1803 @@ -6,6 +6,9 @@ SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $Progress RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/MinGit-2.21.0-64-bit.zip -OutFile git.zip; ` Expand-Archive git.zip -DestinationPath C:\git; +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` + Invoke-WebRequest -UseBasicParsing https://github.com/git-lfs/git-lfs/releases/download/v2.12.0/git-lfs-windows-amd64-v2.12.0.zip -OutFile git-lfs.zip; ` + Expand-Archive git-lfs.zip -DestinationPath C:\git\lfs; FROM mcr.microsoft.com/powershell:nanoserver-1803 COPY --from=git /git /git diff --git a/docker/Dockerfile.windows.1809 b/docker/Dockerfile.windows.1809 index 936400d..5a8c48e 100644 --- a/docker/Dockerfile.windows.1809 +++ b/docker/Dockerfile.windows.1809 @@ -6,6 +6,9 @@ SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $Progress RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/MinGit-2.21.0-64-bit.zip -OutFile git.zip; ` Expand-Archive git.zip -DestinationPath C:\git; +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` + Invoke-WebRequest -UseBasicParsing https://github.com/git-lfs/git-lfs/releases/download/v2.12.0/git-lfs-windows-amd64-v2.12.0.zip -OutFile git-lfs.zip; ` + Expand-Archive git-lfs.zip -DestinationPath C:\git\lfs; FROM mcr.microsoft.com/powershell:nanoserver-1809 COPY --from=git /git /git diff --git a/docker/Dockerfile.windows.1903 b/docker/Dockerfile.windows.1903 index 71982da..2c630c4 100644 --- a/docker/Dockerfile.windows.1903 +++ b/docker/Dockerfile.windows.1903 @@ -6,6 +6,9 @@ SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $Progress RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/MinGit-2.21.0-64-bit.zip -OutFile git.zip; ` Expand-Archive git.zip -DestinationPath C:\git; +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` + Invoke-WebRequest -UseBasicParsing https://github.com/git-lfs/git-lfs/releases/download/v2.12.0/git-lfs-windows-amd64-v2.12.0.zip -OutFile git-lfs.zip; ` + Expand-Archive git-lfs.zip -DestinationPath C:\git\lfs; FROM mcr.microsoft.com/powershell:nanoserver-1903 COPY --from=git /git /git diff --git a/docker/Dockerfile.windows.1909 b/docker/Dockerfile.windows.1909 index 7e53708..8aa645d 100644 --- a/docker/Dockerfile.windows.1909 +++ b/docker/Dockerfile.windows.1909 @@ -6,6 +6,9 @@ SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $Progress RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/MinGit-2.21.0-64-bit.zip -OutFile git.zip; ` Expand-Archive git.zip -DestinationPath C:\git; +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` + Invoke-WebRequest -UseBasicParsing https://github.com/git-lfs/git-lfs/releases/download/v2.12.0/git-lfs-windows-amd64-v2.12.0.zip -OutFile git-lfs.zip; ` + Expand-Archive git-lfs.zip -DestinationPath C:\git\lfs; FROM mcr.microsoft.com/powershell:nanoserver-1909 COPY --from=git /git /git diff --git a/windows/clone.ps1 b/windows/clone.ps1 index 4be8cc4..2ff440f 100644 --- a/windows/clone.ps1 +++ b/windows/clone.ps1 @@ -1,8 +1,8 @@ $ErrorActionPreference = 'Stop'; # HACK: no clue how to set the PATH inside the Dockerfile, -# so am setting it here instead. This is not idea. -$Env:PATH += ';C:\git\cmd;C:\git\mingw64\bin;C:\git\usr\bin' +# so am setting it here instead. This is not ideal. +$Env:PATH += ';C:\git\cmd;C:\git\mingw64\bin;C:\git\usr\bin;C:\git\lfs' # if the workspace is set we should make sure # it is the current working directory. From 35fd81b74012c753d0f15bd925046d9f8b696547 Mon Sep 17 00:00:00 2001 From: Johan Van de Wauw Date: Wed, 3 Jan 2024 14:46:33 +0100 Subject: [PATCH 2/5] Add windows 2022 dockerfile --- docker/Dockerfile.windows.ltsc2022 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docker/Dockerfile.windows.ltsc2022 diff --git a/docker/Dockerfile.windows.ltsc2022 b/docker/Dockerfile.windows.ltsc2022 new file mode 100644 index 0000000..35f4a33 --- /dev/null +++ b/docker/Dockerfile.windows.ltsc2022 @@ -0,0 +1,23 @@ +# escape=` + +FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS git +SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` + Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.43.0.windows.1/MinGit-2.43.0-64-bit.zip -OutFile git.zip; ` + Expand-Archive git.zip -DestinationPath C:\git; +RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` + Invoke-WebRequest -UseBasicParsing https://github.com/git-lfs/git-lfs/releases/download/v3.4.1/git-lfs-windows-amd64-v3.4.1.zip -OutFile git-lfs.zip; ` + Expand-Archive git-lfs.zip -DestinationPath C:\git\lfs; + +FROM mcr.microsoft.com/powershell:nanoserver-ltsc2022 +COPY --from=git /git /git + +ADD windows/* /bin/ + +# https://github.com/PowerShell/PowerShell/issues/6211#issuecomment-367477137 +USER ContainerAdministrator +RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell" + +SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] +CMD [ "pwsh", "C:\\bin\\clone.ps1" ] From f807d0d7fe12e81737a1611b383c668f73a89e4b Mon Sep 17 00:00:00 2001 From: Johan Van de Wauw Date: Mon, 22 Jan 2024 21:59:03 +0000 Subject: [PATCH 3/5] new attempt --- docker/Dockerfile.windows.ltsc2022 | 10 ++++++---- windows/clone-commit.ps1 | 11 +++-------- windows/clone.ps1 | 9 ++++++++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/docker/Dockerfile.windows.ltsc2022 b/docker/Dockerfile.windows.ltsc2022 index 35f4a33..52f9e8d 100644 --- a/docker/Dockerfile.windows.ltsc2022 +++ b/docker/Dockerfile.windows.ltsc2022 @@ -4,20 +4,22 @@ FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS git SHELL ["powershell.exe", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` - Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.43.0.windows.1/MinGit-2.43.0-64-bit.zip -OutFile git.zip; ` + Invoke-WebRequest -UseBasicParsing https://github.com/git-for-windows/git/releases/download/v2.21.0.windows.1/MinGit-2.21.0-64-bit.zip -OutFile git.zip; ` Expand-Archive git.zip -DestinationPath C:\git; RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; ` - Invoke-WebRequest -UseBasicParsing https://github.com/git-lfs/git-lfs/releases/download/v3.4.1/git-lfs-windows-amd64-v3.4.1.zip -OutFile git-lfs.zip; ` + Invoke-WebRequest -UseBasicParsing https://github.com/git-lfs/git-lfs/releases/download/v2.12.0/git-lfs-windows-amd64-v2.12.0.zip -OutFile git-lfs.zip; ` Expand-Archive git-lfs.zip -DestinationPath C:\git\lfs; -FROM mcr.microsoft.com/powershell:nanoserver-ltsc2022 +FROM mcr.microsoft.com/powershell:windowsserver-ltsc2022 COPY --from=git /git /git ADD windows/* /bin/ # https://github.com/PowerShell/PowerShell/issues/6211#issuecomment-367477137 USER ContainerAdministrator -RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell" +RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell;c:\git\cmd;c:\git\lfs\git-lfs-2.12.0" SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] CMD [ "pwsh", "C:\\bin\\clone.ps1" ] + +LABEL org.opencontainers.image.source=https://github.com/johanvdw/drone-git/ diff --git a/windows/clone-commit.ps1 b/windows/clone-commit.ps1 index 43566c5..05aa31c 100644 --- a/windows/clone-commit.ps1 +++ b/windows/clone-commit.ps1 @@ -1,9 +1,3 @@ - -Set-Variable -Name "FLAGS" -Value "" -if ($Env:PLUGIN_DEPTH) { - Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" -} - if (!(Test-Path .git)) { Write-Host 'git init'; git init @@ -11,7 +5,8 @@ if (!(Test-Path .git)) { git remote add origin $Env:DRONE_REMOTE_URL } -Write-Host "git fetch $FLAGS origin +refs/heads/${Env:DRONE_COMMIT_BRANCH}:"; -git fetch $FLAGS origin "+refs/heads/${Env:DRONE_COMMIT_BRANCH}:"; +Write-Host "git fetch origin +refs/heads/${Env:DRONE_COMMIT_BRANCH}:"; +git fetch origin "+refs/heads/${Env:DRONE_COMMIT_BRANCH}:"; Write-Host "git checkout $Env:DRONE_COMMIT_SHA -f $Env:DRONE_COMMIT_BRANCH"; git checkout $Env:DRONE_COMMIT_SHA -b $Env:DRONE_COMMIT_BRANCH; +git lfs logs last \ No newline at end of file diff --git a/windows/clone.ps1 b/windows/clone.ps1 index 2ff440f..cb09bcc 100644 --- a/windows/clone.ps1 +++ b/windows/clone.ps1 @@ -2,7 +2,7 @@ $ErrorActionPreference = 'Stop'; # HACK: no clue how to set the PATH inside the Dockerfile, # so am setting it here instead. This is not ideal. -$Env:PATH += ';C:\git\cmd;C:\git\mingw64\bin;C:\git\usr\bin;C:\git\lfs' +$Env:PATH += ';C:\git\cmd;C:\git\mingw64\bin;C:\git\usr\bin;c:\git\lfs\git-lfs-2.12.0' # if the workspace is set we should make sure # it is the current working directory. @@ -21,6 +21,13 @@ login $Env:DRONE_NETRC_USERNAME password $Env:DRONE_NETRC_PASSWORD "@ > (Join-Path $Env:USERPROFILE '_netrc'); } +if ($Env:DRONE_NETRC_MACHINE) { +@" +machine $Env:DRONE_NETRC_MACHINE +login $Env:DRONE_NETRC_USERNAME +password $Env:DRONE_NETRC_PASSWORD +"@ > (Join-Path $Env:USERPROFILE '.netrc'); +} # configure git global behavior and parameters via the # following environment variables: From 566fda6a31ac9cfc5c7498942de2437a4640bc37 Mon Sep 17 00:00:00 2001 From: Johan Van de Wauw Date: Mon, 22 Jan 2024 23:26:16 +0000 Subject: [PATCH 4/5] Reorder path --- docker/Dockerfile.windows.ltsc2022 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile.windows.ltsc2022 b/docker/Dockerfile.windows.ltsc2022 index 52f9e8d..c38995a 100644 --- a/docker/Dockerfile.windows.ltsc2022 +++ b/docker/Dockerfile.windows.ltsc2022 @@ -17,7 +17,7 @@ ADD windows/* /bin/ # https://github.com/PowerShell/PowerShell/issues/6211#issuecomment-367477137 USER ContainerAdministrator -RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell;c:\git\cmd;c:\git\lfs\git-lfs-2.12.0" +RUN setx /M PATH "%PATH%;C:\Program Files\PowerShell;c:\git\lfs\;c:\git\cmd" SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] CMD [ "pwsh", "C:\\bin\\clone.ps1" ] From 8bf2403f8513512acfcf3010402a4ef305425331 Mon Sep 17 00:00:00 2001 From: Johan Van de Wauw Date: Fri, 9 Feb 2024 14:39:02 +0000 Subject: [PATCH 5/5] Remove depth flags empty string gives issues on 2022 --- windows/clone-tag.ps1 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/windows/clone-tag.ps1 b/windows/clone-tag.ps1 index a37a3f1..04b3992 100644 --- a/windows/clone-tag.ps1 +++ b/windows/clone-tag.ps1 @@ -1,13 +1,8 @@ -Set-Variable -Name "FLAGS" -Value "" -if ($Env:PLUGIN_DEPTH) { - Set-Variable -Name "FLAGS" -Value "--depth=$Env:PLUGIN_DEPTH" -} - if (!(Test-Path .git)) { git init git remote add origin $Env:DRONE_REMOTE_URL } -git fetch $FLAGS origin "+refs/tags/${Env:DRONE_TAG}:" +git fetch origin "+refs/tags/${Env:DRONE_TAG}:" git checkout -qf FETCH_HEAD