Categories
Uncategorized

View from my office

Categories
Uncategorized

Today in WTF-UX

“Read on”

Just kidding.

Categories
Uncategorized

How is it?

2020 and I only just now listened to http://pjharvey.net/music/stories-from-the-city-stories-from-the-sea/ in full.

Categories
Uncategorized

Make it work

I <3 the simple “legend” used here to indicate which bands are supporting each date on this tour. There’s a minor coding mistake- do you see it?-, but the technique is simple and it works so well.

Categories
Uncategorized

Context matters

Categories
Uncategorized

Tods Law

Each thing you do spawns new things to be done.

my Theorem of doing stuff

Categories
Uncategorized

Several People Are Typing

Dad, what was work like before Slack?

Formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.

Dad! Stop it. Seriously what was it like?

Less hurried. More thoughtful.

That sounds nice. Can we go back to that?

No. We only go forward.

Categories
Uncategorized unix

How I use ChromeOS’s linux containers

When you enable “Linux” on ChromeOS, a default Virtual Machine is created (and a default linux container). VM’s are the layer above containers- each VM can house multiple containers. The default VM is named “termina” and once it exists, you can interact with it from crosh (The Chromium OS Shell) using the vmc command. The default container is named “penguin”.

Note, for my purposes, I create a second VM named wpvm and then create containers within that VM. This makes it fast and easy to spin up Debian environments (I’ll try to cover other container types in a later post) for whatever your needs may be. The --enable-gpu is optional. YMMV.

First, open a crosh window (ctrl-alt-t). Then, to create and start a new VM named “wpvm”:

crosh> vmc start --enable-gpu wpvm

After the above VM is created, you’ll end up at a shell prompt within the VM. A potential point of confusion, the prompt below shows “(termina)” when we’re actually in a VM named “wpvm”. The “(termina)” here refers to the VM image ChromeOS uses for all VM’s. Keep calm and keyboard on.

(termina) chronos@localhost

From here, exit the VM using ctrl-d

Now let’s create a container within the new “wpvm” VM. We’ll use Google/ChromeOS’s standard Crostini container, “stretch”:

crosh> vmc container wpvm stretch

If everything worked, you’ll find yourself signed into the new Debian Stretch container with a bash prompt:

mark.drovdahl@stretch:~$

If you want to verify the VM and the container were created and running, you can open a new crosh window (ctrl-alt-t), list the available VM’s, shell into the “wpvm” VM using the vsh command (reminder, this puts you into the VM, not the container) and then check the status of any running containers with:

crosh> vmc list
 wpvm
 termina
 Total Size (bytes): xxxxxxxxx
crosh> vsh wpvm
 (termina) chronos@localhost ~ $ lxc list
 +---------+---------+-----------------------+------+------------+-----------+
 |  NAME   |  STATE  |         IPV4          | IPV6 |    TYPE    | SNAPSHOTS |
 +---------+---------+-----------------------+------+------------+-----------+
 | stretch | RUNNING | 100.115.92.233 (eth0) |      | PERSISTENT | 0         |
 +---------+---------+-----------------------+------+------------+-----------+

To shell into a running container (obviously, the associated VM must also be running):

crosh> vsh wpvm stretch
mark.drovdahl@stretch:~$

References:

https://chromium.googlesource.com/chromiumos/docs/+/master/containers_and_vms.md

Categories
Uncategorized

’93 Landcruiser still rocks

Categories
Uncategorized

WP Dev with Docker

I got stuck for a bit today on how to configure a PHP PDO connection in a Docker based WordPress dev env. Here’s the function…

/**
 * Get the database connection
 * @return \PDO database connection instance
 */
public function get_connection() {
    $dbname = \TMSC\tmsc_sync()::$tms_db_name;
    $username = \TMSC\tmsc_sync()::$tms_db_user;
    $password = \TMSC\tmsc_sync()::$tms_db_password;
    // Build the DSN string
    $host = \TMSC\tmsc_sync()::$tms_db_host;
    $port = '3306';
    if ( strpos( $host, ':' ) ) {
        list( $host, $port ) = explode( ':', $host );
    }

    $dsn = "mysql:host={$host};port={$port};dbname={$dbname}";

    $connection = new \PDO( $dsn, $username, $password, array(
        \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
    ) );

    // Since MySQL supports it, don't automatically quote parameters to allow control over data types.
    // This comes in useful for automatically manipulating the LIMIT clause.
    $connection->setAttribute( \PDO::ATTR_EMULATE_PREPARES, false );

    // Uncomment to enable connection debugging.
    $connection->setAttribute( \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION );

    $this->set_mysql_global_defaults( $connection );
    return $connection;
}

When this function connects to a Remote AWS/RDS database, we configure it with a FQD for the $host variable. But, when running the same function locally, within our Docker setup, we must use the docker container name “jetpack_mysql” (as defined in the docker-compose.yml file) and not “127.0.0.1” or “localhost”.