Pragmatism in the real world

Changing port maps in Docker Compose

When using Docker Compose, I often map the ports to local ones in the compose.yaml like this: services: web: build: context: ./docker/web ports: – "8080:80" Adding to the port map If port 8080 is in use already on a developer's machine, then we can add a new mapping using compose.override.yaml services: web: build: context: ./docker/web ports: – "8081:80" The compose.override.yaml file is merged with the compose.yaml file and the effective configuration is now: services: web:… continue reading.

Release process checklist

I recently released a new version of rst2pdf. We don't do this frequently and it would be very easy to get it wrong. As a result, we have a RELEASE_PROCESS.rst document in our repo that provides a step-by-step list of what to do. I can't emphasise enough how useful such a document is and every project should have one and I've used them with client projects too. In general the following items need to be… continue reading.

Stash unstaged changes in git

I wanted to stash just the unstaged changes in my git repo. There's a git stash –staged which will stash the staged files, but I didn't see an equivalent to stash just the unstaged ones. Obviously, this is a common problem so a minute or two of googling will find the Git stash uncached: how to put away all unstaged changes? Stack Overflow question. Turns out that you have to remember the the staging area… continue reading.

Using GitHub Actions to add Go binaries to a Release

Shortly after building a script to create binaries for Rodeo, my command line Flickr uploader, I realised that I could use a Github Actions workflow to run it and attach the created binaries to the Release page once I had created it. This is what I did. Trigger on release A GitHub Actions workflow is a YAML file and each workflow has to be triggered. For Continuous Integration, it's common to trigger when new PR… continue reading.

Building Go binaries for different platforms

One nice thing about Go is that it can cross-compile which allows me to use my Mac to build binaries for different operating systems. This is increibly useful for providing binaries for Rodeo, my command line Flickr uploader. To do this we set the GOOS and GOARCH environment variables before calling go build. For example to build for x64 on Linux, I do: version=`git describe –tags HEAD` env GOOS=linux GOARCH=amd64 go build \ -ldflags "-X… continue reading.

Setting the version of a Go application when building

When I was building Rodeo, my command line Flickr uploader, one thing I wanted to do was set the version number that you see when you type rodeo -v to the correct version when I build the application for release. The basic process I wanted was: Tag git repository with new version number and push Build rodeo with that version without editing any files Upload binary I've emphasised the important part. I don't want to… continue reading.

Only display body on error with curl

Sometimes, I only want to display the response from a curl request if it errors – i.e. the status code is 400 or higher. With curl 7.76 or greater this is done using the –fail-with-body parameter: curl -s –fail-with-body \ https://api.example.com/foo/${id} \ -H "Content-Type: application/json" \ –data "@data.json" On success, the return code ($?) is 0 and on failure the body is output with the return code set to 22. Prior to 7.76, you can… continue reading.

Quick script to (re)create my python virtualenv

When working on rst2pdf, I use pyenv as I've written about before. Recently, I've found myself needing to recreate virtualenvs for various Python versions and then recreate them to easily reset the list of packages installed into them via pip. To my my life easier, I created a script that I can run from the command line: $ newenv rst2pdf-dev-py3.9 3.9.5 This creates a new virtualenv called rst2pdf-dev-py3.9 from Python version 3.9.5, upgrade pip and… continue reading.

A few Git tips

I don't do that much that's clever with git, but I've found the following helpful. Automatically prune When you do a git fetch or git pull, you can ask it to remove remote tracking branches for a branch that has been removed on the remote by using the –prune flag. This can be automated globally with: git config –global fetch.prune true and if you only want it for a specific repository, you can use: git… continue reading.

Using MailHog via Docker for testing email

I recently needed to modify the emails that a client project sends out. It was set up to send via SMTP and so the easiest way to do this for me was to add a local MailHog instance and point the application at it. Manually running via Docker The quickest and easiest way to do this is via Docker. Manually, we can do: $ docker run -p 8025:8025 -p 1025:1025 mailhog/mailhog This will run MailHog… continue reading.