Files
BitBetter/build.ps1
Michiel Hazelhof 287b6a4d34 Fixes for newer containers (#280)
* Find the new file

Next extract Core.dll, patch, reinsert

* Prepare Linux script too

* Extract and patch Core.dll again

* Make build script dynamic

* Cleanup after ourselves

* Build, then delete file

* Attempt to deconstruct the new file

* Add missing quotes

* Add missing file

* Rectify dll location

* Fix dumb extra character matching

* Dynamically find LicensingService and improve error reporting

* Upgrade package

* Implement new code

* Filter out new lines

* Force the runtime config

* Use correct external .NET library

* Update to .NET 10 in build.sh

Copy .NET 10 runtime from aspnet10.0-alpine3.23 to the bitwarden-lite container

* Update to .NET 10 in build.ps1

Copy .NET 10 runtime from aspnet:10.0-alpine3.23 to bitwarden-lite container

* Update generateKeys.sh to OpenSSL 3.x-compatible

Update to OpenSSL 3.x-compatible cipher generation

* Update generateKeys.ps1 to OpenSSL 3.x-compatible

Update to OpenSSL 3.x-compatible cipher

* Update bitBetter Dockerfile to .NET 10

* Update bitBetter.csproj to .NET 10

* Switch to X509CertificateLoader, switch to patching multiple thumbprint certificates

Update Program.cs in bitBetter to switch from deprecated X509Certificate to X509CertificateLoader
Patch multiple thumbprint certificate instances

* Update licenseGen Dockerfile to .NET 10

* Update licenseGen.csproj to .NET 10

* Remove extra line

* Get rid of extra line

* Update deprecated X509Certificate2 in LicenseGen

* Cleanup

* Fix tabbing

---------

Co-authored-by: Michiel Hazelhof <m.hazelhof@fyn.nl>
Co-authored-by: huntb4646 <94577767+huntb4646@users.noreply.github.com>
2026-06-05 20:09:27 +02:00

147 lines
5.2 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
# detect buildx, ErrorActionPreference will ensure the script stops execution if not found
docker buildx version
# Enable BuildKit for better build experience and to ensure platform args are populated
$env:DOCKER_BUILDKIT=1
$env:COMPOSE_DOCKER_CLI_BUILD=1
# define temporary directory
$tempdirectory = "$pwd\temp"
# define services to patch
$components = "Api","Identity"
# delete old directories / files if applicable
if (Test-Path "$tempdirectory" -PathType Container) {
Remove-Item "$tempdirectory" -Recurse -Force
}
if (Test-Path -Path "$pwd\src\licenseGen\Core.dll" -PathType Leaf) {
Remove-Item "$pwd\src\licenseGen\Core.dll" -Force
}
if (Test-Path -Path "$pwd\src\licenseGen\cert.pfx" -PathType Leaf) {
Remove-Item "$pwd\src\licenseGen\cert.pfx" -Force
}
if (Test-Path -Path "$pwd\src\bitBetter\cert.cer" -PathType Leaf) {
Remove-Item "$pwd\src\bitBetter\cert.cer" -Force
}
if (Test-Path "$pwd\.keys\cert.cert" -PathType Leaf) {
Rename-Item -Path "$pwd\.keys\cert.cert" -NewName "$pwd\.keys\cert.cer"
}
# generate keys if none are available
if (!(Test-Path "$pwd\.keys" -PathType Container)) {
.\generateKeys.ps1
}
# copy the key to bitBetter
Copy-Item "$pwd\.keys\cert.cer" -Destination "$pwd\src\bitBetter"
# build bitBetter and clean the source directory after
docker build --no-cache -t bitbetter/bitbetter "$pwd\src\bitBetter"
Remove-Item "$pwd\src\bitBetter\cert.cer" -Force
# gather all running instances, cannot run a wildcard filter on Ancestor= :(, does find all where name = *bitwarden*
$oldinstances = docker container ps --all -f Name=bitwarden --format '{{.ID}}'
# stop and remove all running instances
foreach ($instance in $oldinstances) {
docker stop $instance
docker rm $instance
}
# update bitwarden itself
if ($args[0] -eq 'update') {
docker pull ghcr.io/bitwarden/lite:latest
} else {
$confirmation = Read-Host "Update (or get) bitwarden source container (y/n)"
if ($confirmation -eq 'y') {
docker pull ghcr.io/bitwarden/lite:latest
}
}
# stop and remove previous existing patch(ed) container
$oldinstances = docker container ps --all -f Ancestor=bitwarden-patched --format '{{.ID}}'
foreach ($instance in $oldinstances) {
docker stop $instance
docker rm $instance
}
$oldinstances = docker image ls bitwarden-patched --format '{{.ID}}'
foreach ($instance in $oldinstances) {
docker image rm $instance
}
# remove old extract containers
$oldinstances = docker container ps --all -f Name=bitwarden-extract --format '{{.ID}}'
foreach ($instance in $oldinstances) {
docker stop $instance
docker rm $instance
}
# start a new bitwarden instance so we can patch it
$patchinstance = docker run -d --name bitwarden-extract ghcr.io/bitwarden/lite:latest
# create our temporary directory
New-item -ItemType Directory -Path $tempdirectory
# extract the files that need to be patched from the services that need to be patched into our temporary directory
foreach ($component in $components) {
New-item -itemtype Directory -path "$tempdirectory\$component"
docker cp $patchinstance`:/app/$component/$component "$tempdirectory\$component\$component"
docker cp $patchinstance`:/etc/supervisor.d/$($component.ToLower()).ini "$tempdirectory\$($component.ToLower()).ini"
}
# stop and remove our temporary container
docker stop bitwarden-extract
docker rm bitwarden-extract
# run bitBetter, this applies our patches to the required files
docker run -v "$tempdirectory`:/app/mount" --rm bitbetter/bitbetter
# create a new image with the patched files
if (Test-Path -Path "$pwd\Dockerfile-bitwarden-patch" -PathType Leaf) {
Remove-Item "$pwd\Dockerfile-bitwarden-patch" -Force
}
$dockerFile = "FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine3.23"
$dockerFile = -join($dockerFile, "FROM ghcr.io/bitwarden/lite:latest")
$dockerFile = -join($dockerFile, "COPY --from=0 /usr/share/dotnet /usr/share/dotnet")
foreach ($component in $components) {
$dockerFile = -join($dockerFile, "`n`nCOPY ./temp/$component/ /app/$component/")
$dockerFile = -join($dockerFile, "`nCOPY ./temp/$($component.ToLower()).ini /etc/supervisor.d/$($component.ToLower()).ini")
$dockerFile = -join($dockerFile, "`nRUN rm -f /app/$component/$component")
}
[System.IO.File]::WriteAllLines("$pwd\Dockerfile-bitwarden-patch", $dockerFile)
docker build . --tag bitwarden-patched --file "$pwd\Dockerfile-bitwarden-patch"
Remove-Item "$pwd\Dockerfile-bitwarden-patch" -Force
# start all user requested instances
if (Test-Path -Path "$pwd\.servers\serverlist.txt" -PathType Leaf) {
foreach($line in Get-Content "$pwd\.servers\serverlist.txt") {
if ((-not ($line.StartsWith("#"))) -and (-not [string]::IsNullOrWhiteSpace($line))) {
Invoke-Expression "& $line"
}
}
}
# remove our bitBetter image
docker image rm bitbetter/bitbetter
# copy our patched library to the licenseGen source directory
Copy-Item "$tempdirectory\Identity\Core.dll" -Destination "$pwd\src\licenseGen"
Copy-Item "$pwd\.keys\cert.pfx" -Destination "$pwd\src\licenseGen"
# build the licenseGen
docker build -t bitbetter/licensegen "$pwd\src\licenseGen"
# clean the licenseGen source directory
Remove-Item "$pwd\src\licenseGen\Core.dll" -Force
Remove-Item "$pwd\src\licenseGen\cert.pfx" -Force
# remove our temporary directory
Remove-Item "$tempdirectory" -Recurse -Force