From cd4ff482a393d80af42641552b64f001383462ed Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Tue, 1 Oct 2024 15:32:53 +0200 Subject: [PATCH] nix: minimize + compress resulting binary (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * nix: add package * nix: add container image * nix: minimize + compress resulting binary --------- Co-authored-by: Lars Sjöström --- flake.nix | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 79d9ef3..df8d0af 100644 --- a/flake.nix +++ b/flake.nix @@ -38,12 +38,16 @@ ]; in { - packages = { + + packages = rec { default = pkgs.buildGo123Module { pname = "envoy-oidc-authserver"; version = "main"; src = ./.; + ldflags = [ "-s -w" ]; + CGO_ENABLED = "0"; + meta = { desciption = "Envoy OIDC Authserver"; homepage = "https://github.com/shelmangroup/envoy-oidc-authserver"; @@ -61,13 +65,17 @@ prePatch = '' HOME="$TMPDIR" ${pkgs.buf}/bin/buf generate ''; + + postInstall = '' + ${pkgs.upx}/bin/upx $out/bin/envoy-oidc-authserver + ''; }; container = pkgs.dockerTools.buildImage { name = "envoy-oidc-authserver"; tag = "latest"; - copyToRoot = [ self.packages.${system}.default ]; - config.Entrypoint = [ (lib.getExe self.packages.${system}.default) ]; + copyToRoot = [ default ]; + config.Entrypoint = [ "${default}/bin/envoy-oidc-authserver" ]; }; };