From 0af01290540776bd0a23dc68af66b458980aac38 Mon Sep 17 00:00:00 2001 From: efim Date: Fri, 15 Mar 2024 06:49:46 +0000 Subject: [PATCH] feat(18): not really working docker images --- 18-expenses-chart/flake.nix | 54 ++++++++++++++++++++++++++++++++++--- 18-expenses-chart/notes.org | 31 +++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/18-expenses-chart/flake.nix b/18-expenses-chart/flake.nix index b998fb7..9cc89d2 100644 --- a/18-expenses-chart/flake.nix +++ b/18-expenses-chart/flake.nix @@ -1,5 +1,5 @@ rec { - description = "templ-practice"; + description = "expenses chart exercise"; inputs = { nixpkgs.url = "github:nixos/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; @@ -11,7 +11,55 @@ rec { let pkgs = nixpkgs.legacyPackages.${system}; templPkg = templ.packages.${system}.templ; - in { + pname = "expenses-chart"; + version = "0.0.1"; + in rec { + thePackage = pkgs.buildGoModule { + inherit pname version; + src = pkgs.nix-gitignore.gitignoreSource [ ] ./.; + vendorHash = "sha256-sKuP3TsRD3MXBGtdSRnX62eXBQE1ASWFQu0kLlXSlFA="; + + preBuild = '' + # Adding the Tailwind build step to preBuild + ${pkgs.nodePackages.tailwindcss}/bin/tailwindcss -i ./input.css -o static/output.css + # Adding generation of go code from templ files + ${templPkg}/bin/templ generate + ''; + + }; + packages = rec { + "${pname}" = thePackage; + "${pname}-image" = pkgs.dockerTools.buildLayeredImage { + name = pname; + tag = "latest"; + created = "now"; + config = { + Cmd = [ "${thePackage}/bin/templ-exercise" ]; + ExposedPorts = { "3000/tcp" = { }; }; + }; + }; + image-hello = pkgs.dockerTools.buildLayeredImage { # so, wow, this works + name = pname; + tag = "latest"; + config.Cmd = [ "${pkgs.hello}/bin/hello" ]; + }; + + image = pkgs.dockerTools.buildImage { + name = pname; + tag = "latest"; + created = "now"; + copyToRoot = pkgs.buildEnv { + name = "image-root"; + paths = [ thePackage pkgs.dockerTools.binSh pkgs.coreutils ]; + pathsToLink = [ "/bin" "/dist" "/public" ]; + }; + config = { + Cmd = [ "/bin/templ-exercise" ]; + ExposedPorts = { "8080/tcp" = { }; }; + }; + }; + + }; devShells.default = pkgs.mkShell { buildInputs = [ pkgs.go @@ -20,7 +68,7 @@ rec { pkgs.gopls pkgs.gnumake templPkg - pkgs.tailwindcss + pkgs.nodePackages.tailwindcss ]; shellHook = '' export GOPATH=$PWD/.go diff --git a/18-expenses-chart/notes.org b/18-expenses-chart/notes.org index 0852590..c77ac43 100644 --- a/18-expenses-chart/notes.org +++ b/18-expenses-chart/notes.org @@ -74,3 +74,34 @@ because then if parent would want to have child take up all space - negative pad *** allright, @ to include sub templates +** well, last part? preparing the docker container for deployment on Render.com? + +which port should be used? +also, this would be first time i'll add templ as a build step + +** for some reason image doesn't work well + +podman run -d -p 9090:8080 localhost/expenses-chart:latest /nix/store/l4r6glmzbvkhg97lp4dn7nm76w6hz41g-expenses-chart-0.0.1/bin/temp-exercise + +this runs, +but podman run -it expenses-chart:latest +Error: crun: executable file `/nix/store/l4r6glmzbvkhg97lp4dn7nm76w6hz41g-expenses-chart-0.0.1/bin/templ-exercise` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found + +oh, well + +** you know what - i give up + +for some reason when i open url to app running in container, +and it's on the 8080 port of the host machine - the static files are served + +if i use any other port of local machine, to forward into container, +the static files are not served + +maybe this is bug in go? i don't know +StripPrefix doesn't seem to do anything + +and for some reason in this specific exercise CMD doesn't work in the container +so let's just give up! + +i could try to write a docker file and check with that, but yeah +