4

I want to deploy a system made in Yesod using Amazon Web Service. But can't find a good tutorial or steps on how to do it.

Looking for a web host that can handle Haskell says that Amazon EC2 is the best. But it doesn't tell how to do it or give a link. Also it has a comment that I can link my S3 to EC2.

Community
  • 1
  • 1
Ryan Monreal
  • 587
  • 5
  • 16

3 Answers3

5

I'd suggest you to look at https://github.com/snoyberg/keter/ and Halcyon at https://halcyon.sh/

They are deployment managers for Haskell web apps. Keter was written in Haskell and Halcyon shell.

In my opinion keter handles amazon better and halcyon is more for dependencies, initial setup, heroku and digital ocean. Both are awesome.

(UPDATE 25-02-2015)

Keter is mentioned at Developing Web Apps with Haskel and Yesod, 2nd Edition, launched this February 2015, (http://www.yesodweb.com/book/deploying-your-webapp). I highly recommend it, both the tools and the book.

Also, I'd recommend heroku if it's just a pet project or something to test on.

Links:

http://shop.oreilly.com/product/0636920035664.do

http://www.amazon.com/Developing-Apps-Haskell-Yesod-Safety-Driven/dp/1491915595/ref=dp_ob_title_bk

https://github.com/snoyberg/keter/

https://halcyon.sh/

notvitor
  • 86
  • 5
  • To complement my answer above I'd also like suggest that you take a look at halcyon (https://halcyon.sh/) and DO NOT compile your code inside your EC2 for obvious reasons. – notvitor Feb 25 '15 at 15:58
  • i already have the compiled version of my project tnx to @fpcomplete IDE. but once i install the keter it gives me and error.. i'll already create and issue to this on [GITHUB](https://github.com/snoyberg/keter/issues/76) – Ryan Monreal Mar 04 '15 at 09:22
2

I could use Nginx as a front end server, and use Yesod app as the reverse proxy on EC2/Ubuntu 14.04. I didn't try Keter, as Nginx/Yesod just works fine. I assume you already install the Nginx.

Installation of Haskell/Yesod

As the Yesod author comments in http://www.yesodweb.com/page/quickstart, Stackage (https://www.stackage.org) is really easy to install dependent libraries, and even Haskell itself. I followed this site (https://github.com/commercialhaskell/stack/blob/master/doc/install_and_upgrade.md) to easily install Stack on Ubuntu 14.04.

  1. wget -q -O- https://s3.amazonaws.com/download.fpcomplete.com/ubuntu/fpco.key | sudo apt-key add -
  2. echo 'deb http://download.fpcomplete.com/ubuntu/trusty stable main'|sudo tee /etc/apt/sources.list.d/fpco.list
  3. sudo apt-get update && sudo apt-get install stack -y

You can use stack ghci to launch Haskell REPL.

Create and build Yesod project

  • stack new my-project yesod-sqlite && cd my-project
  • stack install yesod-bin cabal-install --install-ghc
  • stack build

Use swap to benefit more memory

For my EC2 server, I havd only 1G memory not to finish the build, but I could use swap to use more memory - https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

  1. sudo fallocate -l 4G /swapfile
  2. sudo chmod 600 /swapfile
  3. sudo mkswap /swapfile
  4. sudo swapon /swapfile

Development test

  • stack exec -- yesod devel

You can launch webbrowser to check with http://localhost:3000.

Deployment

From http://www.yesodweb.com/book/deploying-your-webapp, I need three components to deploy to other machine.

  1. Your executable.
  2. The config folder.
  3. The static folder.

The stack build command gives me the location of the executable:

my-project-0.0.0: install
Installing library in
/home/a/my-project/.stack-work/install/x86_64-linux/lts-3.13/7.10.2/lib/x86_64-linux-ghc-7.10.2/my-project-0.0.0-Khn8lQEgR1HARzYGStlvPe
Installing executable(s) in
/home/a/my-project/.stack-work/install/x86_64-linux/lts-3.13/7.10.2/bin
Registering my-project-0.0.0...

The executable is located in /home/a/my-project/.stack-work/install/x86_64-linux/lts-3.13/7.10.2/bin. I could copy the files (executable, static, and config) in ~/deployment directory to check the Yesod works fine.

This is the directory structure.

├── config
│   ├── client_session_key.aes
...
│   └── test-settings.yml
├── my-project
└── static
    ...

Change port number

Change the port number in config/settings.yml

port:           "_env:PORT:3002"
approot:        "_env:APPROOT:http://localhost:3002"

(I'm not sure why) However, to make the settings.yml work, you need to copy the file in current directory, then run the ./my_project settings.yml.

Check http://localhost:3002.

Setup Nginx server

This is the conf file for Yesod.

# the IP(s) on which your node server is running. I chose port 3000.
upstream yesod {
        server 127.0.0.1:3002;
        keepalive 8;
}

# the nginx server instance
server {
        listen 0.0.0.0:80;
        server_name yesod.example.com;
        access_log /var/log/nginx/access_yesod.log;
        error_log /var/log/nginx/error_yesod.log;

        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;

            proxy_pass http://yesod/;
            proxy_redirect off;
        }

        location /excluded {
            return 403;
        } 
}

Copy this file in /etc/nginx/site-enabled (or make symlink from site-available), then relaunch the nginx sudo server nginx restart.

Now, you can access the Yesod app from http://yesod.example.com.

References

Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871
1

Yesod book has a whole chapter on how to deploy your Yesod app http://www.yesodweb.com/book/deploying-your-webapp

Amazon is recommended there, so it should work on amazon without any trouble. If you'll have more specific questions regarding keter -- please post them as new questions then.

Konstantine Rybnikov
  • 2,457
  • 1
  • 22
  • 29
  • @RyanMonreal yeah, it might be confusing a little, but please feel free to ask questions either on StackOverflow or yesod GoogleGroups, I'll help you with them, since I succeeded with Keter in past – Konstantine Rybnikov Mar 04 '15 at 13:16
  • so does it mean you also run yesod on Amazon ec2? can you tell me the what is the minimum requirements to install keter? in my situation i use the the t2.micro for my instance, and I also created an issue o [GITHUB](https://github.com/snoyberg/keter/issues/76). – Ryan Monreal Mar 04 '15 at 17:08
  • @RyanMonreal any amazon instance should be more than happy to run keter, just don't build it there, but build it locally on linux machine (or VM) and copy keter executable to instance. keter is a lightweight high-performance executable, similar to nginx, but written in Haskell, has it's config format and is able to listen to changes in /opt/keter/incoming, so you don't have to do anything other than scping your proj.keter file to /opt/keter/incoming – Konstantine Rybnikov Mar 04 '15 at 17:21
  • i get through on installing the keter on my instance. also i build already my Project using fpcomplete IDE it give me a complete package of the build project. but onece i follow [Link](http://www.yesodweb.com/book/deploying-your-webapp#deploying-your-webapp_server_process) and `sudo start mysite` it give me error.. how was it? – Ryan Monreal Mar 04 '15 at 18:41
  • @RyanMonreal ah, I see now. I was supposing you used just a regular local build to build your project locally. In that case, you would just run `yesod keter` and have a `.keter` file that you need to `scp` to your amazon instance. – Konstantine Rybnikov Mar 05 '15 at 09:01
  • @RyanMonreal let me see how to deploy fpcomplete-developed yesod app for a moment – Konstantine Rybnikov Mar 05 '15 at 09:02
  • @RyanMonreal after you downloaded your app from fpcomplete center you can either just unpack and run that Main executable on your amazon server. It will run on some port (not 80), you can either remove keter and just configure nginx to forward 80 port to that port, or you can try to configure keter for this. To configure keter -- unpack locally that .tar.gz, put a `config/keter.yml` file with following contents https://gist.github.com/k-bx/056b07a85eec3e01ae8d (edit your hostname and ip), then pack it back to .tar.gz, rename that .tar.gz to .keter instead. – Konstantine Rybnikov Mar 05 '15 at 09:10
  • @RyanMonreal scp this .keter-file to your host's /opt/keter/incoming. – Konstantine Rybnikov Mar 05 '15 at 09:10
  • @RyanMonreal but as I understand, recommended way to deploy fpcomplete is to use their deployment mechanism. They will use amazon instance, created for your app. Try that via fpcomplete IDE menu, contact their support if something doesn't work. – Konstantine Rybnikov Mar 05 '15 at 09:12
  • i tried your instruction, now How can i access it in the browser? – Ryan Monreal Mar 06 '15 at 18:29
  • @RyanMonreal amazon control panel shows your server's public address. Go to http://
    : (port should be written by app on launch)
    – Konstantine Rybnikov Mar 07 '15 at 19:42