Created
September 26, 2017 11:42
-
-
Save ethicalvats/5ff561883b7ab3083f7391a2ce95b139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome | |
#Deplyoing to Production | |
## Deployment using dokku (docker manager) | |
*The current way of setting up the server requires knowledge with following:* | |
- *Git* | |
- *docker* | |
- *ssh* | |
#### 1. Setting up the server for deployment | |
ssh into the server using EC2 instance IP or Elastic IP using the provided publickey(ask from the system adminitrators) | |
``` | |
ssh <user>@<IP> -i <local path to publickey> | |
E.g. ssh [email protected] -i ~/Desktop/stuff/aws/vatsdev1.pem | |
``` | |
Install the dokku package (http://dokku.viewdocs.io/dokku/) | |
``` | |
# for debian systems, installs dokku via apt-get | |
$ wget https://raw.githubusercontent.com/dokku/dokku/v0.9.4/bootstrap.sh | |
$ sudo DOKKU_TAG=v0.9.4 bash bootstrap.sh | |
# go to your server's IP and follow the web installer | |
``` | |
Let the script do its thing, once completed check for dokku command is available in the bash | |
``` | |
dokku | |
``` | |
It should display its man page. | |
Now create a new app(under the hood it creates a new docker image and sets it up with proper configurations) | |
``` | |
dokku apps:create <app_name> | |
``` | |
*Note: In case using AWS RDS, don't follow below method* | |
Setup the new MongoDb instance | |
But first install dokku mongo plugin | |
``` | |
sudo dokku plugin:install https://github.com/dokku/dokku-mongo.git mysql | |
``` | |
Now create a new db | |
``` | |
dokku mongo:create <db_name> | |
``` | |
If db needs to be imported | |
``` | |
dokku mongo:import <name> < <file> | |
``` | |
Now connect the db to our app | |
``` | |
dokku mongo:link <db_name> <app_name> | |
``` | |
It would set the *ENVIRONMENT VARIABLES* for the app to required for communication with db | |
###### Adding the ssh key to the dokku | |
``` | |
cat <publickey>.pub | |
E.g. cat ~/.ssh/id_rsa.pub | |
``` | |
visit server IP and paste the key inside the form and submit(It is a one time process). | |
For adding your public key anytime later | |
``` | |
cat ~/.ssh/<publickey>.pub | ssh <user>@<IP> "sshcommand acl-add dokku <description>" | |
E.g. ~ cat ~/.ssh/id_rsa.pub | ssh [email protected] "sshcommand acl-add dokku dev" | |
``` | |
#### 2. Doing the first time Deployment | |
Clone the app using git | |
``` | |
git clone <git_url> <dir_name> | |
``` | |
Add another remote for dokku push | |
``` | |
git remote add dokku dokku@<IP>:<app_name> | |
E.g. git remote add dokku [email protected]:node-app | |
``` | |
Now make code chnage, add the files and commit | |
``` | |
git add . | |
git commit -m "brief description of the committed code changes" | |
``` | |
Push to dokku server | |
``` | |
git push dokku master | |
``` | |
*Dokku only accepts master branch* | |
You should see the server output in your console and at the end the git push message with commtted sha value. | |
The app would be deployed on the server and can be accessible by going to the provided IP:PORT of the git push server IP | |
#### 2. Deployment of susequent changes | |
A normal git push to dokku remote will do redeployment of the app. | |
``` | |
ssh-agent $(ssh-add ~/.ssh/<privatkey>; git push dokku master) | |
E.g. ssh-agent $(ssh-add ~/.ssh/id_rsa; git push dokku master) | |
``` | |
Which would destroy the old docker container and it would recreate and reinitialize and new docker container with updated source code. All the linked services like database etc would remain unaffected. | |
*Note: During this process any new files added into the container after deployment for e.g. images would be deleted permanently* | |
--------------------------------- | |
Connect to DB (prod) | |
dokku mongo:connect <db_name> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment