• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

jkachmar/alpine-haskell-stack: Demonstrating how GHC, Alpine, Stack, and Docker ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

jkachmar/alpine-haskell-stack

开源软件地址(OpenSource Url):

https://github.com/jkachmar/alpine-haskell-stack

开源编程语言(OpenSource Language):

Makefile 57.6%

开源软件介绍(OpenSource Introduction):

GHC, Alpine, Stack, and Docker

Table of Contents

This repository is a small demonstration of the steps required to build an Alpine Linux Docker image with all the tools necessary to compile Haskell programs linked against musl libc.

Such an environment are extremely useful for producing small Docker images for the deployment of services and for creating portable Haskell executables (either statically linked, or bundled with the musl linker and their dynamic dependencies).

At the time of writing, this repository is primarily geared towards showing off a workflow by which one can use stack's Docker integration to seamlessly develop inside an Alpine Linux container. This gives the benefit of stack's build caching and also integrates nicely with development tools like ghcid.

In the future I hope to either update this repository with explicit instructions and/or examples that show how one can create minimal (i.e. tens of MB) Docker images to deploy Haskell applications in production.

Prerequisites

Ensure Docker is installed on your computer and the Docker daemon is running.

Install the Haskell Tool Stack.

Building the Docker Images

At the time of writing (1 Apr. 2019) GHC-HQ doesn't provide a version of GHC that is compatible with musl libc, and the ghc package provided by Alpine is out of date.

This means that the first step in this process is going to be compiling GHC itself and packaging up all the necessary tools and dependencies in an Alpine Linux container.

For convenience, I've combined all of these steps into a single, multi-stage Dockerfile in this repository, and written a Makefile that caches the intermediate build layers so changes to the final environment don't trigger a full rebuild of GHC and the associated tooling.

"Quick" Start

To build the Docker images, navigate to the project root directory and run:

make docker-build-gmp

Keep in mind that this stage compiles GHC, which can take anywhere from 30 mins to upwards of an hour depending on how fast your computer is.

Overview

I've tried to keep the Dockerfile relatively well commented, but the build process can be roughly understood as an impl

  • base

    • Base layer used for all the intermediate build images to follow
    • Contains all OS dependencies required to run ghcup and stack
  • build-ghc

    • Builds GHC via ghcup
    • Contains all dependencies required to build GHC
    • Contains some (currently unused) logic for selecting between integer-gmp and integer-simple
      • integer-gmp depends on libgmp, which is licensed under the LGPL, so if one wants to distribute a statically linked, closed source binary they will need to build against a version of GHC that uses integer-simple
  • build-tooling

    • Downloads stack and verifies the hash
  • alpine-haskell

    • Assembles artifacts from the previous layers
    • Copies GHC and stack
    • Installs bash and shadow
      • stack requires usermod/groupmod from shadow as well as bash to run

Developing Locally with stack

Once the images have finished building, this project can be compiled to demonstrate what local development looks like with stack.

For convenience, I've added some targets to the Makefile that run some common development tasks.

First, ensure that ghcid is installed (for example, by running stack build --copy-compiler-tool ghcid).

Then, compile this project in Docker by running make build-fast.

Finally, start a ghcid development loop with make ghcid; this loop uses stack --docker to spawn a container in which GHC recompiles everything whenever it detects changes in your code.

Try changing something in executables/Main.hs and see the changes reflected in ghcid!

TODO

  • Demonstrate integer-simple support
  • Demonstrate static linking
  • Create separate Dockerfiles for GHC and combined tooling
    • Automate the creation of these images in CI and host them on Dockerhub

Related work




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
maoe/influxdb-haskell: InfluxDB client library for Haskell发布时间:2022-06-24
下一篇:
JakeWheat/simple-sql-parser: SQL parser in Haskell发布时间:2022-06-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap