#TIL : Improve apt package manager speed by changi by changing source list mirrors

Sometimes, you ran into issues that apt update package list so slow or even can not connect to the destination server.

You can change the default list into new one near your country. Get example : if you live in ASIA, choose the Singapore or Japan mirror instead of main mirror. you just change the “archive.ubuntu.com” and “security.ubuntu.com” to “[country_code].archive.ubuntu.com” in file list /etc/apt/sources.list

Then run sudo apt update to test your new mirror :)

TIP : you can generate the new source list file based on this online tool : https://repogen.simplylinux.ch/generate.php

#TIL : Improve apt package manager speed by changing source list mirrors

Sometimes, you ran into issues that apt update package list so slow or even can not connect to the destination server.

You can change the default list into new one near your country. Get example : if you live in ASIA, choose the Singapore or Japan mirror instead of main mirror. you just change the “archive.ubuntu.com” and “security.ubuntu.com” to “[country_code].archive.ubuntu.com” in file list /etc/apt/sources.list

Then run sudo apt update to test your new mirror :)

TIP : you can generate the new source list file based on this online tool : https://repogen.simplylinux.ch/generate.php

#TIL : Ansible running host pattern

Ansible supports pattern to select and filter running hosts from all hosts. Here is some common pattern

  • * : wildcard, standalone mean all
  • group1,group2 : run hosts belong to group1 or group2
  • *.web : run hosts belongs to group matches pattern. Ex: backend.web, frontend.web
  • all:!abc : run all hosts exclude hosts belongs to group abc

Infrastructure by code ;)

#TIL : Using netcat to wait a TCP service

When doing a CI/CD testing, you would need to connect a external service (RDBMS, HTTP server or generic TCP server service). So you need waiting the service before running your test app.

One way to do right waiting instead of sleep for a specified time is using netcat tool

1
$ while ! echo -e '\x04' | nc [service_host] [service_port]; do sleep 1; done;

Examples

  • MySQL service on port 3306
1
2
$ while ! echo -e '\x04' | nc 127.0.0.1 3306; do sleep 1; done;
$ ./run_test.sh

Explanation :

echo -e '\x04' will send an EOT (End Of Transmission) to the TCP every second to check if it’s ready !

#TIL : Free sandbox server for development

We can use Heroku as a forever-free sandbox solution for testing or hosting micro service. Adding a credit card to have 1000 free computing hours.

Heroku will make a service down if no received request come. We can use a cronjob-like service to check service health and keep it live !!! ;)

Cronjob check health SASS : pingdom, statuscake, port-monitor, uptimerobot

Btw, I don’t recommend you keep service live but no use, it makes Heroku infrastructure heavy and THAT’S NOT FAIR for them !

#TIL : Checking forced push conflicts on source code in auto testing

Using automated CI solution likes Travis, Jenkins, DroneCI, … is good solution to ensure quality of software and no breaks in deployment.

Sometimes, developers force push conflicts part to production branch of source code. If the CI tests only backend (python, ruby, php, go, ..) and forget about frontend code, then your application will be exploded !

So checking the conflicts code is required step before testing backend and deployment.

I used grep tool to checking conflicts code in current dir

Create a file name conflict_detector.sh in root dir of source code

1
2
3
#!/bin/bash

grep -rli --exclude=conflict_detector.sh --exclude-dir={.git,vendor,venv,node_modules} "<<<<<<< HEAD" .

Then mini tool print list of conflicted files. If exit code not equal 0 then testing will be failed !