Use Tighten Takeout to manage resources while out to sea on Laravel Sail

Tram Ho

Preface

This is an important part that I believe is also the key to convince people to use Laravel Sail instead of the traditional AMP stack like Laragon. But these days have been too messy, now I can write only a little, hope it still reaches everyone’s hands

The problem that has followed me since I noticed Docker is resource management! Laravel Sail by default comes with Mysql, Redis, MailHog, these are worth mentioning services, but I have not mentioned something like supervisor of all types. Imagine we need to open 3 Sail projects to dev, each with 3 Mysql, 3 Redis, 3 MailHogs, each of which requires a few hundred mb of ram and quite a bit of hard drive space to get the image, sounds a bit painful huh. This is completely a problem for Docker, in this country, Laravel cannot help too much, so I call for the support of one more party, a package of tighten.co , which is Takeout.

What is Takeout?

Takeout, like Sail, is also a tool to manage and use Docker in a more convenient way. But its goal is to create 1-container-unique for each basic service, and be able to share it with all your local projects, whether that project uses Docker or not. Sounds familiar. It’s almost like a services stack like XAMPP but using Docker! At the time of writing this article, Takeout is supporting services like this

See the potential? Even not using Laravel Sail looks good or not

Using

We need to install Takeout global , that is, it can be used anywhere, not limited to a Laravel project, with the command:

Okay, we can now call takeout from anywhere on the terminal. Let’s take a look at some Takeout commands. First, to see what services we can use, let’s call the command below, a list will appear and you can use the navigation key, press up and down to select and press enter!

Also you can enable 1 or more services by passing its short name

During the enable process, there will be a few questions appearing, for example what port do you want to open this service, what is its data save name, … you enter it yourself, press enter always to use the default value. in square brackets, or too lazy, add the --default option to skip all questions and use the default value

To completely disable the service, we have the disable command

You can see the Takeout git link to see all the introduction and its commands

Let’s try MySQL

By default, Sail is using MySQL v8, I will try to setup MySQL with Takeout

We have just started MySQL with the latest release – 8.0, at port 3306 with the volumn name mysql_data . Currently you can test connect with it through HeidiSQL or phpmyAdmin for example. I tried quickly with CLI, if you want to do the same, try to install mysql-client . I am using wsl2-ubuntu so I need to install

After installation is complete, normally I will use mysql , but I use wsl2 so I need define host as 127.0.0.1 instead of the default (it’s localhost , right)

If everything goes well, then you are going to the interface of mysql-client , where we will quickly create the database for our project.

Laravel Sail and Tighten Takeout had a matching sword match

OK, let’s say two guys are active, let’s give it a mix. First, open the file docker-compose.yml inside your project, we will try to turn off mysql, redis, mailhog provided by Sail, by deleting or commenting all the parts related to them.

To connect Sail with Takeout, we need to add 1 more network in docker-compose.yml . You scroll down to networks and add 1 more item

Now our networks are like this

Now pull up, find services, inside there, find networks and add one more - takeout

Save all and rerun sail up -d . Our project must have worked well with Takeout already. Oh, then how to use the service? At this point you type takeout list

See two columns “Base Alias” and “Full Alias”? We can use 1 of those 2 to fill in our .env file. Now it is also mysql , so just edit credentials again.

Let’s try sail artisan migrate !

O seems to run

So you guys keep looking, I’m here again =]]

Share the news now

Source : Viblo