Forked from montrealist/deploy-to-digital-ocean.markdown
Created
March 22, 2018 15:42
-
-
Save drklrd/9419a934d1f7e8c3c165850f9690e2e9 to your computer and use it in GitHub Desktop.
Revisions
-
montrealist revised this gist
Dec 29, 2016 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -108,6 +108,7 @@ git push Inside the logfile, you should see something like this: ``` [INFO ] Updating repository /site [INFO ] HEAD is now at 7d1153a updated gulp to reflect directory change [INFO ] Repository /site successfully updated @@ -118,6 +119,19 @@ Inside the logfile, you should see something like this: [INFO ] 3 commands executed with status; [0, 0, 0] [DEBUG] Successfully released lock: /site/status_running [INFO ] Done ``` If you see an error like below, it means your folder/file permissions are incorrect. Make sure the `git-auto-deploy` user can write to the folder. I just made this user owner of the `public` folder. ``` [ERROR] error: cannot open .git/FETCH_HEAD: Permission denied ``` If you see the below, try to run a `git pull` inside the repo on the server before you test pushing to Gitlab from your machine. ``` [ERROR] fatal: Not a git repository (or any of the parent directories): .git ``` On the server, all the files from repo should now be present. Now every time you push to Gitlab, these changes will also be pushed to your DO server. Rejoice! -
montrealist revised this gist
Dec 29, 2016 . No changes.There are no files selected for viewing
-
montrealist revised this gist
Dec 29, 2016 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ How to get auto-deploy working from Gitlab to your Digital Ocean (DO) server. Install https://github.com/olipo186/Git-Auto-Deploy (via apt-get): ``` sudo apt-get install software-properties-common @@ -9,19 +9,19 @@ sudo apt-get update sudo apt-get install git-auto-deploy ``` Change config file to match your setup: ``` nano /etc/git-auto-deploy.conf.json ``` Here's my config file: ``` { "logfilepath": "/var/log/git-auto-deploy.log", "host": "0.0.0.0", "port": 8016, "global_deploy": [ "echo Deploy started!", "echo Deploy completed!" @@ -39,13 +39,13 @@ Here's my example: } ``` You need to make sure you have the port you specify - in my case 8016 - allowed by the firewall: ``` sudo ufw allow 8016/tcp ``` Time to start the `git-auto-deploy` service and test the port. ``` service git-auto-deploy start @@ -55,23 +55,23 @@ service git-auto-deploy status // * /usr/bin/git-auto-deploy is running From another machine, check if the port is receiving connections: ``` $ telnet domain.com 8016 Trying XXX.XXX.XX.XX... Connected to domain.com. Escape character is '^]'. ``` Now you can add it as a hook in Gitlab. As per git-auto-deploy docs, 'Go to your repository -> Settings -> Web hooks. In "URL", enter your hostname and port (http://domain.com:8016). Hit "Add Web Hook"''. The secret token must be the same as in `git-auto-deploy.conf.json` above. I left "Enable SSL verification" unchecked. After you add it, click the 'test' button to make sure it returns HTTP 200. On DO server, there will be a new user, git-auto-deploy and group with the same name. You need to generate an SSH key for this user _on the server_ in their home directory, under .ssh(`cd ~/.ssh`): ``` ssh-keygen -t rsa -C "git_auto_deploy_on_digital_ocean" -b 4096 ``` Add the new public key (contents of the `~/.ssh/id_rsa.pub`) to Gitlab, click on user icon in the top right, then user settings -> SSH keys Test it on the server: ``` git init @@ -80,7 +80,7 @@ git fetch ``` If the fetch completes without error then your SSH key works. Here's the directory structure to keep all the service stuff (.git directory, package.json, etc.) outside of the publicly-accessible folder: ``` |--site @@ -91,7 +91,7 @@ If the fetch completes without error then your SSH key works. |--index.html ``` You're ready to test it out. Put a tail on the log file: ``` tail -f /var/log/git-auto-deploy.log -
montrealist renamed this gist
Dec 29, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
montrealist created this gist
Dec 29, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,123 @@ How to get auto-deploy working from Gitlab to your Digital Ocean (DO) server. - install https://github.com/olipo186/Git-Auto-Deploy (via apt-get): ``` sudo apt-get install software-properties-common sudo add-apt-repository ppa:olipo186/git-auto-deploy sudo apt-get update sudo apt-get install git-auto-deploy ``` - change config file to match your setup: ``` nano /etc/git-auto-deploy.conf.json ``` Here's my example: ``` { "logfilepath": "/var/log/git-auto-deploy.log", "host": "0.0.0.0", "port": 8003, "global_deploy": [ "echo Deploy started!", "echo Deploy completed!" ], "repositories": [ { "url": "https://gitlab.com/username/domain.com.git", "branch": "master", "remote": "origin", "path": "/site", "deploy": "echo deploying", "secret-token": "secretstuff" } ] } ``` - You need to make sure you have the port you specify - in my case 8003 - allowed by the firewall: ``` sudo ufw allow 8003/tcp ``` - start the service and test the port: ``` service git-auto-deploy start service git-auto-deploy status // * /usr/bin/git-auto-deploy is running ``` From another machine, check if the port is receiving connections: ``` $ telnet domain.com 8003 Trying XXX.XXX.XX.XX... Connected to domain.com. Escape character is '^]'. ``` - Now you can add it as a hook in Gitlab. As per git-auto-deploy docs, 'Go to your repository -> Settings -> Web hooks. In "URL", enter your hostname and port (http://domain.com:8003). Hit "Add Web Hook"''. The secret token must be the same as in `git-auto-deploy.conf.json` above. I left "Enable SSL verification" unchecked. After you add it, click the 'test' button to make sure it returns HTTP 200. - on DO server, there will be a new user, git-auto-deploy and group with the same name. You need to generate an SSH key for this user _on the server_ in their home directory, under .ssh(`cd ~/.ssh`): ``` ssh-keygen -t rsa -C "git_auto_deploy_on_digital_ocean" -b 4096 ``` - add the new public key (contents of the `~/.ssh/id_rsa.pub`) to Gitlab, click on user icon in the top right, then user settings -> SSH keys - test it on the server: ``` git init git remote add origin https://gitlab.com/username/domain.com.git git fetch ``` If the fetch completes without error then your SSH key works. - here's the directory structure to keep all the service stuff (.git directory, package.json, etc.) outside of the publicly-accessible folder: ``` |--site |--.git |--package.json |--public_html |--assets |--index.html ``` - You're ready to test it out. Put a tail on the log file: ``` tail -f /var/log/git-auto-deploy.log ``` On your machine, commit a test file and push: ``` touch test.html git add test.html git commit -m 'test' git push ``` Inside the logfile, you should see something like this: [INFO ] Updating repository /site [INFO ] HEAD is now at 7d1153a updated gulp to reflect directory change [INFO ] Repository /site successfully updated [INFO ] Executing 3 deploy commands [INFO ] Deploy started! [INFO ] deploying [INFO ] Deploy completed! [INFO ] 3 commands executed with status; [0, 0, 0] [DEBUG] Successfully released lock: /site/status_running [INFO ] Done On the server, all the files from repo should now be present. Now every time you push to Gitlab, these changes will also be pushed to your DO server. Rejoice!