Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 79e9d9d

Browse files
committed
vault backup: 2025-01-30 22:34:04
1 parent b2644a8 commit 79e9d9d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

content/programming/tools/justfile/tagged-docker-images.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ services:
3333
context: ./backend
3434
```
3535

36-
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.
36+
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.
37+
38+
Instead, we can use a justfile to calculate the tag dynamically and set the env variable.
3739

3840
```just
3941
export TAG=`(git rev-parse --abbrev-ref HEAD`
@@ -42,11 +44,13 @@ just up *FLAGS:
4244
docker compose up {{FLAGS}}
4345
```
4446
45-
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).
47+
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).
4648

4749
```just
4850
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')`
4951

5052
just up *FLAGS:
5153
docker compose up {{FLAGS}}
5254
```
55+
56+
This branch would get normalized to `my-feature-branch`, all lowercase.

0 commit comments

Comments
 (0)