sidan-lab / plutus-cborhex-automation

A Haskell package for creating RESTful API endpoints for dynamic parameterized Cardano Plutus script.
15 stars 3 forks source link

REST endpoint: test existing solutions #16

Closed aleeusgr closed 1 year ago

aleeusgr commented 1 year ago

Spock tutorial

stack build --fast --pedantic

1

zlib > Configuring zlib-0.6.3.0... cryptonite > [109 of 137] Compiling Crypto.KDF.BCrypt
zlib > Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2: Missing dependency on a foreign
zlib > library:
zlib > Missing (or bad) header file: zlib.h
zlib >
Missing (or bad) C library: z
zlib > This problem can usually be solved by installing the system package that
zlib > provides this library (you may need the "-dev" version). If the library is
zlib > already installed but in a non-standard location then you can use the flags
zlib > --extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
zlib > library file does exist, it may contain errors that are caught by the C
zlib > compiler at the preprocessing stage. In this case you can re-run configure
zlib > with the verbosity flag -v3 to see the error messages.
zlib > If the header file does exist, it may contain errors that are caught by the C
zlib > compiler at the preprocessing stage. In this case you can re-run configure
zlib > with the verbosity flag -v3 to see the error messages.
zlib >

lead

Solution:

add following code to stack.yml

⚠️WARNING: read this for better option

 nix:
    enable:  true
    packages: [zlib.dev, zlib.out]

2

-- While building package primitive-extras-0.8 (scroll up to its section to see the error) using: primitive-extras > Ambiguous occurrence ‘singleton’ primitive-extras > It could refer to
primitive-extras > either ‘PrimitiveExtras.Prelude.singleton’, primitive-extras > imported from ‘PrimitiveExtras.Prelude’ at library/PrimitiveExtras/Bitmap. hs:25:1-70
primitive-extras > (and originally defined in ‘base-4.15.1.0:Data.OldList’) primitive-extras > or ‘PrimitiveExtras.Bitmap.singleton’, primitive-extras > defined at library/PrimitiveExtras/Bitmap.hs:53:1 primitive-extras > |
primitive-extras > 5 | singleton, primitive-extras > | ^^^^^^^^^

Originally posted by @aleeusgr in https://github.com/SIDANWhatever/plutus-cborhex-automation/issues/3#issuecomment-1278544029

Suggestion:

aleeusgr commented 1 year ago

error: (42 results) [35/1870] Spock-core > • Couldn't match type: forall a. Spock-core > ActionCtxT ctx m a -> ActionCtxT () m a Spock-core > with: ActionCtxT ctx m () -> ActionCtxT () m () Spock-core > Expected: LiftHooked ctx m -> ActionCtxT ctx m () -> ActionT m () Spock-core > Actual: LiftHooked ctx m Spock-core > -> forall a. ActionCtxT ctx m a -> ActionCtxT () m a Spock-core > • In the first argument of ‘asks’, namely ‘unLiftHooked’ Spock-core > In the second argument of ‘($)’, namely ‘asks unLiftHooked’ Spock-core > In a stmt of a 'do' block: hookLift <- lift $ asks unLiftHooked Spock-core > • Relevant bindings include Spock-core > action :: [T.Text] -> ActionCtxT ctx m () Spock-core > (bound at src/Web/Spock/Core.hs:78:15) Spock-core > wireAny :: SpockMethod Spock-core > -> ([T.Text] -> ActionCtxT ctx m ()) -> SpockCtxT ctx m () Spock-core > (bound at src/Web/Spock/Core.hs:78:5) Spock-core > | Spock-core > 80 | do hookLift <- lift $ asks unLiftHooked Spock-core > | ^^^^^^^^^^^^ Spock-core > Spock-core > /run/user/1000/stack-87827ee7c5625bb0/Spock-core-0.14.0.0/src/Web/Spock/Core.hs:106:32: error:

aleeusgr commented 1 year ago

Yesod

https://gitlab.haskell.org/ghc/ghc/-/issues/22301

aleeusgr commented 1 year ago

🆗

  1. stack new hello-spock: check alt Design Options
  2. add nix support
  3. nix-shell -> stack build -> stack exec ✅
  4. add Docker support
  5. docker build -t 'name' . [fail]
  6. https://github.com/tweag/stack-docker-nix/issues/10
    >Step 3/13 : RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories
    ---> Running in 769c46699550
    /bin/sh: line 1: /etc/apk/repositories: No such file or directory
    The command '/bin/sh -c echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories' returned a non-zero code: 1

    SMOOTH, NON-INVASIVE HASKELL STACK AND NIX SHELL INTEGRATION

    So while Nix might be great for you, it’s helpful if it’s optional for others. Therefore, any solution combining Nix and Stack should be non-invasive and also work for those who don’t use Nix.

aleeusgr commented 1 year ago

the solution above works, but further development is blocked: docker does not build with it. Try different solution first: https://github.com/srid/haskell-template/discussions/65

error: nix experimental features disabled

aleeusgr commented 1 year ago

https://input-output-hk.github.io/haskell.nix/tutorials/getting-started-flakes.html https://input-output-hk.github.io/haskell.nix/tutorials/getting-started-hix.html

aleeusgr commented 1 year ago

https://github.com/maxice8/ac-abuild

aleeusgr commented 1 year ago

https://nixos.wiki/wiki/Docker https://codesandbox.io/docs/tutorial/getting-started-with-docker https://lethalman.blogspot.com/2016/04/cheap-docker-images-with-nix_15.html https://unix.stackexchange.com/questions/588575/building-docker-image-with-nix-dockertools-buildimage-no-internet-access-in-bu https://jpetazzo.github.io/2020/04/01/quest-minimal-docker-images-part-3/

search nix dockertools

https://stackoverflow.com/questions/43375880/how-to-build-a-docker-container-with-nix https://ryantm.github.io/nixpkgs/builders/images/dockertools/ https://thewagner.net/blog/2021/02/25/building-container-images-with-nix/ https://nix.dev/tutorials/building-and-running-docker-images

aleeusgr commented 1 year ago

https://github.com/aleeusgr/hello-haskell-ci/commit/0a62b34b070cb5a3210319e613d194d17b73d887

milestone achieved: working production environment that can be build into a docker container (see test-docker-nix.sh), or tested nix run or developed nix develop flakes need to be enabled in nix.