Enable sudo without password in Ubuntu/Debian

You probably know that in Ubuntu/Debian, you should not run as the root user, but should use the sudo command instead to run commands that require root privileges. However, it can also be inconvenient to have to enter your password every time that you use sudo. Here’s a quick fix that removes the requirement to enter you password for sudo. Open the /etc/sudoers file (as root, of course!) by running: 1 sudo visudo You should Read more

Swarm secrets made easy

A recent Docker update came with a small but important change for service secrets and configs, that enables a much easier way to manage and update them when deploying Swarm stacks. TL;DR This post describes an automated way to create and update secrets or configs, when they are managed through a Composefile, and are deployed as a stack, along with the services using them. To avoid repeating “secrets and configs” all over the post, I’m Read more

Setup Highly Available applications with Docker Swarm and Gluster

# docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world1b930d010525: Pull completeDigest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50eStatus: Downloaded newer image for hello-world:latestHello from Docker!This message shows that your installation appears to be working correctly. 2. Initialize Docker swarm from the swarm-manager We’ll use the swarm-manager’s private IP as the “advertised address”. swarm-manager:~# docker swarm init --advertise-addr initialized: current node (sz42o1yjz08t3x98aj82z33pe) is now a manager.To add a worker to this swarm, run the following command:docker swarm join Read more

Generate /etc/hosts with Ansible

inventory file [servers] master ansible_ssh_host= node1 ansible_ssh_host= node2 ansible_ssh_host= node3 ansible_ssh_host= templates/etc/hosts.j2 {% for item in ansible_play_batch %} {{ hostvars[item].ansible_ssh_host }} {{ item }}.example.com {% endfor %} playbook task - hosts: servers gather_facts: False tasks: - name: update /etc/hosts file become: true blockinfile: dest: /etc/hosts content: "{{ lookup('template', 'templates/etc/hosts.j2') }}" state: present

Aborting ansible playbook if a host is unreachable

I was about to post a question, when I saw this one. The answer Duncan suggested does not work, atleast in my case. the host is unreachable. All my playbooks specify a max_fail_percentage of 0. But ansible will happily execute all the tasks on the hosts that it is able to reach and perform the action. What I really wanted was if any of the host is unreachable, don’t do any of the tasks. What Read more

Стиль архитектуры, управляемой событиями

Управляемая событиями архитектура включает поставщики событий, которые создают потоки событий, и потребители событий, которые прослушивают эти события. События доставляются практически мгновенно, что позволяет потребителям немедленно реагировать на происходящие события. Поставщики не связаны с потребителями — ни один поставщик не знает, кто прослушивает его события. Потребители также не зависят друг от друга, и каждый из них получает все события. Это важное отличие от шаблона конкурирующих клиентов, в котором пользователи извлекают сообщения из очереди, и каждое сообщение Read more

How Laravel’s SerializesModels Trait Could Save Your Bacon

When a Laravel Job is dispatched that takes an Eloquent Model as an argument in the constructor, you can use the SerializesModels trait which will only serialize the model identifier. When the job is actually handled, the queue system will automatically re-retrieve the full model instance from the database (docs). Taylor also announced that in Laravel 5.3, you will also be able to do this with Eloquent Collections! (link) So why is it necessary or Read more

Event Driven Systems

Событие-это то, на что наше приложение должно реагировать. Изменение адреса клиента, покупка или расчет счета клиента-все это события. Эти события могут исходить из внешнего мира или инициироваться внутри, например, запланированное задание, которое выполняется каждый раз. И суть здесь в том, чтобы захватить эти события и затем обработать их, чтобы вызвать изменения в приложении в дополнение к хранению их в качестве журнала аудита. The workflow Рабочий процесс: На рисунке выше показаны три компонента: клиент, заказ и Read more

Data Transfer Object (DTO) in Laravel with PHP7.4 typed properties

Data Transfer Objects help in «structuring» the data coming from different types of requests ( Http request, Webhook request etc. ) into single form which we can use in various parts of our application. With DTOs, we have confidence that we will not get unexpected data in our application logic. Example class CheckoutData extends DataTransferObject { public int $checkout_id; public Carbon $completed_at; public static function fromRequest(Request $request){ ... } public static function fromWebhook(array $params) { Read more

PHP basic auth file_get_contents()

You will need to add a stream context to get the extra data in your request. Try something like the following untested code. It’s based on one of the examples on the PHP documentation for file_get_contents(): $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("http://example.com/file", false, $context );

Любишь мемасики?

Подпишись на мой телеграм-канал!