{"componentChunkName":"component---src-templates-blog-post-js","path":"/continuous-deployment-git-cpanel/","result":{"data":{"site":{"siteMetadata":{"title":"Rope and Tire","author":"Suprada Urval"}},"markdownRemark":{"id":"ed6d67d4-94cb-5f19-a431-de99139c7a32","excerpt":"Do you run your own static site / blog? Do you still have a shared web hosting service you pay for? Would you like to jump into continuous deployment using just your web host? Sections Today’s manual steps to update site on my web host The automated…","html":"<p>Do you run your own static site / blog? Do you still have a shared web hosting service you pay for? Would you like to jump into continuous deployment using just your web host?</p>\n<h3>Sections</h3>\n<ol>\n<li><a href=\"#today\">Today’s manual steps to update site on my web host</a></li>\n<li><a href=\"#iwouldlike\">The automated way I would like</a></li>\n<li><a href=\"#enablecpanel\">How to enable continuous deployment using git and cPanel</a>\n<ol>\n<li><a href=\"#prerequisites\">Prerequisites</a></li>\n<li><a href=\"#emptygvc\">Create an empty repository on your cPanel Git Version Control interface</a></li>\n<li><a href=\"#cpanelsshlocaldev\">Connect cPanel your local development machine via ssh</a></li>\n<li><a href=\"#managecpanel\">Add the cPanel managed repository as a remote on your local repository</a></li>\n<li><a href=\"#gitignore\"><code class=\"language-text\">.gitignore</code> issues</a></li>\n<li><a href=\"#githook\">Setup automatic deployment via post-receive git hook</a></li>\n<li><a href=\"#emailnotification\">Sending an email once the copy is completed.</a></li>\n</ol>\n</li>\n<li><a href=\"#finalprocess\">Final Process</a></li>\n<li><a href=\"#zalinks\">Links I used to research and implement this</a></li>\n</ol>\n<h3><a name=\"today\"></a>Today’s manual steps to update site on my web host</h3>\n<p>I host my <a href=\"blog.suprada.com\">blog</a> my domain. I use <a href=\"https://www.gatsbyjs.com\">Gatsby</a> to build this blog. The source code is hosted on <a href=\"https://bitbucket.org/\">Bitbucket</a>. Once built, the static files are hosted on <a href=\"https://www.webhostinghub.com/\">Webhosting Hub </a>.</p>\n<p>Today, my process is follows:</p>\n<ol>\n<li>Draft and edit post on <a href=\"https://obsidian.md/\">Obsidian</a></li>\n<li>Use <a href=\"https://code.visualstudio.com/\">VSCode</a> to update <a href=\"blog.suprada.com\">my Gatsby blog</a> repository with this post.</li>\n<li>Test locally. Build. Test the build</li>\n<li>Push the source changes up to Bitbucket.</li>\n<li>Use<a href=\"https://filezilla-project.org/\">Filezilla</a> to FTP to my webhost’s file system and navigate to the correct folder</li>\n<li>Drag + drop the recently updated distribution files (the ‘public’ folder for Gatsby) to Filezilla.</li>\n<li>Refresh and test my live site.</li>\n</ol>\n<h3><a name=\"iwouldlike\"></a>The automated way I would like</h3>\n<p>While this works, I was looking to automate Steps 6 to 9. Once I push the source changes, I would like to have the web host files updated with the new build .I have setup <a href=\"https://www.netlify.com\">Netlify</a> pipelines for my <a href=\"booknotes.suprada.com\">Booknotes site</a> which does exactly that.</p>\n<p>However once I realized that thanks to Git + cPanel, one push deployment can be done, I wanted to try it out. Why - I like the idea of trying something new - I like the idea of relying /maintaining one less service - for my small needs.</p>\n<p>Visually, this is the flow I want. Basically, what cPanel calls ”<a href=\"https://docs.cpanel.net/knowledge-base/web-services/guide-to-git-how-to-set-up-deployment/\">Push Deployment</a>”</p>\n<div class=\"mermaid\" data-processed=\"true\"><svg id=\"mermaid-1621296334695\" width=\"100%\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"974.9109497070312\" style=\"max-width: 684.1796875px;\" viewBox=\"0 0 684.1796875 974.9109497070312\"><style>#mermaid-1621296334695{font-family:\"trebuchet ms\",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-1621296334695 .error-icon{fill:#552222;}#mermaid-1621296334695 .error-text{fill:#552222;stroke:#552222;}#mermaid-1621296334695 .edge-thickness-normal{stroke-width:2px;}#mermaid-1621296334695 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-1621296334695 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-1621296334695 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-1621296334695 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-1621296334695 .marker{fill:#333333;stroke:#333333;}#mermaid-1621296334695 .marker.cross{stroke:#333333;}#mermaid-1621296334695 svg{font-family:\"trebuchet ms\",verdana,arial,sans-serif;font-size:16px;}#mermaid-1621296334695 .label{font-family:\"trebuchet ms\",verdana,arial,sans-serif;color:#333;}#mermaid-1621296334695 .cluster-label text{fill:#333;}#mermaid-1621296334695 .cluster-label span{color:#333;}#mermaid-1621296334695 .label text,#mermaid-1621296334695 span{fill:#333;color:#333;}#mermaid-1621296334695 .node rect,#mermaid-1621296334695 .node circle,#mermaid-1621296334695 .node ellipse,#mermaid-1621296334695 .node polygon,#mermaid-1621296334695 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-1621296334695 .node .label{text-align:center;}#mermaid-1621296334695 .node.clickable{cursor:pointer;}#mermaid-1621296334695 .arrowheadPath{fill:#333333;}#mermaid-1621296334695 .edgePath .path{stroke:#333333;stroke-width:1.5px;}#mermaid-1621296334695 .flowchart-link{stroke:#333333;fill:none;}#mermaid-1621296334695 .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-1621296334695 .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-1621296334695 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-1621296334695 .cluster text{fill:#333;}#mermaid-1621296334695 .cluster span{color:#333;}#mermaid-1621296334695 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\"trebuchet ms\",verdana,arial,sans-serif;font-size:12px;background:hsl(80,100%,96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-1621296334695 .node rect{font-size:80%;overflow:visible;}#mermaid-1621296334695,#mermaid-1621296334695 .label foreignObject{font-size:80%;overflow:visible;}#mermaid-1621296334695:root{--mermaid-font-family:\"trebuchet ms\",verdana,arial,sans-serif;}#mermaid-1621296334695 flowchart{fill:apa;}</style><g><g class=\"output\"><g class=\"clusters\"><g class=\"cluster\" id=\"flowchart-id34-27\" transform=\"translate(342.08984375,487.45547103881836)\" style=\"opacity: 1;\"><rect style=\"fill:#efefef;margin:300px;\" width=\"668.1796875\" height=\"958.9109420776367\" x=\"-334.08984375\" y=\"-479.45547103881836\"></rect><g class=\"label\" transform=\"translate(0, -465.4554748535156)\" id=\"mermaid-1621296334695Text\"><g transform=\"translate(-149.578125,-7.5)\"><foreignObject width=\"299.15625\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Desired automated deployment using git and cPanel</div></foreignObject></g></g></g></g><g class=\"edgePaths\"><g class=\"edgePath LS-id1 LE-id2\" id=\"L-id1-id2\" style=\"opacity: 1;\"><path class=\"path\" d=\"M92.51256793478261,644.4109420776367L57.0234375,604.4109420776367L57.0234375,510.14844131469727L57.0234375,423.3859405517578L57.0234375,380.8859405517578L57.0234375,338.3859405517578L57.0234375,295.8859405517578L57.0234375,245.8859405517578L57.0234375,165.6929702758789L57.0234375,93L165.7578125,62.55347951410336\" marker-end=\"url(#arrowhead111)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead111\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id2 LE-id6\" id=\"L-id2-id6\" style=\"opacity: 1;\"><path class=\"path\" d=\"M231.51351087233598,68L263.9546871185303,93L264.4546871185303,118.50000152587893\" marker-end=\"url(#arrowhead112)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead112\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id6 LE-id1\" id=\"L-id6-id1\" style=\"opacity: 1;\"><path class=\"path\" d=\"M239.2645692385783,188.69582114592703L174.18515586853027,245.8859405517578L174.18515586853027,295.8859405517578L174.18515586853027,338.3859405517578L174.18515586853027,380.8859405517578L174.18515586853027,423.3859405517578L174.18515586853027,510.14844131469727L174.18515586853027,604.4109420776367L128.17048222085702,644.4109420776367\" marker-end=\"url(#arrowhead113)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead113\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id6 LE-id3\" id=\"L-id6-id3\" style=\"opacity: 1;\"><path class=\"path\" d=\"M282.4010942838582,195.93952880879309L312.3359375,245.8859405517578L312.3359375,278.3859405517578\" marker-end=\"url(#arrowhead114)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead114\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id3 LE-id4\" id=\"L-id3-id4\" style=\"opacity: 1;\"><path class=\"path\" d=\"M312.3359375,313.3859405517578L312.3359375,338.3859405517578L312.3359375,363.3859405517578\" marker-end=\"url(#arrowhead115)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead115\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id4 LE-id5\" id=\"L-id4-id5\" style=\"opacity: 1;\"><path class=\"path\" d=\"M312.3359375,398.3859405517578L312.3359375,423.3859405517578L312.8359375,448.88594131469745\" marker-end=\"url(#arrowhead116)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead116\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id5 LE-id1\" id=\"L-id5-id1\" style=\"opacity: 1;\"><path class=\"path\" d=\"M270.755691396016,530.3306952107132L110.8046875,604.4109420776367L108.88077445652173,644.4109420776367\" marker-end=\"url(#arrowhead117)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead117\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id5 LE-id8\" id=\"L-id5-id8\" style=\"opacity: 1;\"><path class=\"path\" d=\"M311.07550038221177,570.650504196909L309.5703125,604.4109420776367L309.5703125,636.9109420776367\" marker-end=\"url(#arrowhead118)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead118\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id8 LE-id9\" id=\"L-id8-id9\" style=\"opacity: 1;\"><path class=\"path\" d=\"M309.5703125,686.9109420776367L309.5703125,711.9109420776367L309.5703125,736.9109420776367\" marker-end=\"url(#arrowhead119)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead119\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id5 LE-id10\" id=\"L-id5-id10\" style=\"opacity: 1;\"><path class=\"path\" d=\"M356.0857661554474,529.1611111333713L532.5546875,604.4109420776367L532.5546875,636.9109420776367\" marker-end=\"url(#arrowhead120)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead120\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id10 LE-id11\" id=\"L-id10-id11\" style=\"opacity: 1;\"><path class=\"path\" d=\"M532.5546875,686.9109420776367L532.5546875,711.9109420776367L532.5546875,736.9109420776367\" marker-end=\"url(#arrowhead121)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead121\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id11 LE-id12\" id=\"L-id11-id12\" style=\"opacity: 1;\"><path class=\"path\" d=\"M532.5546875,771.9109420776367L532.5546875,796.9109420776367L532.5546875,821.9109420776367\" marker-end=\"url(#arrowhead122)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead122\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g><g class=\"edgePath LS-id12 LE-id13\" id=\"L-id12-id13\" style=\"opacity: 1;\"><path class=\"path\" d=\"M532.5546875,856.9109420776367L532.5546875,881.9109420776367L533.0546875000001,907.4109420776367\" marker-end=\"url(#arrowhead123)\" style=\"fill:none\"></path><defs><marker id=\"arrowhead123\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"8\" markerHeight=\"6\" orient=\"auto\"><path d=\"M 0 0 L 10 5 L 0 10 z\" class=\"arrowheadPath\" style=\"stroke-width: 1; stroke-dasharray: 1, 0;\"></path></marker></defs></g></g><g class=\"edgeLabels\"><g class=\"edgeLabel\" transform=\"\" style=\"opacity: 1;\"><g transform=\"translate(0,0)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"0\" height=\"0\"></rect><foreignObject width=\"0\" height=\"0\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id1-id2\" class=\"edgeLabel L-LS-id1' L-LE-id2\"></span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"\" style=\"opacity: 1;\"><g transform=\"translate(0,0)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"0\" height=\"0\"></rect><foreignObject width=\"0\" height=\"0\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id2-id6\" class=\"edgeLabel L-LS-id2' L-LE-id6\"></span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"translate(174.18515586853027,380.8859405517578)\" style=\"opacity: 1;\"><g transform=\"translate(-7.5234375,-7.5)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"15.046875\" height=\"15\"></rect><foreignObject width=\"15.046875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id6-id1\" class=\"edgeLabel L-LS-id6' L-LE-id1\">No</span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"translate(312.3359375,245.8859405517578)\" style=\"opacity: 1;\"><g transform=\"translate(-9.734375,-7.5)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"19.46875\" height=\"15\"></rect><foreignObject width=\"19.46875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id6-id3\" class=\"edgeLabel L-LS-id6' L-LE-id3\">Yes</span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"\" style=\"opacity: 1;\"><g transform=\"translate(0,0)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"0\" height=\"0\"></rect><foreignObject width=\"0\" height=\"0\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id3-id4\" class=\"edgeLabel L-LS-id3' L-LE-id4\"></span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"\" style=\"opacity: 1;\"><g transform=\"translate(0,0)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"0\" height=\"0\"></rect><foreignObject width=\"0\" height=\"0\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id4-id5\" class=\"edgeLabel L-LS-id4' L-LE-id5\"></span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"translate(110.8046875,604.4109420776367)\" style=\"opacity: 1;\"><g transform=\"translate(-7.5234375,-7.5)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"15.046875\" height=\"15\"></rect><foreignObject width=\"15.046875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id5-id1\" class=\"edgeLabel L-LS-id5' L-LE-id1\">No</span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"translate(309.5703125,604.4109420776367)\" style=\"opacity: 1;\"><g transform=\"translate(-9.734375,-7.5)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"19.46875\" height=\"15\"></rect><foreignObject width=\"19.46875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id5-id8\" class=\"edgeLabel L-LS-id5' L-LE-id8\">Yes</span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"\" style=\"opacity: 1;\"><g transform=\"translate(0,0)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"0\" height=\"0\"></rect><foreignObject width=\"0\" height=\"0\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id8-id9\" class=\"edgeLabel L-LS-id8' L-LE-id9\"></span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"translate(532.5546875,604.4109420776367)\" style=\"opacity: 1;\"><g transform=\"translate(-9.734375,-7.5)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"19.46875\" height=\"15\"></rect><foreignObject width=\"19.46875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id5-id10\" class=\"edgeLabel L-LS-id5' L-LE-id10\">Yes</span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"\" style=\"opacity: 1;\"><g transform=\"translate(0,0)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"0\" height=\"0\"></rect><foreignObject width=\"0\" height=\"0\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id10-id11\" class=\"edgeLabel L-LS-id10' L-LE-id11\"></span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"\" style=\"opacity: 1;\"><g transform=\"translate(0,0)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"0\" height=\"0\"></rect><foreignObject width=\"0\" height=\"0\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id11-id12\" class=\"edgeLabel L-LS-id11' L-LE-id12\"></span></div></foreignObject></g></g><g class=\"edgeLabel\" transform=\"\" style=\"opacity: 1;\"><g transform=\"translate(0,0)\" class=\"label\"><rect rx=\"0\" ry=\"0\" width=\"0\" height=\"0\"></rect><foreignObject width=\"0\" height=\"0\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\"><span id=\"L-L-id12-id13\" class=\"edgeLabel L-LS-id12' L-LE-id13\"></span></div></foreignObject></g></g></g><g class=\"nodes\"><g class=\"node default\" id=\"flowchart-id2-29\" transform=\"translate(208.8046875,50.5)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-43.046875\" y=\"-17.5\" width=\"86.09375\" height=\"35\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-33.046875,-7.5)\"><foreignObject width=\"66.09375\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Test locally</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id1-28\" transform=\"translate(108.0390625,661.9109420776367)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-65.0390625\" y=\"-17.5\" width=\"130.078125\" height=\"35\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-55.0390625,-7.5)\"><foreignObject width=\"110.078125\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Make local changes</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id6-31\" transform=\"translate(263.9546871185303,165.6929702758789)\" style=\"opacity: 1;\"><polygon points=\"47.69296875,0 95.3859375,-47.69296875 47.69296875,-95.3859375 0,-47.69296875\" transform=\"translate(-47.69296875,47.69296875)\" class=\"label-container\"></polygon><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-25.4921875,-7.5)\"><foreignObject width=\"50.984375\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Working?</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id3-35\" transform=\"translate(312.3359375,295.8859405517578)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-24.3984375\" y=\"-17.5\" width=\"48.796875\" height=\"35\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-14.3984375,-7.5)\"><foreignObject width=\"28.796875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Build</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id4-37\" transform=\"translate(312.3359375,380.8859405517578)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-38.609375\" y=\"-17.5\" width=\"77.21875\" height=\"35\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-28.609375,-7.5)\"><foreignObject width=\"57.21875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Test build</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id5-39\" transform=\"translate(312.3359375,510.14844131469727)\" style=\"opacity: 1;\"><polygon points=\"61.7625,0 123.525,-61.7625 61.7625,-123.525 0,-61.7625\" transform=\"translate(-61.7625,61.7625)\" class=\"label-container\"></polygon><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-41.125,-7.5)\"><foreignObject width=\"82.25\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Build working?</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id8-43\" transform=\"translate(309.5703125,661.9109420776367)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-86.4921875\" y=\"-25\" width=\"172.984375\" height=\"50\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-76.4921875,-15)\"><foreignObject width=\"152.984375\" height=\"30\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">All changes except <br> distribution or public files <br></div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id9-45\" transform=\"translate(309.5703125,754.4109420776367)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-60.453125\" y=\"-17.5\" width=\"120.90625\" height=\"35\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-50.453125,-7.5)\"><foreignObject width=\"100.90625\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Push to Bitbucket</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id10-47\" transform=\"translate(532.5546875,661.9109420776367)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-86.4921875\" y=\"-25\" width=\"172.984375\" height=\"50\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-76.4921875,-15)\"><foreignObject width=\"152.984375\" height=\"30\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">All files including <br> distribution or public files <br></div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id11-49\" transform=\"translate(532.5546875,754.4109420776367)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-108.625\" y=\"-17.5\" width=\"217.25\" height=\"35\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-98.625,-7.5)\"><foreignObject width=\"197.25\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Push to cPanel Git Version Control</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id12-51\" transform=\"translate(532.5546875,839.4109420776367)\" style=\"opacity: 1;\"><rect rx=\"0\" ry=\"0\" x=\"-93.859375\" y=\"-17.5\" width=\"187.71875\" height=\"35\" class=\"label-container\"></rect><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-83.859375,-7.5)\"><foreignObject width=\"167.71875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">cPanel deploys automatically</div></foreignObject></g></g></g><g class=\"node default\" id=\"flowchart-id13-53\" transform=\"translate(532.5546875,924.4109420776367)\" style=\"opacity: 1;\"><polygon points=\"-11.666666666666666,0 161.54166666666666,0 144.04166666666666,-35 5.833333333333333,-35\" transform=\"translate(-74.9375,17.5)\" class=\"label-container\"></polygon><g class=\"label\" transform=\"translate(0,0)\"><g transform=\"translate(-64.9375,-7.5)\"><foreignObject width=\"129.875\" height=\"15\"><div xmlns=\"http://www.w3.org/1999/xhtml\" style=\"display: inline-block; white-space: nowrap;\">Freshly deployed blog!</div></foreignObject></g></g></g></g></g></g></svg></div>\n<h3><a name=\"enablecpanel\"></a>How to enable continuous deployment using git and cPanel</h3>\n<h4>1. <a name=\"prerequisites\"></a>Here are the prerequisites:</h4>\n<ol>\n<li>Your web host offer shell access?</li>\n<li>Your web host offer terminal access?</li>\n<li>Your repo host allow ssh access? (Github, Bitbucket, Gitlab do.)</li>\n<li>You have a way to build and compile your site to generate static files (Gatsby or Next JS or Create-React-App or some such)</li>\n<li>You know where the built / distribution files live.</li>\n</ol>\n<p>Then</p>\n<h4>2. <a name=\"emptygvc\"></a>Create an empty repository on your cPanel Git Version Control interface</h4>\n<p><a href=\"https://www.youtube.com/watch?v=-whBU90olDA\">youtube instructions</a></p>\n<ol>\n<li>Go to your cPanel. Navigate to ‘Git Version Control’. Click on ‘Create’.</li>\n<li>Make sure that the ‘toggle’ panel is turned OFF.</li>\n<li>In the form, add the repository path - I use /repositories/repository-name</li>\n<li>In the form, fill in the repository name</li>\n<li>Click ‘Create.’</li>\n<li>In the window which pops up, copy the remote / Clone Url</li>\n</ol>\n<h4>3. <a name=\"cpanelsshlocaldev\"></a>Connect cPanel your local development machine via ssh</h4>\n<ol>\n<li>In your local repository, check what your git user.name and user.email are.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git config --local user.name\ngit config --local user.email</code></pre></div>\n<p>If the username and email are not set, you can choose to set it or use the global email. To set it, use the same commands with the values you want to set</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> git config --local user.name &quot;My Name&quot;\n git config --local user.email &quot;my_git_email@example.com&quot;</code></pre></div>\n<p>Make a note of this email address.</p>\n<ol start=\"2\">\n<li>Create SSH keys on your system, using this email address and add it to the ssh-agent. <a href=\"https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent\">Github has great instructions</a> for this. Use the following command for generating the ssh key.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ ssh-keygen -t rsa -b 4096 -C  &quot;my_git_email@example.com&quot;</code></pre></div>\n<ol start=\"3\">\n<li>Give the file a unique name.</li>\n<li>After you run this command, the system will prompt you to enter a passphrase. Do <strong>not</strong> enter a passphrase, and press <em>Enter</em> to continue.</li>\n<li>Add your SSH key to the ssh-agent.\n<ol>\n<li>Start agent in the background <code class=\"language-text\">eval &quot;$(ssh-agent -s)&quot;</code></li>\n<li>For Macs, modify your ssh.config <code class=\"language-text\">open ~/.ssh/config </code></li>\n<li>Add the following lines to it</li>\n<li>\n<div class=\"gatsby-highlight\" data-language=\"host*\"><pre class=\"language-host*\"><code class=\"language-host*\">AddKeysToAgent yes\nUseKeychain yes\n IdentityFile ~/.ssh/&lt;your file name&gt; ```</code></pre></div>\n</li>\n<li>Add your key to the SSH agent. <code class=\"language-text\">ssh-add ~/.ssh/&lt;your file name&gt;</code></li>\n</ol>\n</li>\n<li>Add these keys to your cPanel SSH Keys\n<ol>\n<li>Go to ‘SSH Keys’. Click on Import Key.</li>\n<li>In the form which shows up, fill the following:\n<ol>\n<li>name - I use the same name as the file</li>\n<li>Paste the private key (from the file generated without the .pub extension)</li>\n<li>Leave the passphrase empty</li>\n<li>Paste the public key (from the .pub generated file)</li>\n<li>Click import.</li>\n</ol>\n</li>\n</ol>\n</li>\n</ol>\n<h4>4. <a name=\"managecpanel\"></a>Add the cPanel managed repository as a remote on your local repository</h4>\n<ol>\n<li>\n<p>Update the Clone URL you had copied in the last step of Section 1 with the port.<br>\nFor example, if your URL was <code class=\"language-text\">ssh://username@domain.com/home/{username}/repositories/{reponame}</code> and your port is <code class=\"language-text\">2222</code>, your new URL will be <code class=\"language-text\">ssh://username@domain.com:2222/home/{username}/repositories/{reponame}</code></p>\n</li>\n<li>\n<p>Go to your local repository and add this as a remote. To do this, run the command<br>\n<code class=\"language-text\">git remote add &lt;remotename&gt; &lt;cloneurl&gt;</code>.<br>\n<code class=\"language-text\">&lt;remotename&gt;</code> needs to be unique. Like many others, I use ‘cpanel’ for cPanel, and ‘origin’ for Bitbucket.<br>\n<code class=\"language-text\">&lt;cloneurl&gt;</code> is the clone URL you copied over form Git Version Control.\nNote: the instructions mentioned in cPanel name the remote as ‘origin’. However, I use ‘origin’ for my Github/Bitbucket accounts, and name this remote as ‘cpanel’</p>\n</li>\n<li>\n<p>Push your changes to the cpanel repository.<br>\n<code class=\"language-text\">git push -u cpanel main</code>\nThis should fail at this point with a timeout error</p>\n</li>\n<li>\n<p>.gitignore setup for checking out publci only</p>\n</li>\n</ol>\n<h4>5. <a name='gitignore'></a><code class=\"language-text\">.gitignore</code> issues</h4>\n<p>Generally, for Gatsby repos, the ‘public’ directory is included in the .gitignore file and is ignored and these files are not pushed to the repo. In my case, I want my Bitbucket repo to stay clean, as they are. However I want the public files to get pushed to the cPanel repo. For this, I have to use a slightly clunky mechanism - branches.</p>\n<ol>\n<li>The main branch with clean code remains ‘main’.</li>\n<li>Create a new branch named deployment. <code class=\"language-text\">git checkout -b deployment</code>.</li>\n<li>In the deployment branch, remove ‘public’ from .gitignore.</li>\n<li>Commit the changes in deployment.</li>\n<li>Push the ‘deployment’ branch to cPanel. <code class=\"language-text\">git push cpanel deployment</code>.</li>\n<li>In cPanel, in Git Version Control, go to the repository and <a href=\"https://www.youtube.com/watch?v=-whBU90olDA&#x26;t=4m33s\">set the the ‘Checked-out branch’</a> to ‘deployment.</li>\n</ol>\n<h4>6. <a name='githook'></a>Setup automatic deployment via post-receive git hook</h4>\n<p>The <a href=\"https://docs.cpanel.net/knowledge-base/web-services/guide-to-git-how-to-set-up-deployment/\">official way using a <code class=\"language-text\">.cpanel.yml</code></a> did not work for me. I kept seeing the following error:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[username@domain hooks]$ ./post-receive\n./post-receive: line 17: /dev/stdin: Operation not permitted</code></pre></div>\n<p>Digging on forums, I realized <a href=\"https://forums.cpanel.net/threads/git-automatic-deployment-not-working-but-manual-deployment-is.679837/\">others had similar issue</a></p>\n<p>Instead, inspired by <a href=\"https://www.texelate.co.uk/blog/how-to-set-up-git-in-cpanel-and-use-it-to-publish-files\">here</a> and <a href=\"https://forums.cpanel.net/threads/cpanel-yml-and-staging-production-environments.661589/\">here</a>, I just re-use the post-receive git hook to</p>\n<ul>\n<li>checkout the correct branch, ‘deployment’ in our case</li>\n<li>copy the contents of the public folder in the repository to my deploy path.</li>\n<li>send me an email</li>\n</ul>\n<ol>\n<li>Create a file called ‘post-receive’ with no extension.</li>\n<li>Open the file in a text-editor and use the following code</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#!/bin/sh\n\n# post-receive hook\necho &quot;Received a push to repo. Checking out deployment branch via work tree&quot;\ngit --work-tree=/home/{username}/repositories/{reponame} --git-dir=/home/{username}/repositories/{reponame}/.git checkout -f deployment\n\necho &quot;copy updated files from repo public to deploy path - public_html/blog&quot;\nexport DEPLOYPATH=/home/{username}/public_html/blog/\n/bin/cp -R -u /home/{username}/repositories/{reponame}/public/* $DEPLOYPATH\n\necho &quot;copy done&quot;</code></pre></div>\n<p>In your script, replace <code class=\"language-text\">{username}</code> with your username,<code class=\"language-text\">{reponame}</code> with your repository name, and set the DEPLOYPATH to where you want to deploy.</p>\n<ol start=\"3\">\n<li>Move this file into your web host folder under <code class=\"language-text\">home/{username}/repositories/{reponame}/.git/hooks</code></li>\n<li>Login in terminal in cPanel and make sure the git hook has executable permissions by running\n<code class=\"language-text\">chmod +x /home/{username}/repositories/{reponame}/.git/hooks/post-receive</code></li>\n</ol>\n<p>Now, when you push a file to cPanel from your local repository using <code class=\"language-text\">git push cpanel deployment</code>, this will automatically move the files over to where you want it to be.</p>\n<h4>7. <a name=\"emailnotification\"></a>Sending an email once the copy is completed.</h4>\n<p>I haven’t implemented it yet. <a href=\"https://forums.cpanel.net/threads/git-update-notification.645649/\">https://forums.cpanel.net/threads/git-update-notification.645649/</a> has more information to do this.</p>\n<h3>4. <a name=\"finalprocess\"></a>Final Process:</h3>\n<p>Here is what my process looks like.</p>\n<ol>\n<li>In VSCode, <code class=\"language-text\">git checkout main</code></li>\n<li>Make changes. Test. Commit changes.</li>\n<li>Build using <code class=\"language-text\">gatsby build</code>. Test build</li>\n<li>Push changes to Bitbucket. <code class=\"language-text\">git push origin main</code></li>\n<li>Update the deployment branch with these changes and commit.\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git checkout deployment\ngit merge master\ngit commit -m &quot;update: new blog post&quot;</code></pre></div>\n</li>\n<li>Push the deployment branch changes to cPanel <code class=\"language-text\">git push cpanel deployment</code></li>\n</ol>\n<p>And there you go! Easy-peasy.</p>\n<h3>5. <a name='zalinks'></a>Links I used to research and implement this.</h3>\n<ul>\n<li><a href=\"https://dev.to/cheerupemodev/continuous-deployment-of-a-gatsby-site-to-cpanel-with-git-version-control-5ha2\">https://dev.to/cheerupemodev/continuous-deployment-of-a-gatsby-site-to-cpanel-with-git-version-control-5ha2</a></li>\n<li>[cPanel deploument instructions youtube] (<a href=\"https://www.youtube.com/watch?v=18tXFctuqQ0\">https://www.youtube.com/watch?v=18tXFctuqQ0</a>)</li>\n<li><a href=\"https://docs.cpanel.net/cpanel/security/ssh-access/\">CPanel SSH Access - cPanel Docs</a></li>\n<li><a href=\"https://docs.cpanel.net/knowledge-base/web-services/guide-to-git-how-to-set-up-deployment/\">cPanel Deployment types - cPanel Docs</a></li>\n<li><a href=\"https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent\">Generating a new SSH key and adding it to ssh-agent - Github docs</a></li>\n<li><a href=\"https://www.texelate.co.uk/blog/how-to-set-up-git-in-cpanel-and-use-it-to-publish-files\">https://www.texelate.co.uk/blog/how-to-set-up-git-in-cpanel-and-use-it-to-publish-files</a></li>\n<li><a href=\"https://forums.cpanel.net/threads/cpanel-yml-and-staging-production-environments.661589/\">https://forums.cpanel.net/threads/cpanel-yml-and-staging-production-environments.661589/</a></li>\n<li><a href=\"https://docs.cpanel.net/knowledge-base/web-services/guide-to-git-for-system-administrators/\">cpanel docs git deploynment Troubleshooting link</a></li>\n<li><a href=\"https://forums.cpanel.net/threads/git-update-notification.645649/\">git update notification email from cpanel</a></li>\n</ul>\n<p>I would love to hear from you (tweet @suprada) if you have an even better way of leveraging cpanel!</p>","frontmatter":{"title":"Continuous deployment via git and cPanel for your Gatsby (or other static) blog","date":"April 25, 2021","url":"/continuous-deployment-git-cpanel/","tags":["web-development","automation"]}}},"pageContext":{"slug":"/continuous-deployment-git-cpanel/","previous":{"fields":{"slug":"/2021-04-21-why-i-blog/"},"frontmatter":{"title":"Why I blog","url":"/why-i-blog/","tags":["writing","reading","learning","thoughts"]}},"next":{"fields":{"slug":"/2021-05-17-goal-hierarchies/"},"frontmatter":{"title":"Goal Hierarchy - What is it and why should I spend time thinking about it?","url":"/goal-hierarchy/","tags":["concepts","mental-phenomenon"]}}}},"staticQueryHashes":["3128451518","426816048"]}