Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save drklrd/9419a934d1f7e8c3c165850f9690e2e9 to your computer and use it in GitHub Desktop.

Select an option

Save drklrd/9419a934d1f7e8c3c165850f9690e2e9 to your computer and use it in GitHub Desktop.

Revisions

  1. @montrealist montrealist revised this gist Dec 29, 2016. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions deploy-to-digital-ocean.markdown
    Original 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!

  2. @montrealist montrealist revised this gist Dec 29, 2016. No changes.
  3. @montrealist montrealist revised this gist Dec 29, 2016. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions deploy-to-digital-ocean.markdown
    Original 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):
    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:
    Change config file to match your setup:

    ```
    nano /etc/git-auto-deploy.conf.json
    ```

    Here's my example:
    Here's my config file:

    ```
    {
    "logfilepath": "/var/log/git-auto-deploy.log",
    "host": "0.0.0.0",
    "port": 8003,
    "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 8003 - allowed by the firewall:
    You need to make sure you have the port you specify - in my case 8016 - allowed by the firewall:

    ```
    sudo ufw allow 8003/tcp
    sudo ufw allow 8016/tcp
    ```

    - start the service and test the port:
    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 8003
    $ 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: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.
    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`):
    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
    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:
    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:
    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:
    You're ready to test it out. Put a tail on the log file:

    ```
    tail -f /var/log/git-auto-deploy.log
  4. @montrealist montrealist renamed this gist Dec 29, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @montrealist montrealist created this gist Dec 29, 2016.
    123 changes: 123 additions & 0 deletions gistfile1.txt
    Original 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!