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

create docker container #2

Closed aleeusgr closed 1 year ago

aleeusgr commented 1 year ago

Docs

Haskell

https://discourse.haskell.org/t/haskell-and-docker/499 https://docs.haskellstack.org/en/stable/docker_integration/ https://hub.docker.com/_/haskell https://github.com/haskell/docker-haskell

Docker

https://dockerlabs.collabnix.com/docker/cheatsheet/ https://docs.docker.com/develop/develop-images/baseimages/ https://docs.docker.com/engine/reference/builder/ https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ https://thoughtbot.com/blog/easy-haskell-development-and-deployment-with-docker

Nix

https://nix.dev/tutorials/building-and-running-docker-images

aleeusgr commented 1 year ago

NixOS development environment setup:

$ docker-compose build hello-postgresql $ docker run --rm --interactive --tty thoughtbot/ghc $ docker --version OK [+] Building 0.0s (0/0)

no valid drivers found: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied

Solution:

extraGroups = [ "docker" ]; in configuration.nix

aleeusgr commented 1 year ago

Dockerize an application, from here

using stack:

FROM haskell:8.10
RUN stack install --resolver lts-17.14 pandoc citeproc
ENTRYPOINT ["pandoc"]

using cabal:

FROM haskell:8.10
RUN cabal update && cabal install pandoc citeproc
ENTRYPOINT ["pandoc"]
aleeusgr commented 1 year ago

Dockerize any app

  1. Choose a base Image DESIGN OPTIONS:
  1. Install the necessary packages link
  2. Add your custom files
  3. Define which user will (or can) run your container
  4. Define the exposed ports
  5. Define the entrypoint
  6. Define a Configuration method
  7. Externalize your data
  8. handle the logs as well
aleeusgr commented 1 year ago

FromScratch

  1. have docker installed
  2. mkdir&cd, cabal init
  3. Create Dockerfile (how? Search github for examples, touch Dockerfile is recommended in docker docs)
  4. docker build -t . (~build pwd)

Error: cabal: There is no .cabal package file or cabal.project file. To build packages locally you need at minimum a .cabal file. You can use 'cabal init' to create one.

For non-trivial projects you will also want a cabal.project file in the root directory of your project. This file lists the packages in your project and all other build configuration. See the Cabal user guide for full details.

aleeusgr commented 1 year ago

nix haskell hello -> simplest dockerfile

https://github.com/ners/hello-haskell

✅ nix run

Next: search "dokerize nix" https://nix.dev/tutorials/building-and-running-docker-images

Why not?

Nobbz on discord:

Why don't you use nix to build the container, rather than using nix in the container? Use dockerTools

aleeusgr commented 1 year ago

https://www.fpcomplete.com/blog/2015/05/haskell-web-server-in-5mb/

code

This runs:

docker pull fpco/rdr2tls
docker run -i -t --rm -p 8080:8080 fpco/rdr2tls

test it : curl -v 'http://localhost:8080/remote/worker?pants=YES'

but rebuilding fails.

aleeusgr commented 1 year ago

/bin/sh: stack: not found The command '/bin/sh -c stack setup' returned a non-zero code: 127

nix haskell hello -> simplest dockerfile

https://github.com/ners/hello-haskell

white_check_mark nix run

Next: search "dokerize nix"

And I have nix docker image

  1. add code
aleeusgr commented 1 year ago

$ docker run f2b203482528 GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help Prelude> Leaving GHCi.

Step 4/4 : RUN cabal run ---> Running in 6c362e4ef754 Error: cabal: There is no .cabal package file or cabal.project file. To build packages locally you need at minimum a .cabal file. You can use 'cabal init' to create one.

aleeusgr commented 1 year ago

https://github.com/phadej/docker-haskell-example

Hello @phadej! I was looking for some multi-stage build Dockerfiles for Haskell projects and I happened upon this one, which has some great tips. I think one currently agreed-upon Docker best practice is missing, though, from your Dockerfile: don't run processes as root. It may be worth changing here if people are finding your blog-post and copying the code in there? I could probably submit a PR to this repo if you think it's worth it.

09:00 $ cabal run cabal: Could not resolve dependencies:
[0] trying: docker-haskell-example-0 (user goal)
[
1] trying: warp-3.2.27 (dependency of docker-haskell-example)
[2] trying: wai-3.2.2 (dependency of warp)
[
3] trying: transformers-0.5.6.2/installed-0.5.6.2 (dependency of wai)
[4] next goal: vault (dependency of warp)
[
4] rejecting: vault-0.3.1.2 (conflict: transformers =>base==4.15.1.0/installed-4.15.1.0, vault => base>=4.5 && <4.13)

09:00 $ docker run docker-haskell-example docker-haskell-example: user error (PASSWORD not set)

aleeusgr commented 1 year ago

https://github.com/tweag/stack-docker-nix

aleeusgr commented 1 year ago

Small Docker images with Alpine, Haskell, and Stack

aleeusgr commented 1 year ago

https://github.com/srid/haskell-flake https://github.com/srid/haskell-template https://srid.ca/haskell-template/start https://srid.ca/haskell-template

OR https://magnus.therning.org/2022-03-13-simple-nix-flake-for-haskell-development.html

aleeusgr commented 1 year ago

✅nixpkgs.dockerTools

Intro

Packaging a Haskell library for artefact evaluation using nix

2021-03-26-HASKELL-DOCKER-NIX

User manual

another User manual

https://vaibhavsagar.com/blog/2019/08/11/ihaskell-nix-docker/

aleeusgr commented 1 year ago

Building docker container requires nix-build to complete:

https://github.com/SIDANWhatever/plutus-cborhex-automation/issues/18