Skip to content

Commit 6a4a50e

Browse files
Add project/taskfiles/docker.yml.j2 template
1 parent 460cac2 commit 6a4a50e

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

project/taskfiles/docker.yml.j2

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
version: "3.0"
2+
3+
set: ['e', 'u', 'pipefail']
4+
shopt: ['globstar']
5+
6+
env:
7+
BUILD: "{{"{{"}}".TLD"{{"}}"}}/bin/build.sh"
8+
COMPOSE_FILE: "{{"{{"}}".TLD"{{"}}"}}/docker-compose.yml"
9+
DOCKERFILE: "{{"{{"}}".TLD"{{"}}"}}/Dockerfile"
10+
PLATFORM:
11+
sh: "echo ${PLATFORM:-linux/arm64/v8}"
12+
REGISTRY:
13+
sh: "echo ${REGISTRY:-ghcr.io}"
14+
USER_NAME:
15+
sh: "echo ${USER_NAME:-{{ repository_namespace }}}"
16+
SERVICE: "{{ python_package_distribution_name }}"
17+
VERSION:
18+
sh: "echo ${VERSION:-latest}"
19+
20+
tasks:
21+
net:
22+
desc: "Create docker network"
23+
cmds:
24+
- |
25+
docker network create \
26+
--driver bridge \
27+
app-tier
28+
status:
29+
- |
30+
docker network ls --format \{\{.Name\}\} \
31+
| grep -q '^app-tier$'
32+
33+
vol:
34+
desc: "Create docker volume"
35+
cmds:
36+
- |
37+
docker volume create \
38+
--driver local \
39+
{{"{{"}}".SERVICE"{{"}}"}}-vol
40+
status:
41+
- |
42+
docker volume ls --format \{\{.Name\}\} \
43+
| grep -q '^{{"{{"}}".SERVICE"{{"}}"}}-vol$'
44+
45+
build:
46+
desc: "Build the docker image"
47+
summary: |
48+
Build the docker image with the specified dockerfile.
49+
50+
The default dockerfile is `Dockerfile`.
51+
52+
USAGE
53+
task docker:build
54+
cmds:
55+
- |
56+
docker build \
57+
-f {{"{{"}}".DOCKERFILE"{{"}}"}}" \
58+
-t {{"{{"}}".SERVICE"{{"}}"}}" \
59+
--platform {{"{{"}}".ARCH"{{"}}"}}" \
60+
.
61+
62+
login:
63+
desc: "Login to the container registry"
64+
cmds:
65+
- |
66+
echo "{{"{{"}}".REGISTRY_PASS"{{"}}"}}" | docker login \
67+
-u {{"{{"}}".USER_NAME"{{"}}"}}" \
68+
--password-stdin {{"{{"}}".REGISTRY_URL"{{"}}"}}"
69+
run: once
70+
silent: true
71+
status:
72+
- |
73+
jq -e '.auths | keys[] | select(contains("{{"{{"}}".REGISTRY_URL"{{"}}"}}"))' ~/.docker/config.json
74+
75+
push:
76+
desc: "Push the docker image to the registry"
77+
deps:
78+
- login
79+
- build
80+
cmds:
81+
- docker push {{"{{"}}".REGISTRY_URL"{{"}}"}}/{{"{{"}}".USER_NAME"{{"}}"}}/{{"{{"}}".SERVICE"{{"}}"}}"
82+
83+
up:
84+
desc: "Start the project with docker compose"
85+
cmds:
86+
- |
87+
docker compose -f {{"{{"}}".COMPOSE_FILE"{{"}}"}}" up -d \
88+
--build \
89+
--remove-orphans
90+
91+
exec:
92+
desc: "Shell into a running container"
93+
cmds:
94+
- docker exec -it {{"{{"}}".SERVICE"{{"}}"}}" sh
95+
96+
logs:
97+
desc: "Follow the logs of a running container"
98+
cmds:
99+
- docker compose logs -tf {{"{{"}}".SERVICE"{{"}}"}}"
100+
101+
stop:
102+
desc: "Stop the project with docker compose"
103+
cmds:
104+
- docker compose -f {{"{{"}}".COMPOSE_FILE"{{"}}"}}" stop
105+
106+
down:
107+
desc: "Stop and remove containers, networks, and volumes with docker compose"
108+
cmds:
109+
- |
110+
docker compose -f {{"{{"}}".COMPOSE_FILE"{{"}}"}}" down \
111+
--volumes
112+
113+
prune:
114+
desc: "Prune docker"
115+
cmds:
116+
- docker system prune --all --force
117+
- docker builder prune --all --force

0 commit comments

Comments
 (0)