Automatically Deploy From GitHub To Server On Push

后端 未结 6 1650
陌清茗
陌清茗 2020-12-02 11:23

We have a VPS on linode, and code hosted on gitHub. How do we setup so when we push to gitHub, it also pushes automatically to our linode server. We are using PHP on the lin

相关标签:
6条回答
  • 2020-12-02 11:53

    I wrote a small Github-Auto-Deploy server in python, that does exactly what you want.

    • Enter your domain to a new post-receive service hook on Github
    • Match local repository paths with repository urls in the config file
    • The server will receive requests from github and run git pull in local repository path
    • It also runs a shell script for deployment afterwards if you provide one
    0 讨论(0)
  • 2020-12-02 11:57

    Using any kind of webhook involves deploying a listener for that hook, and then triggering, from your listener server host, the action.

    You can take a shortcut now (oct. 2018) with GitHub Actions (Oct. 2018).

    GitHub Actions allows you to connect and share containers to run your software development workflow. Easily build, package, release, update, and deploy your project in any language—on GitHub or any external system—without having to run code yourself.

    See Actions: pushing is only one of the possibilities behind Actions!

    Workflows can be triggered by GitHub platform events (i.e. push, issue, release) and can run a sequence of serial or parallel actions in response. Combine and configure actions for the services you know and love built and maintained by the community.

    0 讨论(0)
  • 2020-12-02 11:58

    Maybe i'm out of context but i prefer to manually choose where to push from my command line eg: git push linode

    To do this i create a repository container in my linode server and created a post-receive hook that checkouts my folder to the last pushed commit

    Create a git repo container mkdir /var/repo && cd /var/repo git --bare init

    Create the post-receive hook in /var/repo/hooks/ touch post-receive nano post-receive chmod +x post-receive

    post-receive content #!/bin/sh git --work-tree=/var/www/ --git-dir=/var/repo checkout -f

    On your local repository git remote add linode root@<linode ip|domain>:/var/repo git push linode

    your code is now deployed

    0 讨论(0)
  • 2020-12-02 11:58

    You may refer to this tutorial:
    Automatically Updating Your Website Using GitHub's Service Hooks:

    In short it explains the following steps:

    Create a php file in .git folder on your server with the following contents.

    <?php `git pull`;?>
    

    Setup your server for the SSH keys to exist. Something like:

    key. cat ~/.ssh/id_rsa.pub
    

    Setup the service hook on GitHub . Enter WebHook URL:

    http://your.domain.com/path/to/yourfile.php
    

    When all is set. The file is going deploy all the work on your server each time you push to GitHub.

    0 讨论(0)
  • 2020-12-02 12:03

    I ended up creating my own rudimentary deployment tool (much like Karl but in PHP) which would automatically pull down new updates from the repo - https://github.com/jesalg/SlimJim - Basically it listens to the github post-receive-hook and uses a proxy to trigger an update script.

    0 讨论(0)
  • 2020-12-02 12:04

    You probably want to use GitHub's post-receive hooks.

    In summary, GitHub will POST to a supplied URL when someone pushes to the repo. Just write a short PHP script to run on your linode VPS and pull from GitHub when it receives said POST.

    0 讨论(0)
提交回复
热议问题