Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying to Amazon Elastic Beanstalk #244

Closed
andybeak opened this issue Aug 19, 2016 · 24 comments
Closed

Deploying to Amazon Elastic Beanstalk #244

andybeak opened this issue Aug 19, 2016 · 24 comments

Comments

@andybeak
Copy link

Has anybody had any experience with this? Could you recommend some reading sources or point me in the direction of example config setups?

@Spracto
Copy link

Spracto commented Sep 6, 2016

I'm currently struggling through trying to do this. I'd appreciate some help with it as I'm totally lost trying to write a Dockerrun.aws.json file for the 5 containers that laradock created to dockerize the laravel project.

@ivanhueso
Copy link

ivanhueso commented Jan 28, 2017

I'm trying to deploy to Elastic Beanstalk I'm having issues when it too. Need help.

@davehensley
Copy link

davehensley commented Feb 2, 2017

  1. Create whatever images you need, e.g. docker-compose build nginx php-fpm
  2. Tag your image, e.g. docker tag laradock_nginx:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/laradock/nginx:latest (replace with the URI of your ECR repository)
  3. Repeat the previous step for the rest of your images.
  4. Get your authorization token from AWS: aws ecr get-login
  5. Run the docker command that the aws tool outputs in the previous step: docker login -u AWS -p ...
  6. Deploy your new image to ECR: docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/laradock/nginx:latest (replace with the URI of your repository)
  7. Repeat the previous step for the rest of your images.
  8. Create a file called Dockerrun.aws.json one directory up from your Laravel app (so if Laravel is in ~/Projects/YourProject/application/ then put Dockerrun.aws.json in ~/Projects/YourProject/). Use the sample file below as a starting point.
  9. Deploy your app: eb deploy

Sample Dockerrun.aws.json file:

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
    {
      "essential": true,
      "image": "123456789.dkr.ecr.us-east-1.amazonaws.com/laradock/php-fpm:latest",
      "memory": 256,
      "mountPoints": [
        {
          "containerPath": "/var/www",
          "sourceVolume": "application"
        },
        {
          "containerPath": "/usr/local/var/log",
          "sourceVolume": "awseb-logs-php-fpm"
        }
      ],
      "name": "php-fpm"
    },
    {
      "essential": true,
      "image": "123456789.dkr.ecr.us-east-1.amazonaws.com/laradock/nginx:latest",
      "links": [
        "php-fpm"
      ],
      "memory": 512,
      "mountPoints": [
        {
          "containerPath": "/var/www",
          "sourceVolume": "application"
        },
        {
          "containerPath": "/var/log/nginx",
          "sourceVolume": "awseb-logs-nginx"
        }
      ],
      "name": "nginx",
      "portMappings": [
        {
          "containerPort": 80,
          "hostPort": 80
        }
      ]
    }
  ],
  "volumes": [
    {
      "host": {
        "sourcePath": "/var/app/current/application"
      },
      "name": "application"
    }
  ]
}

@Mahmoudz
Copy link
Member

@davehensley can you include your answer in the docs!?

@davehensley
Copy link

@davehensley can you include your answer in the docs!?

@Mahmoudz I'm not sure which docs you're referring to (laradock.io maybe?), but I'm not part of the Laradock project so I don't have write access to them. But if you do, you're more than welcome to copy my solution and include it there if you think it would be useful.

@Mahmoudz
Copy link
Member

@davehensley actually the site is hosted on Github and the readme files are in the project, so you can send a normal PR as you used to when updating the readme.md. Please refer to this docs for how to update the docs http://laradock.io/contributing/#update-documentation-site. Note: do not edit HTML files, someone did that mistake before, just edit the markdown files and re-generate the HTML from them, the link should help. Thanks for your quick response. Best,

@canfone
Copy link

canfone commented Jul 10, 2017

@davehensley Thanks for your answer. In that case, do I need to create each repository for each images in my ECR? For example, one for nginx, one for php-fpm, etc? Or I can create just one repository and tag all of them in that one repo?

Sorry for my ignorance. Hope you can help me.

@davehensley
Copy link

@canfone You should create a separate repo for each image.

@canfone
Copy link

canfone commented Jul 10, 2017

@davehensley
Thanks for your quick response.
I followed your instructions but I encounter this error when deploying to eb

Dockerfile and Dockerrun.aws.json are both missing, abort deployment

I believe that there are processes I need to do before the steps you suggested. I don't know where or what to start. Do you have any suggestions or ideas what things I need to be done before following the steps you gave?

Thanks.

@davehensley
Copy link

@canfone Hmm, what was the process that you used to create your EB app? Try something like this (it should download Laravel and deploy the default app):

~ $ mkdir -p ~Projects/my-project && cd !$
my-project $ eb init
my-project $ git clone git@github.com:laravel/laravel.git application
my-project $ cp /path/to/Dockerrun.aws.json .
my-project $ eb create

@canfone
Copy link

canfone commented Jul 10, 2017

@davehensley Thanks for your reply.

I'm using awsebcli to create my EB app. I think I managed to create the app and deployed it to elastic beanstalk. However, my nginx configurations were not included in the nginx image of my ECR. Also, the application files is not in /var/www inside workspace container. It is in /var/app/current instead. Maybe there are bindings I missed that's why those files were not properly located in my containers.

