Author: Oliver

  • Log rotation on docker compose

    To setup log rotation on docker compose simply add this

    logging:
      driver: "json-file"
      options:
        max-size: "1k"
        max-file: "3"

    so example docker-compose.yml file

    database:
      image: postgres:14.5-alpine
      restart: always
      ports:
        - "5432:5432"
      environment:
        POSTGRES_USER: user
      volumes:
        - ./data:/var/lib/postgresql/data:rw
      logging:
        driver: "json-file"
        options:
          max-size: "1k"
          max-file: "3"
  • Volume resize on Linode Ubuntu VPS

    I recently had to upgrade the amount of storage on an external storage volume on a linode node and thought it would help to keep a note of the command to resize the volume on ubuntu

    resize2fs /dev/sdc

    where /dev/sdc is the attached volume

  • New Symfony Project

    When I start symfony projects I like to have certain things installed to start with – heres the command I run to get things setup.

    symfony new project-name --webapp

    I always start with the webapp project just because everything is always web facing I work on

    composer require template
    composer require profiler --dev
    composer require debug
    composer require symfony/asset
    composer require maker --dev
    composer require symfony/orm-pack --with-all-dependencies
    composer require form validator
    composer require symfony/mailer
    composer require symfony/apache-pack
    composer require gedmo/doctrine-extensions --update-with-dependencies 
    composer require stof/doctrine-extensions-bundle
    composer require symfony/http-client

    after setting up the .env file for a database

    php bin/console doctrine:database:create
    php bin/console make:entity
    php bin/console make:migration
    php bin/console doctrine:migrations:migrate

    then creating users

    composer require security
    php bin/console make:user
    Edit the user entity php bin/console make:entity User
    php bin/console make:migration
    php bin/console doctrine:migrations:migrate
    php bin/console make:controller SecurityController (do not add anything to controller)
    php bin/console make:auth (1, LoginFormAuthenticator, SecurityController, yes logout)
    composer require symfony/expression-language
    composer require symfonycasts/verify-email-bundle
    php bin/console make:registration-form

  • Private Docker Registry

    I’ve recently started using a private docker registry for some docker images i’ve been using for certain projects that require special setup.

    To create the image

    docker build -t docker.example.com/directory/image:tag .

    Then I find the ID of the image using

    docker image ls

    Then when i’ve got the image ID I can tag the image

    docker tag 12345678 docker.example.com/directory/image:tag

    After that I can then push to the repository

    docker push docker.example.com/directory/image:tag
  • Handy du commands in Linux

    Transfering files between servers and making sure directory sizes match has lead me down a path of exploring the du command in detail – heres some helpful commands I’ve been using to list directory sizes. I’ve been using ubuntu but should work in debian etc too.

    To list all top level directories

    du -h -d 1

    To list all directories that match a directory name

    du -hsc Name*

    this one lists top level where directory name stars with Name and the wildcard * at the end – Name, NameOne, NameTwo etc

    Another handy feature is adding sort in reverse order with human readable sizes by piping the output into the sort command

    du -hsc Name* | sort -hr

    also watching the directory sizes whilst transferring files is helpful!

    watch -n 10 du -h -d 1

    where the -n 10 is the amount of seconds between refreshes

  • Install Docker on Ubuntu 24.04

    Just a quick snippet to remind me quickly how to install docker on Ubuntu 24.04

    curl -fsSL https://get.docker.com -o get-docker.sh
    chmod a+x get-docker.sh
    ./get-docker.sh

  • Watch without watch

    Heres a little bash script to do what watch does without having to install watch

    Start by creating watch.sh

    #!/bin/bash
    
    while true; do
        clear
        $2
        sleep $1  # adjust interval as needed
    done

    make sure to set the permissions to be able to execute

    chmod a+x watch.sh

    execute with

    ./watch.sh 2 "du -h -d 1"

    where the first parameter is interval in seconds and the second is the command wrapped in double quotes

  • Symfony User Check Interface

    Recently needed to add a check in a symfony app where only active users could login.

    I first created a user checker interface

    <?php
    
    namespace App\Security;
    
    use App\Entity\User;
    use Symfony\Component\Security\Core\Exception\LockedException;
    use Symfony\Component\Security\Core\User\UserCheckerInterface;
    use Symfony\Component\Security\Core\User\UserInterface;
    
    class UserChecker implements UserCheckerInterface
    {
        public function checkPreAuth(UserInterface $user)
        {
            if (!$user instanceof User) {
                return;
            }
    
            if (!$user->getActive()) {
                throw new LockedException();
            }
        }
    
        public function checkPostAuth(UserInterface $user)
        {
        }
    }

    then registered this as a service

    # config/packages/security.yaml
    security:
        firewalls:
            api:
                pattern: ^/
                user_checker: App\Security\UserChecker
  • CloudPanel Installation

    Install cloudpanel on a Ubuntu 24.04 LTS server

    ssh root@yourIpAddress
    
    apt update && apt -y upgrade && apt -y install curl wget sudo
    
    curl -sS https://installer.cloudpanel.io/ce/v2/install.sh -o install.sh; \
    echo "2aefee646f988877a31198e0d84ed30e2ef7a454857b606608a1f0b8eb6ec6b6 install.sh" | \
    sha256sum -c && sudo bash install.sh

    Once install access via

    https://yourIpAddress:8443

    Updated instructions can be found here:

    https://www.cloudpanel.io/docs/v2/getting-started/other/

  • Rclone Sync Command

    Sample of the rclone sync command thats setup to transfer 10 files at a time

    rclone sync --progress --multi-thread-streams=10 --transfers=10 /home/user/folder/ /mnt/ShareName/

    Another handy little flag is the check first flag which does all the checking first before starting transfers

    --check-first

    and always remember to dry run first

    --dry-run