introduction to stack's docker integration (1)
TRANSCRIPT
Nice to meet you! (^-^)Yuji Yamamoto (@igrep) age 27.
NO RELATION WITH Emacs plugin "igrep.el"!
Nice to meet you! (^-^)Software Engineer at GMO CLICK Holdings, Inc.
Writing online trading market of GMO CLICK Securities, Inc. in Java.
Hobby Haskeller.
Using Haskell for 4 years.
Holding workshop of Haskell (almost) every month.
Nice to meet you! (^-^)( ̄^ ̄) Professional Haskeller.
(;^ω^) Used to be. Just for a month
(;_;) Using Haskell was given up
Due to difficulty of teaching my colleagues...
Advertisement m(_ _)m 1HaskellJP wiki:
http://wiki.haskell.jp “〆(゚_゚*)
Anyone can edit with a GitHub account!
The most helpful page: Haskellに関する日本語のリンク集Haskell-related pages in Japanese
Recently all edits are only by me... (;_;)
Advertisement m(_ _)m 2Published a blog post 「JavaでMonadをはじめからていねいに」 “〆(゚_゚*)
Monad in Java from the beggining
( ̄^ ̄) Told the relation between the do notation and the associative law most clearly!
I'm gonna talk about...What is Stack's Docker integration
How it works
Tips on using it
Case study
(^w^) May help you to convince your boss to adapt Haskell!
I'm NOT gonna talk about...Basic usage of Stack
Basic usage of Docker.
Programming language Haskell itself.
TL;DRWith Stack's Docker integration,
(^-^) You can always build production-ready application as easily as you use stack command as usual.
BackgroundHow does GHC make Haskell code run?
Emit native executables!
Usually single, self-contained!
Just put the executables to deploy!
Stack itself is actually single binary!
But...You must build for your production server!
Linux!
Dependent system (C) libraries and their version.
... and so on!
Corss-compilation with GHC is hard...
With Stack's Docker integration,Build directly for your production environment.
Just by stack build as usual.
Stack's Docker integration does:Wrap docker command.
Make almost all operation of stack on the container.
Setup GHC.
Install dependencies.
Then build your app!
Run tests.
How to use
1. Append docker option to stack.yaml
docker: enable: true
2. Run stack build/install/setup as usual.
How it works※Changes by the configurations.
1. Create a temporary container just for executing stack'ssubcommands.
2. Share the project directory and ~/.stack by mounting.
Where dependencies and build artifacts are saved.
3. stack command runs in the container.
4. Delete the temporary container
Build dependencies and artifacts are still persisted.
How it works (cont)5. Now you can upload the executable to your production,
staging, or any target server!
☆ Tips on using Stack's Dockerintegration ☆
ᕦ(ò_óˇ)ᕤ Build on your own Docker image
三┏( ^o^)┛ Go over the proxy!
(x_x) DON'T overwrite ENTRYPOINT!
ᕦ(ò_óˇ)ᕤ Build on your ownDocker image
Default: Stack's original image (based on Ubuntu)
How to use CentOS/Debian/Arch?
How to install C libraries or any other non-Haskelldependencies?
ᕦ(ò_óˇ)ᕤ Build on your ownDocker image
Edit stack.yaml
docker: repo: "https://your-docker-repo/image:latest"
ᕦ(ò_óˇ)ᕤ Build on your ownDocker image
Requirement for Orignal Images:
GHC must be installable (or already installed):
libgmp
Tools to build C sources.
gcc, make etc.
ᕦ(ò_óˇ)ᕤ Build on your ownDocker image
Requirement for Orignal Images:
Or, install stack itself in the image in advance.
三┏( ^o^)┛ Go over the proxy!May also need build-time-arguments...
$ docker build --build-arg=http_proxy=...
(x_x) DON'T override ENTRYPOINT!
ENTRYPOINT your-cool-entrypoint-command
Stack uses ENTRYPOINT internally!
Case studyTiny mock server to test with an external Web API.
Must run on the staging server.
CentOS 6
Case studyNever mind zlib/libgmp/etc's diff in version, installation path.
Production-ready executables are always built on mydevelopment machine!
Just by the familliar stack build/exec/...
Then scp the executable to our server!
stack install scp ~/.local/bin/executable [email protected]:/
Case study(o˘◡˘o) My impression
(*´∀`*)ノ Comfortable:
I did't have to install anything except the built app.
(´∪`*) The tiny application didn't need even CI!
All was done on my development machine.
(x_x;) Initial build takes a long time...
(;^ω^) Haskell was not good for tiny apps!
(x_x;) The Bad Newsboot2docker is NOT recommended.
VirtualBox's shared folder is too slow!
Unavailable on Docker for Windows...
See this issue
Current limitationUse on Linux or Mac OS X!
(;^ω^) Sorry Windows users!
Use the other VMs to run Linux!