How to display GitHub Actions status badge image in your repository’s

GitHub actions is one of the latest additions in the sphere of tools, available for CI/CD. It’s quite powerful and integrates directly with the GitHub repository where it’s ran.

One of the benefits of having a CI system, is the ability to quickly understand if your latest build is passing or not. The so called “status badges” help with this, especially for Open Source projects.

Showing such a status badge image in your own repository is quite easy.

You just need to collect 3 pieces of information:

  • Your GitHub organization or username
  • Your GitHub repo’s name (the one visible in the URL)
  • The GitHub Actions workflow name (usually on the first line of /.github/workflows/main.xml

Based on these 3 things, you can construct a URL to an image that’s automatically generated by GitHub actions and represents the latest build status:<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_FILE_PATH>/badge.svg

To use it inside a repository’s

![Build passing](<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_FILE_PATH>/badge.svg)

Terraform error “InvalidParameterException: The target group with targetGroupArn arn:aws:xxx does not have an associated load balancer”. How to solve it?

Recently, while trying to create a Terraform stack for the infrastructure of an experimental app, I encountered a cryptic error:

Error: Error applying plan:

1 error(s) occurred:

* module.ecs.aws_ecs_service.current_task: 1 error(s) occurred:

* aws_ecs_service.current_task: InvalidParameterException: The target group with targetGroupArn arn:aws:elasticloadbalancing:eu-west-1:1111111111:targetgroup/xxx/xxxxxxxxxxxxxxx does not have an associated load balancer.
        status code: 400, request id: 5e027278-85ba-asdf-bd5b-cd67eda86a92 "test-apis"

After some research, I discovered that the error appears due to a race condition. Attempting to create an “aws_alb_target_group” Terraform resource without the underlying ALB (load balancer) being ready, triggers the error.

The solution (workaround) was simple, just enforce the order of resource creation using Terraform’s “depends_on” attribute.

For example:

resource "aws_lb" "this" {
  // ALB attributes here
resource "aws_alb_target_group" "frontend" {
  name = "frontend"
  port = 80
  protocol = "HTTP"
  vpc_id = xxxxx
  depends_on = [
    // Important bit is here

Happy Terraforming!

Fixing a failing Composer installation: Unable to write to: /home/$USER/.composer

Recently, I started a project which uses Composer as a dependency management system. In the spirit of reducing the dependencies on the host system, I wanted to bundle even Composer itself inside the project’s source code. This is possible by downloading and including a composer.phar at the root of the project. However, failing Composer installation is not something new to developers, especially if you haven’t used it before.

What is composer.phar?

It’s basically a PHP script that contains the core functionality of Composer – namely, the ability to read a composer.json/composer.lock file (a JSON definition of the project’s dependencies) and manage those dependencies – download them, resolve them to the best possible version, lock them to a version, etc.

How to download composer.phar?

There are basically two main ways to download the composer.phar:

  • Programmatically (easier)
  • Manual (safer)

For my most recent project, I opted for the programmatical approach, which is documented on the Composer website.

Using that approach, you pretty much have to run a single command:

wget -O - -q | php -- --quiet
Note: The command above is up to date as of writing this but may change in the future. For the up to date version, go through the website link above.
Troubleshooting: Composer installation error on Ubuntu – “Failing Composer installation: Unable to write to: /home/$USER/.composer”

Occasionally, I stumble upon this error when I try to include Composer in a real life project. The error is kind of ambiguous, but the reason behind it is pretty clear: your current user doesn’t have ownership over the /home/$USER/.composer folder OR some of the files inside.

Solution: Change the ownership of the .composer folder to be owned by your user ($USER is a variable that always refers to the current user in UNIX systems):

sudo chown $USER -R /home/$USER/.composer

Let me know in the comments if that worked for you. If you are still struggling with Composer issues, I am available for paid consulting.

How to uninstall Swarmpit – the Docker Swarm orchestration tool

Recently, I’ve been looking for a good Docker container orchestration and host machine management tool and I’ve come across Swarmpit.

It’s a wonderful tool and I recomment it to anyone who is looking for a web based interface to make it easier to launch, scale and destroy Docker Swarm stacks on host machines, without having SSH access to the machine itself (e.g. while traveling).

However, what’s missing online is information about how to uninstall Swarmpit, once you no longer need it. Here are the steps to do it:

  1. SSH into the machine where Swarmpit is running
  2. “docker stack ls” and find the stack that represents Swarmpit. It’s usually called simply “swarmpit“. Take note of this name.
  3. Destroy the Swarmpit stack using “docker stack rm swarmpit“. Replace “swarmpit” with the name of the stack from the previous step.

While you are here, if you are struggling with integrating Docker or Docker Swarm within your project, feel free to write me – I may be able to help (for a fee).

Installing Docker Toolbox on Windows (Video)

Docker is a very powerful and lightweight virtualization engine that allows you to run any linux machine inside (almost) any host environment. The following tutorial will teach you how to install the Docker host inside Windows and how to run a few of the most populate commands to get you started in the Docker world.

What you’ll need to get Docker running on Windows:

  • A Windows computer
  • Docker Toolbox – a package of all the software needed to have a fully functional environment to run Docker containers (available as Mac or Windows installation package)

How to Insert a MD5 Password (or the Result of Any Other MySQL Function) Into a Field with “Navicat for MySQL”

MySQL already supports MD5() in terms of built-in functions. This is helpful whenever you want to insert something into a cell using the INSERT INTO users (id,username,password_hash) VALUES (1001,john_page,MD5(‘password_here’)) query.

But what happens when you already have a database and you want to change one single cell without fiddling manually with raw SQL queries, especially when you have Navicat SQL GUI software available? Luckily, Navicat has the so-called “Raw Mode” when viewing a table’s rows which allows us to insert data using expressions/functions which will be evaluated and converted to a string as soon as you press ENTER.

Here are the steps to follow if you want to convert a raw string into its MD5 representation and insert that representation as a cell within a MySQL cell:

  1. Open your desired table with Navicat (e.g. “users”)
  2. Choose “View->Raw Mode” from the top menu
  3. In your password field, type the expression, whose result you want inserted in that field, e.g. MD5(‘newpassword’)
  4. Hit “Enter” and “Ctrl+S” to apply the changes. Optionally disable “Raw mode” from the menu if you need to go back to the regular mode.

Enjoy the result of the MD5, without using complex raw SQL queries that are prone to typos.