Skip to content

Commit

Permalink
Convert from libbuildpack to powershell
Browse files Browse the repository at this point in the history
- Include profile.d support for multibuildpacks
  • Loading branch information
dgodd committed Jan 22, 2019
1 parent 844016a commit 3cbfc44
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 309 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
/go_buildpack-*.zip
/bin/finalize.exe
/bin/supply.exe
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
3 changes: 3 additions & 0 deletions bin/finalize.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF
SET ScriptDir=%~dp0
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%ScriptDir%finalize.ps1' %1 %2 %3 %4";
28 changes: 28 additions & 0 deletions bin/finalize.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)] [string]$BuildDir,
[Parameter(Mandatory=$True,Position=2)] [string]$CacheDir,
[Parameter(Mandatory=$True,Position=3)] [string]$DepsDir,
[Parameter(Mandatory=$True,Position=4)] [string]$DepsIdx
)

$ErrorActionPreference = "Stop"
$env:PATH += ";$DepsDir/$DepsIdx/bin"

Write-Output "-----> Build app"
Set-Location $BuildDir
go build -o myapp.exe .
if ($lastexitcode -ne 0) {
Write-Output "ERROR building app with go"
Write-Output "EXITCODE: $lastexitcode"
Exit 1
}

Write-Output "-----> Configure runtime path and env vars"
$dirs = Get-Childitem -Path $DepsDir | where{ Join-Path $_.FullName "bin" | Test-Path } | %{ '%DEPS_DIR%\' + $_.Name + '\bin' } | &{$ofs=';';"$input"}
Set-Content -Path "$DepsDir/../profile.d/000_multi-supply.bat" -Value "set PATH=$dirs;%PATH%"
Foreach ($d in (Get-Childitem -Path $DepsDir | where{ Join-Path $_.FullName "profile.d" | Test-Path })) {
Foreach ($f in (Get-Childitem -Path "$DepsDir/$d/profile.d")) {
Copy-Item $f.FullName -Destination "$DepsDir/../profile.d/${d}_${f}"
}
}
3 changes: 3 additions & 0 deletions bin/supply.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ECHO OFF
SET ScriptDir=%~dp0
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%ScriptDir%supply.ps1' %1 %2 %3 %4";
32 changes: 32 additions & 0 deletions bin/supply.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)] [string]$BuildDir,
[Parameter(Mandatory=$True,Position=2)] [string]$CacheDir,
[Parameter(Mandatory=$True,Position=3)] [string]$DepsDir,
[Parameter(Mandatory=$True,Position=4)] [string]$DepsIdx
)

$ErrorActionPreference = "Stop"
# Write-Output " BuildDir: $BuildDir"
# Write-Output " CacheDir: $CacheDir"
# Write-Output " DepsDir: $DepsDir"
# Write-Output " DepsIdx: $DepsIdx"
# Write-Output ""

$Version = (Get-Content "$PSScriptRoot/../VERSION" -Raw).Replace("`n","").Replace("`r","")
Write-Output "-----> Go Buildpack (version $Version)"

Write-Output "-----> Download go"
$ProgressPreference = 'SilentlyContinue'
(New-Object System.Net.WebClient).DownloadFile('https://dl.google.com/go/go1.11.4.windows-amd64.zip', "$CacheDir/go.zip")
$ExpectedSHA = 'eeb20e21702f2b9469d9381df5de85e2f731b64a1f54effe196d0f7d0227fe14'
$ActualSHA = (Get-FileHash "$CacheDir/go.zip" -Algorithm SHA256).Hash
If ($ExpectedSHA -ne $ActualSHA) {
Write-Output "go.zip checksum did not match. expected '$ExpectedSHA', found '$ActualSHA'"
Exit 1
}

Write-Output "-----> Extract go"
Expand-Archive -Path "$CacheDir/go.zip" -DestinationPath "$DepsDir/$DepsIdx" -Force
Move-Item -Path "$DepsDir/$DepsIdx/go/*" -Destination "$DepsDir/$DepsIdx"
Remove-Item -Path "$DepsDir/$DepsIdx/go"
28 changes: 0 additions & 28 deletions finalize.go

This file was deleted.

60 changes: 0 additions & 60 deletions finalize/main.go

This file was deleted.

3 changes: 0 additions & 3 deletions go.mod

This file was deleted.

53 changes: 0 additions & 53 deletions go.sum

This file was deleted.

28 changes: 0 additions & 28 deletions interfaces.go

This file was deleted.

9 changes: 0 additions & 9 deletions manifest.yml

This file was deleted.

5 changes: 1 addition & 4 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ $ErrorActionPreference = "Stop"
$Version = (Get-Content "$PSScriptRoot/../VERSION" -Raw).Replace("`n","").Replace("`r","")

cd "$PSScriptRoot/.."
$env:GOOS = "windows"
go build -o bin/supply.exe ./supply/
go build -o bin/finalize.exe ./finalize/
Compress-Archive -LiteralPath bin, manifest.yml, VERSION -CompressionLevel Optimal -DestinationPath "$PSScriptRoot/../go_buildpack-windows2016-v$Version.zip" -Force
Compress-Archive -LiteralPath bin, VERSION -CompressionLevel Optimal -DestinationPath "$PSScriptRoot/../go_buildpack-windows2016-v$Version.zip" -Force

37 changes: 0 additions & 37 deletions supply.go

This file was deleted.

84 changes: 0 additions & 84 deletions supply/main.go

This file was deleted.

0 comments on commit 3cbfc44

Please sign in to comment.