commit a9c08415926e0511f0ba901bdebd3c37a1f4f5de
parent a05d227138d584a78062ef126cf53a3e283cb0da
Author: James Eversole <james@eversole.co>
Date: Fri, 5 May 2023 19:38:59 -0500
Stop using a Cabal library to achieve reasonable Docker image sizes
Diffstat:
| M | Purr.cabal | | | 73 | +++++++++++++++++-------------------------------------------------------- |
| M | flake.lock | | | 52 | +++++++++++++++++++++++++++++++++++++++++++++++++++- |
| M | flake.nix | | | 19 | ++++++++++++++----- |
3 files changed, 82 insertions(+), 62 deletions(-)
diff --git a/Purr.cabal b/Purr.cabal
@@ -13,64 +13,11 @@ extra-source-files:
README
ChangeLog.md
-library
- exposed-modules:
- Core.Configuration
- Core.HTTP
- Core.SQLite
- Core.Templates
- Core.Types
- Feature.Generation.HTTP
- Feature.Generation.Links
- Feature.Generation.Passwords
- Feature.Generation.Shared
- Feature.Generation.Templates
- Feature.Sharing.HTTP
- Feature.Sharing.SQLite
- Feature.Sharing.Templates
- Lib
- other-modules:
- Paths_Purr
- hs-source-dirs:
- src
- default-extensions:
- ConstraintKinds
- DeriveGeneric
- FlexibleContexts
- FlexibleInstances
- GeneralizedNewtypeDeriving
- OverloadedStrings
- ScopedTypeVariables
- build-depends:
- base >=4.7
- , base64-bytestring >=1.2.0.0
- , blaze-html >=0.9.1.0
- , bytestring >=0.10.12.1
- , containers >=0.6.4.1
- , dhall >=1.40
- , file-embed ==0.0.15.0
- , http-types >=0.12.3
- , iso8601-time >=0.1.5
- , mtl >=2.2.2
- , random >=1.2
- , saltine >=0.2.0.0
- , scotty >=0.12
- , shakespeare >=2.0.20
- , split >=0.2.3.4
- , sqlite-simple >=0.4.18.0
- , text >=1.2.5.0
- , time >=1.9
- , utf8-string ==1.0.2
- , wai-extra >=3.1.12.1
- , wai-middleware-static >=0.5
- default-language: Haskell2010
-
executable Purr
main-is: Main.hs
- other-modules:
- Paths_Purr
hs-source-dirs:
app
+ , src
default-extensions:
ConstraintKinds
DeriveGeneric
@@ -81,8 +28,7 @@ executable Purr
ScopedTypeVariables
ghc-options: -threaded -rtsopts -with-rtsopts=-N -optl-pthread -fPIC
build-depends:
- Purr
- , base >=4.7
+ base >=4.7
, base64-bytestring >=1.2.0.0
, blaze-html >=0.9.1.0
, bytestring >=0.10.12.1
@@ -103,4 +49,19 @@ executable Purr
, utf8-string ==1.0.2
, wai-extra >=3.1.12.1
, wai-middleware-static >=0.5
+ other-modules:
+ Core.Configuration
+ Core.HTTP
+ Core.SQLite
+ Core.Templates
+ Core.Types
+ Feature.Generation.HTTP
+ Feature.Generation.Links
+ Feature.Generation.Passwords
+ Feature.Generation.Shared
+ Feature.Generation.Templates
+ Feature.Sharing.HTTP
+ Feature.Sharing.SQLite
+ Feature.Sharing.Templates
+ Lib
default-language: Haskell2010
diff --git a/flake.lock b/flake.lock
@@ -18,8 +18,57 @@
"type": "github"
}
},
+ "flake-utils_2": {
+ "locked": {
+ "lastModified": 1653893745,
+ "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nix2container": {
+ "inputs": {
+ "flake-utils": "flake-utils_2",
+ "nixpkgs": "nixpkgs"
+ },
+ "locked": {
+ "lastModified": 1677791117,
+ "narHash": "sha256-zL4Fc5133KMqX7zCzcPODaBPEblUfgQt2UccNBm34Pc=",
+ "owner": "nlewo",
+ "repo": "nix2container",
+ "rev": "85670cab354f7df69dd4af097c27cf9bc5826cb2",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nlewo",
+ "repo": "nix2container",
+ "type": "github"
+ }
+ },
"nixpkgs": {
"locked": {
+ "lastModified": 1677612629,
+ "narHash": "sha256-yC+9LfhfwOd5sXFW8TLnDmqVMNYiHXYPGy9BbdpRqfU=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "111ca8e0378e88d9decaa1c6dd7597f35d8bc67f",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "nixpkgs_2": {
+ "locked": {
"lastModified": 1683159243,
"narHash": "sha256-Fh41KQcZTswb4NyYfSsbNEhDS/Im0/Id6m3k7qZ6/Xw=",
"owner": "NixOS",
@@ -36,7 +85,8 @@
"root": {
"inputs": {
"flake-utils": "flake-utils",
- "nixpkgs": "nixpkgs"
+ "nix2container": "nix2container",
+ "nixpkgs": "nixpkgs_2"
}
},
"systems": {
diff --git a/flake.nix b/flake.nix
@@ -4,22 +4,29 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
+ nix2container.url = "github:nlewo/nix2container";
};
- outputs = { self, nixpkgs, flake-utils }:
+ outputs = { self, nixpkgs, flake-utils, nix2container }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
packageName = "purr";
dockerPackageName = "${packageName}-docker";
+ nix2containerPkgs = nix2container.packages.x86_64-linux;
+
haskellPackages = pkgs.haskellPackages;
enableSharedExecutables = false;
+ enableSharedLibraries = false;
+
+ purr = pkgs.haskell.lib.justStaticExecutables self.packages.${system}.default;
+
in {
+
packages.${packageName} =
- haskellPackages.callCabal2nix packageName self rec {
- };
+ haskellPackages.callCabal2nix packageName self rec {};
packages.default = self.packages.${system}.${packageName};
defaultPackage = self.packages.${system}.default;
@@ -33,17 +40,19 @@
};
devShell = self.devShells.${system}.default;
+
packages.${dockerPackageName} = pkgs.dockerTools.buildImage {
name = "purr";
+
copyToRoot = pkgs.buildEnv {
name = "image-root";
- paths = [ self.packages.${system}.default ];
+ paths = [ purr ];
pathsToLink = [ "/bin" ];
};
tag = "latest";
config = {
Cmd = [
- "/bin/Purr-musl"
+ "/bin/Purr"
];
ExposedPorts = {
"3000/tcp" = {};