我想用Haskell和Yesod开发一个个人网站。我之前的网络工作主要是Python。我使用Docker,因此一旦完成所有内容,我就可以在Amazon Web Services上轻松部署。我在容器中进行所有开发 - 因此除了像vim和git这样的实用程序之外,没有软件可以直接安装在我的机器上 - 然后只需部署容器。我想为这个网站做同样的事情。
我的Dockerfile目前看起来像这样:
FROM haskell:latest
MAINTAINER Garry Cairns
ENV REFRESHED_AT 2015-03-19
# create a haskell user to run our programs
# ADD must be after chown see http://stackoverflow.com/a/26145444/1281947
RUN ["groupadd", "haskell"]
RUN ["useradd", "haskell", "-s", "/bin/bash", "-m", "-g", "haskell", "-G", "haskell"]
ENV HOME /home/haskell
RUN ["mkdir", "/home/haskell", "-p"]
WORKDIR /home/haskell
RUN ["chown", "-R", "haskell:haskell", "/home/haskell"]
ADD ./ /home/haskell
# install yesod
RUN ["apt-get", "install", "-y", "wget"]
RUN ["wget", "http://www.stackage.org/lts/cabal.config"]
RUN ["cabal", "update"]
RUN ["cabal", "install", "yesod"]
# uncomment the line below to use container as a non-root user
# USER haskell:haskell
安装yesod评论下的说明来自yesod quick start guide。容器构建但是,在cabal update
步骤中,我看到一个警告说:
Config file path source is default config file.
Config file /home/haskell/.cabal/config not found.
Writing default configuration to /home/haskell/.cabal/config
Downloading the latest package list from hackage.haskell.org
Note: there is a new version of cabal-install available.
To upgrade, run: cabal install cabal-install
这可能与以下错误有关,也可能没有。
我使用sudo docker run -itv /home/garry/projects/personal/api/:/home/haskell garrycairns/haskell /bin/bash
在此容器上运行shell会话并尝试yesod init
,这告诉我它无法找到yesod
命令。运行ghci也不允许我import Yesod
。
无论我是cabal安装yesod还是yesod-bin,结果都是一样的。
我也尝试以相同的结果作为haskell用户(请参阅我的Dockerfile)运行。
运行yesod init
应该按照快速入门指南中的说明操作我的应用程序。
yesod命令在我的容器中不可用。
如何设置一个Docker容器,让我运行yesod init
以及稍后yesod devel
?
答案 0 :(得分:1)
您需要将位置~/.cabal/bin/
添加到您访问由cabal安装的程序的路径,例如yesod。
其次,最好将cabal作为haskell用户运行,因为它希望由非root用户运行(这可能会阻止你加载ghci中的文件)。
最后,最好在主文件夹的子文件夹中进行开发,因为cabal沙箱会添加隐藏文件。
您可能还想为您的数据库等安装系统库。
以下文件似乎有效:
FROM haskell:latest
MAINTAINER Garry Cairns
ENV REFRESHED_AT 2015-03-19
# create a haskell user to run our programs
# ADD must be after chown see http://stackoverflow.com/a/26145444/1281947
RUN ["groupadd", "haskell"]
RUN ["useradd", "haskell", "-s", "/bin/bash", "-m", "-g", "haskell", "-G", "haskell"]
ENV HOME /home/haskell
RUN ["mkdir", "/home/haskell", "-p"]
WORKDIR /home/haskell
RUN ["chown", "-R", "haskell:haskell", "/home/haskell"]
ADD ./ /home/haskell
# install wget
RUN ["apt-get", "install", "-y", "wget"]
# set up haskell
USER haskell:haskell
# add cabal installed programs to path
ENV PATH /home/haskell/.cabal/bin:$PATH
# enter working directory
RUN ["mkdir", "yesod"]
WORKDIR /home/haskell/yesod
# install yesod binary
RUN ["wget", "http://www.stackage.org/lts/cabal.config"]
RUN ["cabal", "update"]
RUN ["cabal", "install", "alex", "happy", "yesod-bin"]
答案 1 :(得分:1)
我最终做了以下事情。
下载global stackage config file并将其作为stackage
保存在我的项目根目录中。
构建以下Dockerfile,它使用我们刚刚创建的stackage
文件,直到我说出来评论其他所有文件。
FROM haskell:7.8
# install database dependencies
RUN ["apt-get", "update"]
RUN ["apt-get", "-y", "install", "libpq-dev"]
# update cabal and install yesod
RUN cabal update
ADD ./stackage /root/.cabal/stackage
RUN cat /root/.cabal/config /root/.cabal/stackage > /root/.cabal/config2
RUN ["mv", "/root/.cabal/config2", "/root/.cabal/config"]
RUN cabal update
RUN ["cabal", "install", "yesod-bin", "-j4"]
# Add your .cabal file before the rest of the code so next step caches
# Comment out here on the first run
ADD ./myproject.cabal /opt/server/myproject.cabal
# Docker will cache this command as a layer, freeing us up to
# modify source code without re-installing dependencies
RUN cd /opt/server && cabal install --only-dependencies -j4
# Add and Install Application Code
ADD ./ /opt/server
RUN cd /opt/server && cabal install
# Add installed cabal executables to PATH
ENV PATH /root/.cabal/bin:$PATH
# Default directory for container
WORKDIR /opt/server
使用项目root作为卷运行新容器,然后在容器内运行yesod init --bare
。这也将在主机上的项目根目录中创建其文件。
取消注释上面注释掉的Dockerfile中的行并再次构建它。你现在有一个工作的Dockerfile。