By the way, my laradock folder is outside the laravel application.

@canfone
Copy link

canfone commented Jul 11, 2017

@davehensley Nevermind my previous comment. I managed to mount nginx conf files. I just need to use volumes. Thanks for your help.

@chkm8
Copy link
Contributor

chkm8 commented Aug 8, 2017

Hi, Im follwing the guide that is provided above, i managed to create the laradock instance in elastic server via ecr. but the application is not working, im having 502 bad gateway error, and when I checked the apache2 container logs inside eb server, is says that SSLCertificateFile: file '/etc/ssl/certs/ssl-cert-snakeoil.pem' does not exist or is empty, how would i solve this one, in my local instance there is no ssl-cert issues, so the logic would be my local should be the same once i upload it on eb server. hope you could help me . thanks

@davehensley
Copy link

@chkm8 This is a bit outside the scope of the original question, but the answer is that it's easiest to set up a secure site on Elastic Beanstalk if the EC2 instances inside your EB environment don't know anything about SSL. Even if you're running a secure site, your webserver inside your docker container should be listening on port 80 only, so you don't even need to install mod_ssl. The job of storing SSL certificates and keys and encrypting the connection is performed by Amazon's Elastic Load Balancer.

So the traffic goes like this:

Your container <---port 80 (http)---> Elastic Load Balancer <---port 443 (https)---> Internet

AFAIK there isn't a way to upload an SSL certificate/key through the AWS console, but you can do it pretty easily with the aws command line tool:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-ssl-upload.html

Everything else is configurable through the AWS console (just allow incoming https connections in your Elastic Load Balancer's security group, and then enable HTTPS on port 443 in your load balancer settings and choose the certificate that you just uploaded from the dropdown menu).

If you really do need full end-to-end encryption (which you almost certainly don't), or you're running a single-instance EB environment without a load balancer, then it is possible to configure your container to listen for https connections (but I strongly recommend trying the other way first):
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-endtoend.html

@chkm8
Copy link
Contributor

chkm8 commented Aug 9, 2017

@davehensley , yup, the error is not related, i finally uploaded our project in EB following the guide you provided, the error I was referring to is how the "laradock apache2 container" was buid making a copy of the default ssl and with missing plugins (snakeoil). I rebuild a new one but remove the default ssl.

@comlaterra
Copy link

Now that there is an aws service, I've followed what the documentaiton says: http://laradock.io/documentation/#use-aws also what AWS documentaiton explains, looks is up and running but:
I get Forbidden on the root url of the project
and a double laravel error without any log in any other path.

Any help is welcome, a link, some pointer og where to research to...?

@chkm8
Copy link
Contributor

chkm8 commented Sep 21, 2017

The aws service was meant to provide easy tools to access aws using eb ssh. Are you having Forbidden error when you access your environment url? I also had trouble in setting it up first but I forgot the specific errors but what I learned was that make sure that you setup the security group of each containers, they should have access with port 80 and 443. Also you need to enable that the listener to your eb instance both 80 and 443.

@comlaterra
Copy link

comlaterra commented Sep 21, 2017

Thanks @chkm8 !
Well, I've changed the aws config to access to teh public folder, and I can see the laraval errors... without log (?!) and with two headers (?)
screen shot 2017-09-21 at 11 46 19

I'm also trying to access to the logs, but I can't. The app works perfectly in my local Docker btw :)
Any idea/points where I can search self-educate to fix this issue?

Thanks!

@chkm8
Copy link
Contributor

chkm8 commented Sep 21, 2017

How did you deploy your project to elastic beanstalk? Can you do eb logs | grep apache2 inside the aws laradock container? or inside eb instance sudo docker logs ?

@comlaterra
Copy link

I've deployed completely with eb cli. Followed the instructions:
docker-compose up -d aws then docker-compose exec aws bash and the rest from eb cli.
So eb init and eb deploy --staged.
Do I need to have a Dockerrun.aws.json file? I though the point is that the cli makes up actions from the docker-compose.
eb logs | grep apache2 doesn't returns anything, the logs in general looks good.

Thanks! I keep researching!

@chkm8
Copy link
Contributor

chkm8 commented Sep 22, 2017

If you wanted to deply your application using laradock, yes you need the Dockerrun.aws.json, there is a sample for that in the comment above on this thread. So if you dont use Dockerrun.aws.json, I assumed that when you did eb init you choose php as environment right? I havent tried deploying it in that way because I use the multiple docker options and I provided the Dockerrun.aws.json.

@codeasashu
Copy link
Contributor

I am using nginx, php-fpm, mariadb for one of the project. I followed the steps suggested by @davehensley and can see a successful deployment. (I am using multi docker instance in aws ebs)

However, I was unable to see any nginx config when I exec'd into it. I see nginx.conf but no conf.d/default.conf. I think I have to write a Dockerfile, using ADD command to manually copy the config to /etc/nginx/conf.d. I will soon share the Dockerfile

@stale
Copy link

stale bot commented Feb 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Feb 2, 2020
@stale
Copy link

stale bot commented Feb 23, 2020

Hi again 👋 we would like to inform you that this issue has been automatically closed 🔒 because it had not recent activity during the stale period. We really really appreciate your contributions, and looking forward for more in the future 🎈.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants