Skip to content

Commit

Permalink
vault backup: 2025-01-30 22:34:04
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiaagarwal committed Jan 31, 2025
1 parent b2644a8 commit 79e9d9d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions content/programming/tools/justfile/tagged-docker-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ services:
context: ./backend
```

We can instead do `TAG=my-branch docker compose build` ! Still, not optimal. It involves typing _at least_ 4 extra characters, and if you're anything like me, you're going to do it more often than not. We _could_ export it globally, but I personally tend to avoid setting env variables.
We can instead do `TAG=my-branch docker compose build` ! Still, not optimal. It involves typing _at least_ 4 extra characters, and if you're anything like me, you're going to do it less often than not. We _could_ export it globally, but I personally tend to avoid setting env variables.

Instead, we can use a justfile to calculate the tag dynamically and set the env variable.

```just
export TAG=`(git rev-parse --abbrev-ref HEAD`
Expand All @@ -42,11 +44,13 @@ just up *FLAGS:
docker compose up {{FLAGS}}
```
Pretty cool! But this could create docker tags that aren't syntactically valid, like if the branch is called `my/feature-branch`. Instead, we can normalize it, following exactly what gitlab does to generate [`CI_COMMIT_REF_SLUG`](https://gitlab.com/gitlab-org/gitlab-runner/-/blame/af6932352f8ed15d1a6d9c786399607bc6be2c2d/Makefile.build.mk?page=1#L25).
Pretty cool! But this could create docker tags that aren't syntactically valid, like if the branch is called `my/FEATURE-branch`. Instead, we can normalize it, following exactly what gitlab does to generate [`CI_COMMIT_REF_SLUG`](https://gitlab.com/gitlab-org/gitlab-runner/-/blame/af6932352f8ed15d1a6d9c786399607bc6be2c2d/Makefile.build.mk?page=1#L25).

```just
export TAG=`(git rev-parse --abbrev-ref HEAD) | tr '[:upper:]' '[:lower:]) | cut -c -63 | sed -E 's/[^a-z0-9-]+/-/g' | sed -E 's/^-*([a-z0-9-]+[a-z0-9])-*$$/\1/g')`

just up *FLAGS:
docker compose up {{FLAGS}}
```
This branch would get normalized to `my-feature-branch`, all lowercase.

0 comments on commit 79e9d9d

Please sign in to comment.