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

Commit b2644a8

Browse files
committed
vault backup: 2025-01-30 22:30:06
1 parent 73d66f0 commit b2644a8

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

content/programming/languages/python/sqlalchemy/pydantic.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ class PydanticModelType[T: BaseModel](TypeDecorator[T]):
1616
cache_ok = True
1717
impl = JSON()
1818

19-
def __init__(self, pydantic_type: type[T]) -> None:
20-
self.pydantic_type = pydantic_type
19+
def __init__(self) -> None:
2120
super().__init__()
2221

2322
@override
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Using `just` to properly tag docker compose images
3+
tags:
4+
- observations
5+
---
6+
You're developing a dockerized application, so you have a docker compose stack.
7+
8+
```yaml
9+
services:
10+
frontend:
11+
image: 'frontend:develop'
12+
build:
13+
context: ./frontend
14+
backend:
15+
image: 'backend:develop'
16+
build:
17+
context: ./backend
18+
```
19+
20+
This is pretty neaat, but it does mean that all your images are built with the tag `develop`. Let's say you switch to another branch, and you want to test the application there. You are _forced_ to rebuild, and then you lose your old image entirely.
21+
22+
A common workaround is to define an environment variable `TAG`, and then rewrite the docker compose to be:
23+
24+
```yaml
25+
services:
26+
frontend:
27+
image: 'frontend:${TAG:-develop}$'
28+
build:
29+
context: ./frontend
30+
backend:
31+
image: 'backend:${TAG:-develop}$'
32+
build:
33+
context: ./backend
34+
```
35+
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.
37+
38+
```just
39+
export TAG=`(git rev-parse --abbrev-ref HEAD`
40+
41+
just up *FLAGS:
42+
docker compose up {{FLAGS}}
43+
```
44+
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).
46+
47+
```just
48+
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')`
49+
50+
just up *FLAGS:
51+
docker compose up {{FLAGS}}
52+
```

0 commit comments

Comments
 (0)