Swedish TWOT

You know them. A little too smug in their encapsulated immaturity. Old enough to know enough, but too young to know anything. And sycophantic Western culture, keen to never offend or discount anyone…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to deploy from Gitlab CI

Gitlab CI is a built-in continuous integration tool from Gitlab, in this tutorial, we will explain how to setup auto-deploy for any kind of system

Still using FTP, SFTP or SSH to deploy your websites? Forgotten which files you updated since your last deployment? Seems familiar, look no further and start using Gitlab CI for your deployment.

Auto-deployment has been around for years, but has been made simpler with Gitlab CI and it’s Docker integration.

If you’ve ever deployed a website to both staging and live, your mile may vary but there’s always a problem because you probably forgot to upload something, or overwritten something that shouldn’t have been uploaded yet.

It surely isn’t, as is with every other software solution there are tons of variations.

To give some alternatives: * Jenkins CI * Circle CI * Bitbucket pipelines * …

These all work quite well, Jenkins is also open source but requires an own server for installation and Circle CI is only free for open source projects.

But since Gitlab is the online repo platform I’m using and it has a built-in CI integration which is completely free it makes sense for me to go this route.

You should be able to switch easily since Gitlab CI and many others use the Docker platform behind the scenes.

When pushing any code to your repository Gitlab will check if you have a .gitlab-ci.yml file in your root directory.

This file will define how Gitlab CI should interact with your project.

You define in the file which Docker image should be used and build your commands from there on.

First of all, here’s an example of how I build my very basic Gitlab CI file.

The Docker image chose here is php:7.2-apache, which is defined by the image type.

You can see the stages as steps if the first step fails it won’t go to the next one, which is good because if a test fails you don’t want to actually deploy anything.

The deployment of different apps can be quite different, but one thing is always certain. You’ll need to get your code onto your server somehow. This can be either done using FTP, SFTP or SSH.

Prepare your server

Preparing your server is half the work, most servers and even shared hosting services have git pre-installed. (If not contact your hosting provider)

To transfer the files easily from Gitlab to the server I use a bare repository which will wait for a push to transfer the new code to the right position.

You now created a bare repository in the ~/repos/<my-site>.git directory. Now with nano paste in the following code:

This file acts as a hook when pushing to your server. It will take the code sent from Gitlab and copy it to the defined directory.

In case you need the commands like composer install on your server you can just add them like above.

To finish things, give execute rights to the hook chmod +x hooks/post-receive

Setup Gitlab

Already now you can use the post-receive hook by pushing directly from your local repository, this defeats the purpose of using Gitlab CI though since you’re not running any tests before deploying.

Depending on if you’re using FTP or SSH you’ll need either an FTP password or SSH private key to continue.

Since we don’t want to pass this valuable information as cleartext to our .gitlab-ci.yml file I add them to the Gitlab CI secret variables.

Setup .gitlab-ci.yml file.

Now that your server and Gitlab is ready it’s time to set up the .gitlab-ci.yml for deployment!

Remember, we just need to push our code to the hook made on our server, that’s it!

If you have any questions, like always feel free to comment below!

Get involved on Slack!

Have any more questions? Come and join us on Slack and get involved in the web community! I will help with any questions I can help with regards web development, SEO and hosting.

Add a comment

Related posts:

Detect Nudes Using Python Programming and Deep AI

My name is Rohit Kumar Thakur. Last night I was surfing the internet and trying to download a movie. But that movie site was full of personalized nude ads. I thought, is it possible to detect nudes…

Brainwashed Baby CRT Antiracist Baby by Ibram X. Kendi. Brainwashing In the Political Arena

Thank to Judicial Watch for obtaining Documents from Montgomery County Public Schools in Maryland. Get the Exclusive Documents here Brainwashing In the Political Arena: maybe you are Left, Right or…

Prioritize Your Health with Responsible Online Purchase of Medications

When it comes to managing your health, access to necessary medications plays a crucial role. In today’s digital age, online pharmacies have emerged as a convenient option for purchasing prescription…