How does Django deployments happen on Servers? - django

I learnt how to deploy the django projects to EC2 instances.
Basically 1st time when the django project is deployed to EC2, the instance will be configured with httpd.conf, wsgi, change permissions on files and folders and other stuff and the project will be cloned to the EC2 instance and server is restarted.
My question is how do they do future deployments? They in this context is anyone who deploys Django on EC2 instances.
Do they login to EC2 instances and manually clone the repository from VCS site and restart the server?
Do they have any other automated mechanism to pull the code, ensure permissions and restarting the apache server etc.
How is it done basically every time they go for a release?

Related

Running an ec2 instance from other server provider existing image

I have installed ressources on a scalway server scaleway.com (a frensh servers and cloud provider). This server uses ubuntu as os and runs a python app with many installations and configs.
In scalway, you can run a new server from a server image you had before installed or already existing. In ec2 too, you can surely launch an aws ec2 instances from an existing AMI https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html.
But, is there a way please to launch an ec2 instance with a scalway image. It will save much time in deployment of the app.
Thanks.
It seems that there is no way:
https://www.reddit.com/r/Scaleway/comments/jwha9q/is_there_a_way_to_download_an_image/

How can automatic deploy yii2 app when Elastic Beanstalk instance is terminated and created a new instance

Currently I have setup my yii2 website on AWS Elastic beanstalk. I followed following steps :
Created Elastic Beanstalk app and environment : Platform PHP 7.0, RDS database
Created SSH connection from EC2 instance of elastic beanstalk using putty with .pem file
In Apache folder I have cloned my yii2 git repo using (sudo git clone repo_url) command
Installed composer using this link https://gist.github.com/asugai/6694502
Run command : (sudo composer install) in my repo folder
Edited common/config/main-local.php and made db connection
And run migration using (sudo php yii migrate)
Setup a domain for this elastic beanstalk app
Now I don't know how should I proceed further and I am facing following problems :
Elastic Balance loader is creating new instance and terminating current one when it fails or health goes in severe.
Due this, my all data in that instance is lost. To make it work I am doing all steps again and again manually.
How can I make my domain https (SSL certified)
How can make easy process to pull new changes from git
I already have a working site in nodeJS. which is using elastic beanstalk, elastic balance loader, RDS(postgres), S3 bucket, cloudfront for Route 53, SSL certificate (https), code pipeline, code commit. And AWSCLI at local to deploy nodeJS app.
my question is about I want to use same flow for yii2 advance app.
Can anyone please help me here?
Thanks in advance :)

Python app uses old filed on EC2 instance

I have an interesting problem:
There is an EC2 instance, on which py3env is stored
I deploy my web app from pyCharm to EC2 and run the server (runserver 0.0.0.0)
Since last week the web app uses OLD files, which I have already deleted from EC2. I check app files on EC2 - they are correct, but still I have 'old' app running.
Maybe there is some EC2 cache problem or what?
There is nice documentation about your question.

How to connect to specific instance behind Elastic Load Balancer

I'm deploying my app via Elastic Beanstalk, which creates and Elastic load balancer and puts all my instances behind it (3 or more).
Is there a way to contact each of these instances directly? I want to trigger a specific command on each instances (git pull command to synchronize with the latest code in my remote repo).
I have the list of IP address and public DNS of the instances from PHP SDK but since the firewalls rules restricts the source of IP address to the elastic load balancer IP on port 80, I can't seem to access them directly.
Is there a way around it?
P.S. The SSH port seems to open for all traffic, but how can I create a trigger with that? I'm hoping to create a PHP script to automate this with a webhook on the remote repo.
I highly suggest you use the EB CLI with git integration for all deployments, no matter how small. It is great because you can map a git branch to an environment with eb use YOUR_ENV then when you run eb deploy with that branch checked out it will deploy to that environment.
There is a lot of work involved in ensuring multiple servers pull the correct code and everything is working as expected. What if a server is in the processes of spinning up but is not ready for SSH so your script skips it and it does not get the new code?
Also, what happens when a new server spins up but it is using the old application because that's what is in EB? You could have your kickstart do a git pull but then what happens when you are not ready to push, a new server starts and is alone with the new code?
I could probably find 5 more edge cases without breaking a sweat. Look into eb deploy, you will be happy you did.
You need to setup a CI (or make a simple web service) and create a webhook in your repository. Your CI need to get all instances under your Elastic Beanstalk environment and then call git pull via SSH.
Or, just create a cron job in your all instances via .ebxensions script.
I thought it's not a good practice in Elastic Beanstalk to run git pull in order to synchronize your app with your git repo. Because, it misused the Application Version semantic meaning. Sometimes, you can't determine which app version are in your instances from Application Version. It's better to create a new Application Version in Elastic Beanstalk to deploy a new app version.
If you host your repo in Github, you can take a look into CodeDeploy.

running a docker loop device on aws

I'm new to aws and am having some issues with getting my mobile app back running again. Forgive me if this question seems vague.
For a school project we created a mobile app on aws and deployed using docker containers (another student managed these tasks). When trying to get my own key pair to ssh into my ec2 instance i detached the volume associated with my instance and reattached it after getting my own key pair. Now i can ssh into my instance but my front end cant talk to my web server.
So my question is, do i create a new application on elastic beanstalk to deploy my app? Even though when i run lsblk is shows a have a docker loop device and when i run docker images i see several that match the name of my application? or do i somehow get the container running again, docker run doesn't seem to be working.
No need, just upload a new update into Elastic Beanstalk. AWS will handle the rest.
FYI, Elastic Beanstalk - Single Docker Container update process (simple under the hood):
You upload the update into AWS.
AWS will put it on your S3.
Inside your EC2, there is an Elastic Beanstalk agent. It will check for a new update.
If there is an update, the agent will download the update file and extract it.
The agent will build a new Docker image.
If the build is success, it will generate a new config to tell Nginx (web proxy) the new web server container.
Nginx will be reloaded.
Your old docker container will be destroyed.
Don't change anything inside EC2 of Elastic Beanstalk, except you know what you do. Elastic Beanstalk is design for automate deployment and scaling. So, if you change something in your EC2 manually, it might be lost. Of course, you can modified your EC2 instance, but you need to automate it using .ebextensions or take an image.