Skip to content

Commit

Permalink
Initial debian packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Byrd committed Apr 12, 2018
1 parent b011a60 commit b8aef4b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
52 changes: 43 additions & 9 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ let netCoreProjs =
!! (appDir </> "*/*.fsproj")

let runtimes =
[ "win7-x86"; "win7-x64"; "osx.10.11-x64"; "ubuntu.14.04-x64"; "ubuntu.16.04-x64" ]
[ "win7-x86"; "win7-x64"; "osx.10.11-x64"; "linux-x64" ]

module CircleCi =
let isCircleCi = Environment.environVarAsBool "CIRCLECI"
Expand Down Expand Up @@ -824,9 +824,9 @@ Target.create "CheckReleaseSecrets" (fun _ ->
Environment.environVarOrFail "github_user" |> ignore
Environment.environVarOrFail "github_token" |> ignore
)
let executeFPM args =
let executeFPM args workingDir =
printfn "%s %s" "fpm" args
Shell.Exec("fpm", args=args, dir="bin")
Shell.Exec("fpm", args=args, dir=workingDir)

type SourceType =
| Dir of source:string * target:string
Expand All @@ -835,6 +835,7 @@ type DebPackageManifest =
SourceType : SourceType
Name : string
Version : string
Architecture : string
Dependencies : (string * string option) list
BeforeInstall : string option
AfterInstall : string option
Expand All @@ -846,6 +847,15 @@ type DebPackageManifest =
See https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
Ask @theangrybyrd (slack)
-s dir -t deb -f \
-n vision-server -v 2.57.0~beta001 \
-d 'mono-devel' --before-install ../deploy/vision-server/preinst \
--after-install ../deploy/vision-server/postinst \
--config-files /etc/vision-server/vision-server.conf \
./BDS.Endpoint.Server=/opt/ ../deploy/00-vision=/etc/sudoers.d/ \
../deploy/vision-server.conf=/etc/vision-server/ \
../deploy/vision-server/bds-endpoint-server.service=/lib/systemd/system/
{
SourceType = Dir("./MyCoolApp", "/opt/")
Name = "mycoolapp"
Expand All @@ -869,18 +879,19 @@ might also want a prerm and postrm if you want to play nice on cleanup
*)

Target.create "DotNetCoreCreateDebianPackage" (fun _ ->
let createDebianPackage (manifest : DebPackageManifest) =
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
| 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)
Expand All @@ -889,10 +900,32 @@ Target.create "DotNetCoreCreateDebianPackage" (fun _ ->
argsList.Add <| match manifest.SourceType with
| Dir (source,target) -> sprintf "%s=%s" source target
argsList.AddRange <| manifest.AdditionalArgs
if argsList |> String.concat " " |> executeFPM <> 0 then
let args = argsList |> String.concat " "
if executeFPM args workingDir <> 0 then
failwith "Failed creating deb package"
ignore createDebianPackage
()

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


)

Expand Down Expand Up @@ -1045,6 +1078,7 @@ open Fake.Core.TargetOperators
=?> ("CreateNuGet", Environment.isWindows)
==> "CopyLicense"
=?> ("DotNetCoreCreateChocolateyPackage", Environment.isWindows)
=?> ("DotNetCoreCreateDebianPackage", Environment.isWindows |> not)
=?> ("GenerateDocs", BuildServer.isLocalBuild && Environment.isWindows)
==> "Default"

Expand Down
4 changes: 4 additions & 0 deletions packaging/debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

chmod +x /opt/fake/fake
ln -s /opt/fake/fake /usr/local/bin/fake
1 change: 1 addition & 0 deletions packaging/debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/sh
1 change: 1 addition & 0 deletions packaging/debian/preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/sh
1 change: 1 addition & 0 deletions packaging/debian/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/bin/sh

0 comments on commit b8aef4b

Please sign in to comment.