Gizra / circuit-yesod

3 stars 1 forks source link

Deploy app [5h] #31

Open amitaibu opened 7 years ago

amitaibu commented 7 years ago

There's Keter, but maybe a better approach would be to use Docker (see example) and have a load balancer infront of it, so we can switch on and off instances.

@AronNovak this is definitely a task under your domain 😉

AronNovak commented 7 years ago

@amitaibu Exciting :), what would the the priority of this task?

AronNovak commented 7 years ago

Up and running everything on localhost: port

AronNovak commented 7 years ago

For the sake of my curiosity, just made a bid POSTing quick benchmark: saved

AronNovak commented 7 years ago

About the deployment part, I'd envision something like this: Docker-compose on host virtual machine, that uses the following images:

Start to play with these on localhost.

AronNovak commented 7 years ago

Now I realize that we don't need any Haskell / Yesod thing on the production, we need the:

And that's all. Trying it out on a temporary VPS, for now without Docker.

AronNovak commented 7 years ago

On the VPS, the app can be started, it only fails due to the lack of MySQL. Ubuntu 16.04.2, the only extra package is libpq5

root@localhost:~# ./circuit-yesod 
circuit-yesod: libpq: failed (could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
)
amitaibu commented 7 years ago

it only fails due to the lack of MySQL

we in fact use postgres

amitaibu commented 7 years ago

just made a bid POSTing quick benchmark:

24ms for POST and 12ms for GET is nice, isn't it? 😜

AronNovak commented 7 years ago

The benchmark is nice, however we're in almost the same order of magnitude with PHP7. However for sure we can expect much better scalability here, possibly multithreaded app out of the box (?).

Yes, it's postgres, i just use MySQL too many places :)

AronNovak commented 7 years ago

Dockerized Postgres is used by the yet not Dockerized app on the VPS: db-docker

AronNovak commented 7 years ago

Temporarily http://172.104.150.92:3000 hosts the app: den

AronNovak commented 7 years ago

Both the DB and the app is in Docker (at the DB, without persistency considerations for now) docker Somehow the app tries to connect to localhost, @amitaibu , dist/config/settings.yml should hold the config normally, right?

amitaibu commented 7 years ago

I would guess so, but haven't executed a built app. I've always used stack exec -- yesod devel

amitaibu commented 7 years ago

Do you have approot set?

amitaibu commented 7 years ago

(you can set via variable export APPROOT=https://example.com)

AronNovak commented 7 years ago

The solution was that I need to edit the configfile before stack build, it's somehow compiled in. dockerized

Now DB + Yesod app is nicely working in the container. Still have 2 hours left from the issue, playing with the loadbalancer in front of the app.

amitaibu commented 7 years ago

it's somehow compiled in.

That's part of the hot sauce of Yesod -- you get compiler validations on your settings (even on your css files!)

AronNovak commented 7 years ago

We have a smooth mix of Nginx loadbalancer, Yesod servers (3 of them) and Postgresql. smooth

The app is available via http://172.104.150.92/ (i will leave it like this for a day or so). We have 0.5 hours remaining.

Actually there could be several improvements and fixes to think of:

amitaibu commented 7 years ago

nice!

In order to allow login in debug mode could you set debug to true?

Actually there could be several improvements and fixes to think of:

As follow ups? If so, can you open the issue(s) and timebox them as you see fit.

AronNovak commented 7 years ago

Re-deployed with debug mode, login is now possible. Yes, we can think about it as follow-ups, however the work is not fully self-contained here. In the remaining 0.5 hours, i try to make the last point, to make sure all the steps are automated. And going to create the follow-up issues for sure.

amitaibu commented 7 years ago

If you'd like to bump this issue in 2-3h (?) and address them here that also possible.

AronNovak commented 7 years ago

Thanks! Sounds better for me, webapp DB without persistency is not something ready, that's for sure :)

amitaibu commented 7 years ago

btw @AronNovak is this an ec server? Can we Blazemeter it to see how scalable it is?

AronNovak commented 7 years ago

@amitaibu No, it's a Linode VPS on my personal account, I don't like EC2 too much either, and we did not arrange Google Cloud access, so i solved it that way, as anyways it should be disposable.

AronNovak commented 7 years ago

And certainly we can do scalability tests, why not with Blazemeter.

amitaibu commented 7 years ago

I've added you to a Google cloud project

AronNovak commented 7 years ago

Thanks!

@amitaibu trial

Could you advise me how to access that?

AronNovak commented 7 years ago

Just tested, related to sessions, it's absolutely not an issue to have the loadbalancer, not sure how the session handling of the app works exactly, but had a session where /profile was served by different backends and the login remained persistent.

AronNovak commented 7 years ago

Just rolled out a new version (just changed the copyright) of the app with zero downtime:

root@localhost:~/deploy/deploy# docker build -t circuit .
Sending build context to Docker daemon 249.3 MB
Step 1/5 : FROM ubuntu:16.04
 ---> 6a2f32de169d
Step 2/5 : RUN apt-get -y update && apt-get install -y libpq5
 ---> Using cache
 ---> 28d61589b2ed
Step 3/5 : WORKDIR /var/www
 ---> Using cache
 ---> 9123112b7064
Step 4/5 : ADD . /var/www
docker images ---> 48f77f4cdb20
Removing intermediate container 7a8b142d2ac4
Step 5/5 : CMD sleep 10 && cd /var/www/dist/ && /var/www/dist/circuit-yesod
 ---> Running in e4513b611f4c
 ---> 5862d3412186
Removing intermediate container e4513b611f4c
Successfully built 5862d3412186
root@localhost:~/deploy/deploy# docker-compose stop circuit_2
Stopping deploy_circuit_2_1 ... done
root@localhost:~/deploy/deploy# docker-compose stop circuit_1
Stopping deploy_circuit_1_1 ... done
root@localhost:~/deploy/deploy# docker-compose up -d --no-deps circuit_1
Recreating deploy_circuit_1_1
root@localhost:~/deploy/deploy# docker-compose up -d --no-deps circuit_2
Recreating deploy_circuit_2_1
root@localhost:~/deploy/deploy# docker-compose stop circuit_0
Stopping deploy_circuit_0_1 ... done
root@localhost:~/deploy/deploy# docker-compose up -d --no-deps circuit_0
Recreating deploy_circuit_0_1
root@localhost:~/deploy/deploy# ls
dist  docker-compose.yml  Dockerfile  nohup.out  package.sh
root@localhost:~/deploy/deploy#

Adding README.md for the initial and the further deployments.

AronNovak commented 7 years ago

Now what was done in the PR is self-contained, all the points from https://github.com/Gizra/circuit-yesod/issues/31#issuecomment-293881137 are addressed, at least in a basic way.