I finally used Docker and Amazon Elastic Beanstalk (to deploy Disqus comment search service)

For those of you who don’t want to read this, I have my Disqus comment search deployed now, at disqussearch.com.

From now on, I’ll give an outline of my experience deploying my Disqus comment search web app.

Heroku

I had deployed the Disqus comment search web service I developed on Heroku, with the endpoint being https://pacific-waters-11622.herokuapp.com. What I didn’t expect was to end up blocked on account verification (now I’m pretty sure it’s almost certainly not my problem, since a similar procedure has worked on others), especially given that Heroku is pretty large and established, now a Salesforce company.

So that led me to try AWS. I made an account (it’s kind of a shame that I never cared enough about software engineering to have already made one long ago) and with some looking up info online plus trial and error I got it deployed on Amazon Elastic Beanstalk. As for details, I developed this in Scala using Scalatra and when testing locally, it was powered by Jetty web server, which I ran in sbt. For Heroku all I had to do, after incorporating a

JettyLauncher.scala

(you can easily find the source online) was a

git push heroku master

and that did the trick. It detected sbt, did the build, made the .jar and .war files and deployed it to that endpoint.

Amazon Elastic Beanstalk + Docker

On Amazon Elastic Beanstalk, I first tried (too wishfully) deploying it directly as Apache Tomcat, and expectedly I got 404. So it occurred to me to try Docker, which is probably the more systematic way of going about it nowadays. I first did a Tomcat within Docker.

For that, the code was

# Pull base image
From tomcat:8-jre8

# Maintainer
MAINTAINER "gmachine1729 <gmachine1729@foxmail.com">

# Copy to images tomcat path
ADD [url where I stored my locally built .war file] /usr/local/tomcat/webapps/

# Some copies of resources used by this webapp
[omitted Docker config code]

# for a Python subprocess within my Scala
RUN apt-get -y update
RUN apt-get -y install python

EXPOSE 8080

CMD ["catalina.sh", "run"]

I remember it also asked for

Dockerfile.aws.json

at one point. And I found online and copied and modified to something like

{
  "AWSEBDockerrunVersion": "1",
  "Image": {
    "Name": "disqus-comment-search-tomcat2:latest"
  },
  "Ports": [
    {
      "ContainerPort": "8888"
    }
  ]
}

In the above,

disqus-comment-search-tomcat2:latest

is name of my locally built Docker image.

And it worked, excepting a css glitch that resolved itself after a few refreshes.

Later on I decided that probably I should use Jetty, the environment that I’m testing in. The Dockerfile is

FROM jetty:9.3-jre8

USER root

# copies of resources
[code omitted]

# https://hub.docker.com/_/jetty told me to use ROOT.war to deploy to / context
ADD [url where I uploaded my locally built war file] /var/lib/jetty/webapps/ROOT.war

RUN apt-get -y update
RUN apt-get -y install python

EXPOSE 8080

In command line, using

eb

, part of the whole suite of AWS CLI tools,

eb create

did the trick. This was after I did

eb init

in which I made sure to pick Docker in one of the selections asking for the type of deployment.

I also realized that, because this worked, the stuff in

Dockerfile.aws.json

still there is superfluous. All I remember was it had at one point given me an error in the likes of “No Dockerfile.aws.json.” So you might need the file, but contents inside it might not matter for something as simple as this.

Domain name with GoDaddy and then Amazon Route53

I had purchased a domain name through GoDaddy (the domain name provider probably best known that I chose without really considering other choices) before trying Amazon and Docker. Originally, my plan was to connect to Heroku, but after Heroku kept blocking me, I full-heartedly decided to switch to AWS. And after the deployment on AWS was resolved, searching for info to add CNAME or whatever to connect GoDaddy domain to the AWS endpoint only gave me a rather incoherent clutter of info. But through it I learned of Route 53, Amazon’s domain name provider, which is much easier to integrate with AWS EB.

So I bought another domain name disqussearch.com through Route 53 ($12 per year with privacy protection cheaper than GoDaddy). The procedure to route it to my AWS EB endpoint was very simple. I made an Alias record in the Hosted Zone corresponding to the domain I bought through Route 53 that was automatically added for me following instructions in https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-beanstalk-environment.html#routing-to-beanstalk-environment-get-domain-name.

2019-05-04 下午2.45.16

Within 60 seconds, disqussearch.com brought me to my Disqus comment search web service.

2019-05-04 下午2.52.12

I hope this information can be helpful to people who do similar stuff in the future. Feedback welcome!

Advertisements