Tuesday, May 10, 2022

[Docker] grep versions in BusyBox don't support "grep -oP"

 


Ref: https://github.com/firehol/firehol/issues/325

Working with "grep -E" seems to work. Maybe this could be a workaround.

How to set user and group in Docker Compose

 

How to set user and group in Docker Compose

Ref: https://blog.giovannidemizio.eu/2021/05/24/how-to-set-user-and-group-in-docker-compose/

version: '3' services: app: image: alpine user: "${UID}:${GID}"

Docker not found when building docker image using Docker Jenkins container pipeline

 


Ref: https://localcoder.org/docker-not-found-when-building-docker-image-using-docker-jenkins-container-pipel

Solution 5:

docker run -d \
--group-add docker \
-v $(pwd)/jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker \
-p 8080:8080 -p 50000:50000 \
jenkins/jenkins:lts

Just add option --group-add docker when docker run.


Wednesday, April 13, 2022

Codeigniter with redis and Memcache Session Drivers

 Ref: https://codeigniter.com/userguide3/libraries/sessions.html


Session Drivers

As already mentioned, the Session library comes with 4 drivers, or storage engines, that you can use:

  • files
  • database
  • redis
  • memcached

By default, the Files Driver will be used when a session is initialized, because it is the most safe choice and is expected to work everywhere (virtually every environment has a file system).

However, any other driver may be selected via the $config['sess_driver'] line in your application/config/config.php file, if you chose to do so. Have it in mind though, every driver has different caveats, so be sure to get yourself familiar with them (below) before you make that choice.

In addition, you may also create and use Custom Drivers, if the ones provided by default don’t satisfy your use case.

Redis Driver

Note

Since Redis doesn’t have a locking mechanism exposed, locks for this driver are emulated by a separate value that is kept for up to 300 seconds.

Redis is a storage engine typically used for caching and popular because of its high performance, which is also probably your reason to use the ‘redis’ session driver.

The downside is that it is not as ubiquitous as relational databases and requires the phpredis PHP extension to be installed on your system, and that one doesn’t come bundled with PHP. Chances are, you’re only be using the ‘redis’ driver only if you’re already both familiar with Redis and using it for other purposes.

Just as with the ‘files’ and ‘database’ drivers, you must also configure the storage location for your sessions via the $config['sess_save_path'] setting. The format here is a bit different and complicated at the same time. It is best explained by the phpredis extension’s README file, so we’ll simply link you to it:

Warning

CodeIgniter’s Session library does NOT use the actual ‘redis’ session.save_handler. Take note only of the path format in the link above.

For the most common case however, a simple host:port pair should be sufficient:

$config['sess_driver'] = 'redis';
$config['sess_save_path'] = 'tcp://localhost:6379';

Memcached Driver

Note

Since Memcache doesn’t have a locking mechanism exposed, locks for this driver are emulated by a separate value that is kept for up to 300 seconds.

The ‘memcached’ driver is very similar to the ‘redis’ one in all of its properties, except perhaps for availability, because PHP’s Memcached extension is distributed via PECL and some Linux distrubutions make it available as an easy to install package.

Other than that, and without any intentional bias towards Redis, there’s not much different to be said about Memcached - it is also a popular product that is usually used for caching and famed for its speed.

However, it is worth noting that the only guarantee given by Memcached is that setting value X to expire after Y seconds will result in it being deleted after Y seconds have passed (but not necessarily that it won’t expire earlier than that time). This happens very rarely, but should be considered as it may result in loss of sessions.

The $config['sess_save_path'] format is fairly straightforward here, being just a host:port pair:

$config['sess_driver'] = 'memcached';
$config['sess_save_path'] = 'localhost:11211';
Bonus Tip

Multi-server configuration with an optional weight parameter as the third colon-separated (:weight) value is also supported, but we have to note that we haven’t tested if that is reliable.

If you want to experiment with this feature (on your own risk), simply separate the multiple server paths with commas:

// localhost will be given higher priority (5) here,
// compared to 192.0.2.1 with a weight of 1.
$config['sess_save_path'] = 'localhost:11211:5,192.0.2.1:11211:1';



Using memcached as a session storage with CodeIgniter

Ref: https://stackoverflow.com/questions/2617835/using-memcached-as-a-session-storage-with-codeigniter 

Having PHP put the sessions into Memcache directly, rather than through framework code is easy - it's just changing two lines in the PHP.ini:


# see http://php.net/manual/en/memcache.ini.php
session.save_handler = memcache
session.save_path="tcp://127.0.0.1:11211?persistent=1&weight=1&timeout=1&retry_interval=15"

This uses the slightly older (but still entirely supported) 'memcache' extension from PECL.

Tuesday, April 12, 2022

Jenkins delete builds older than latest 20 builds for all jobs

 Ref: https://stackoverflow.com/questions/35610053/jenkins-delete-builds-older-than-latest-20-builds-for-all-jobs

You can use the Jenkins Script Console to iterate through all jobs, get a list of the N most recent and perform some action on the others.

import jenkins.model.Jenkins
import hudson.model.Job

MAX_BUILDS = 20

for (job in Jenkins.instance.items) {
  println job.name

  def recent = job.builds.limit(MAX_BUILDS)

  for (build in job.builds) {
    if (!recent.contains(build)) {
      println "Preparing to delete: " + build
      // build.delete()
    }
  }
}

The Jenkins Script Console is a great tool for administrative maintenance like this and there's often an existing script that does something similar to what you want.

Install and use xorg-server on macOS via Homebrew

  The instructions to install and use xorg-server on macOS via Homebrew: Install Homebrew (if you haven't already): /bin/bash -c ...