Deployment from git to virtual webhosting

Started by lamnzxzfd, Nov 21, 2022, 12:33 AM

Previous topic - Next topic

lamnzxzfdTopic starter

Hey there!

I have a question regarding manual site deployment via Github to the server. Currently, I build and develop the website on my local computer, then send it to Github in order to clone the project via ssh to virtual hosting.

Although everything seems to be working well, I am a bit hesitant about keeping both the source code and the finished assembly on Github. As a result, all sources are also pulled along with the folder .git to the hosting, which doesn't seem particularly correct.

One option is to name the folder with the assembly public_html and clone it to the shared folder with the site for hosting. This way, only the assembly would get into the public_html folder, which is accessible from the outside. However, all the sources are still being pulled to hosting, even if they don't fall into public_html.

Could you please help me understand if I'm missing anything? I'm a beginner when it comes to this and we're not yet talking about any hooks or CI deployment.
  •  

PrimoPierotz

One alternative to logging in via ssh is to collect the data locally and then send it to the server via scp/rsync. I'm not entirely sure what manual deployment is, but I do recall collecting projects directly on the server at one point.

What I do know for certain is that storing the assembly in git with the source code is not acceptable. Even without ci, you can use a script to collect, archive, and copy the scp project to a remote server. Of course, you could also accomplish this manually by collecting the archive, copying it to the server, and unpacking it.
  •  

outsourcelink

In order to use Git, you must have repositories on either your local computer or in your GitHub, GitLab or bitbucket account. If you're interested in deploying these repositories on your real server via cPanel and have previously used the manual method of downloading your repositories from GitHub, GitLab or Bitbucket, then manually uploading them through the cPanel file manager tool, we have good news for you.

By following a few simple steps, we can show you how to automatically deploy your repositories to cPanel. Assuming you have the appropriate permissions, you can even host a local git repository with a remote online repository (such as Github or Bitbucket) in a cPanel account.

As a reminder, Git is an open source Version Control System (VCS) that allows you to track the history and versions of content (files and directories) without overwriting any part of the project. This enables developers to collaborate and work on a project simultaneously.
  •  

arashigorez

When you clone a repository from GitHub, it includes the entire commit history and all the files in your project, including the source code and any other files needed for building and deployment. It's normal for all the source code to be pulled onto the hosting server.

However, you can structure your repository and deployment process in a way that separates the source code from the production-ready files that should be exposed to the public. Here are a few suggestions:

1. Separate Source Code and Build Files: You can create a separate branch (e.g., "source" or "development") that contains only the source code and the necessary build scripts. This branch should not include any production-ready files. Then, keep the "master" or "main" branch clean and use it solely for production-ready files.

2. Use a Build Tool: Consider using a build tool like Grunt, Gulp, or Webpack to automate the process of generating the production-ready files. These tools can compile your source code, optimize assets, and generate a folder (e.g., "build" or "dist") that contains only the files needed for deployment.

3. .gitignore: Create a .gitignore file in your repository's root directory and specify all the files and folders you don't want to be tracked by Git. This will prevent them from being included in the cloning process.

4. Deployment Script: Use a deployment script or tool to copy only the necessary files from your repository to the hosting server. You can configure it to exclude certain files or directories, such as the ".git" folder or any other development-related files.


Here are a few more tips to consider for your manual site deployment:

1. Create a separate configuration file: You can create a configuration file (e.g., config.php or settings.json) that contains environment-specific information such as database credentials or API keys. Make sure this file is not tracked by Git and is excluded from the deployment process. On the hosting server, you can then have a different version of this file with the necessary production values.

2. Use environment variables: Instead of storing sensitive information directly in your code or configuration files, consider using environment variables. This allows you to keep your secrets separate from your source code. Many hosting providers allow you to set environment variables in their control panels or via command-line tools.

3. Implement a deployment plan: Document your deployment steps and ensure consistency across deployments. This includes tasks like clearing caches, updating dependencies, and restarting services. Having a well-defined plan will help streamline the process and reduce the chances of errors.

4. Take backup precautions: Before deploying any changes, it's always a good practice to take a backup of your production files and database. This ensures you have a restore point in case something goes wrong during the deployment process.

5. Test thoroughly before deploying: Make sure to thoroughly test your website on a separate staging environment before deploying it to the live server. This helps identify any issues or bugs that might arise during deployment.

Remember, as your project grows and becomes more complex, you may want to explore automated deployment solutions, such as using Continuous Integration/Continuous Deployment (CI/CD) tools like Jenkins, Travis CI, or CircleCI. These tools can help streamline and automate the deployment process further.
  •