Skip to content

Commit

Permalink
Using dotnet-packaging to create debian package
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Byrd committed May 22, 2018
1 parent 0fb1250 commit f33e51b
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 266 deletions.
117 changes: 23 additions & 94 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -1179,101 +1179,30 @@ Target.create "CheckReleaseSecrets" (fun _ ->
secret.Force() |> ignore
)

let executeFPM args workingDir =
printfn "%s %s" "fpm" args
Shell.Exec("fpm", args=args, dir=workingDir)


type SourceType =
| Dir of source:string * target:string
type DebPackageManifest =
{
SourceType : SourceType
Name : string
Version : string
Architecture : string
Dependencies : (string * string option) list
BeforeInstall : string option
AfterInstall : string option
ConfigFile : string option
AdditionalOptions: string list
AdditionalArgs : string list
}
(*
See https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
Ask @theangrybyrd (slack)
{
SourceType = Dir("./MyCoolApp", "/opt/")
Name = "mycoolapp"
Version = originalVersion
Dependencies = [("mono-devel", None)]
BeforeInstall = "../deploy/preinst" |> Some
AfterInstall = "../deploy/postinst" |> Some
ConfigFile = "/etc/mycoolapp/default.conf" |> Some
AdditionalOptions = []
AdditionalArgs =
[ "../deplo/mycoolapp.service=/lib/systemd/system/" ]
}
23:08
so thats stuff i you want to setup like users or what not
23:09
adding to your path would be in the after script postinst
23:10
setting permissions also, its just a shell script
23:10
might also want a prerm and postrm if you want to play nice on cleanup
*)

Target.create "DotNetCoreCreateDebianPackage" (fun _ ->
let createDebianPackage (manifest : DebPackageManifest) workingDir =
let argsList = ResizeArray<string>()
argsList.Add <| match manifest.SourceType with
| Dir (_) -> "-s dir"
argsList.Add <| sprintf "-a %s" manifest.Architecture
argsList.Add <| "-t deb"
argsList.Add <| "-f"
argsList.Add <| (sprintf "-n %s" manifest.Name)
argsList.Add <| (sprintf "-v %s" (manifest.Version.Replace("-","~")))
let dependency name version =
match version with
| Some v -> sprintf "-d %s %s" name v
| None -> sprintf "-d %s" name
argsList.AddRange <| (Seq.map(fun (a,b) -> dependency a b) manifest.Dependencies)
manifest.BeforeInstall |> Option.iter(sprintf "--before-install %s" >> argsList.Add)
manifest.AfterInstall |> Option.iter(sprintf "--after-install %s" >> argsList.Add)
manifest.ConfigFile |> Option.iter(sprintf "--config-files %s" >> argsList.Add)
argsList.AddRange <| manifest.AdditionalOptions
argsList.Add <| match manifest.SourceType with
| Dir (source,target) -> sprintf "%s=%s" source target
argsList.AddRange <| manifest.AdditionalArgs
let args = argsList |> String.concat " "
if executeFPM args workingDir <> 0 then
failwith "Failed creating deb package"

let manifest = {
SourceType = Dir(".", "/opt/fake")
Name = "fake"
Version = release.NugetVersion
Architecture = "amd64"
Dependencies = [
// https://github.com/dotnet/cli/issues/3390#issuecomment-282488747
("libunwind8", None)
// https://stackoverflow.com/a/49744600/890736
("icu-devtools", None)
]
BeforeInstall =__SOURCE_DIRECTORY__ @@ "packaging/debian/preinst" |> Some
AfterInstall = __SOURCE_DIRECTORY__ @@ "packaging/debian/postinst" |> Some
ConfigFile = None
AdditionalOptions = []
AdditionalArgs =
[ ]
}

__SOURCE_DIRECTORY__ @@ "nuget/dotnetcore/Fake.netcore/linux-x64"
|> createDebianPackage manifest

DotNet.restore (fun opt ->
{ opt with
Common = { opt.Common with WorkingDirectory = "src/app/Fake.netcore/" } |> dtntSmpl
Runtime = Some "linux-x64"}) "Fake.netcore.fsproj"
let args =
[
sprintf "/t:%s" "CreateDeb"
sprintf "/p:TargetFramework=%s" "netcoreapp2.0"
sprintf "/p:RuntimeIdentifier=%s" "linux-x64"
sprintf "/p:Configuration=%s" "Release"
sprintf "/p:PackageVersion=%s" release.NugetVersion
] |> String.concat " "
let result =
DotNet.exec (fun opt ->
{ opt with
WorkingDirectory = "src/app/Fake.netcore/" } |> dtntSmpl
) "msbuild" args
if result.OK |> not then
failwith "Debian package creation failed"

[(sprintf "src/app/Fake.netcore/bin/Release/netcoreapp2.0/linux-x64/fake-cli.%s.linux-x64.deb" release.NugetVersion)]
|> Shell.copy artifactsDir

)

Expand Down Expand Up @@ -1587,7 +1516,7 @@ let prevDocs =
==> "CreateNuGet"
==> "CopyLicense"
=?> ("DotNetCoreCreateChocolateyPackage", Environment.isWindows)
=?> ("DotNetCoreCreateDebianPackage", Environment.isWindows |> not)
==> "DotNetCoreCreateDebianPackage"
=?> ("GenerateDocs", BuildServer.isLocalBuild && Environment.isWindows)
==> "Default"
(if fromArtifacts then "PrepareArtifacts" else "_AfterBuild")
Expand Down
2 changes: 1 addition & 1 deletion fake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel Curre

PATH="~/.dotnet:$PATH"
dotnet restore build.proj
dotnet fake $@
dotnet fake $@
4 changes: 2 additions & 2 deletions packaging/debian/postinst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

chmod +x /opt/fake/fake
ln -s /opt/fake/fake /usr/local/bin/fake
chmod +x /opt/fake/fake-cli
ln -s /opt/fake/fake-cli /usr/local/bin/fake-cli
4 changes: 3 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ nuget Octokit
nuget System.Net.Http
nuget Microsoft.DotNet.PlatformAbstractions
nuget FSharp.Control.Reactive

// From FSharp.Compiler.Service, but manually managed because of rename
nuget System.ValueTuple copy_local: true, redirects:force

Expand Down Expand Up @@ -167,4 +168,5 @@ group netcore
nuget System.IO.Compression.ZipFile
nuget System.Runtime.Loader
nuget System.IO.FileSystem.Watcher

nuget Packaging.Targets

0 comments on commit f33e51b

Please sign in to comment.