-
Notifications
You must be signed in to change notification settings - Fork 2
/
Taskfile.yml
161 lines (156 loc) · 5.48 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
version: '3'
dotenv: ['.env']
tasks:
build:image:
prompt: "Before we build, is the version number up to date?"
desc: builds a publishable docker image
cmds:
- |
docker buildx build \
--platform=linux/amd64,linux/arm64 \
-t ghcr.io/{{.ORG_NAME}}/{{.PACKAGE_NAME}}:{{.PROJ_VER}} \
-t ghcr.io/{{.ORG_NAME}}/{{.PACKAGE_NAME}}:latest \
-f Dockerfile.prod .
vars:
PROJ_VER:
sh: "task version"
publish:image:
prompt: "Before we build, is the version number up to date?"
desc: builds a publishable docker image
cmds:
- |
docker buildx build \
--platform=linux/amd64,linux/arm64 \
--push \
-t ghcr.io/{{.ORG_NAME}}/{{.PACKAGE_NAME}}:{{.PROJ_VER}} \
-t ghcr.io/{{.ORG_NAME}}/{{.PACKAGE_NAME}}:latest \
-f Dockerfile.prod .
vars:
PROJ_VER:
sh: "task version"
publish:chart:
prompt: "Before we build, is the version number up to date?"
desc: builds and publishes the helm chart for this project
dir: charts
cmds:
- helm package {{.PACKAGE_NAME}}
- helm push {{.PACKAGE_NAME}}-{{.PROJ_VER}}*.tgz oci://ghcr.io/{{.ORG_NAME}}/charts
vars:
PROJ_VER:
sh: "task version"
publish:tag:
prompt: "Before we push, is the version number up to date?"
desc: tag a release and push to origin
summary: |
This will tag a release and push it to origin, it will also push
the tag to the remote origin.
cmds:
- git tag -a v{{.PROJ_VER}} -m "chore release v{{.PROJ_VER}}"
- git push origin v{{.PROJ_VER}}
vars:
PROJ_VER:
sh: "task version"
dev:test:
desc: runs tests inside the server container
summary: |
Uses pytest to run a set of extensive test suites for the project
cmds:
- docker compose exec api sh -c "pytest"
dev:pyshell:
desc: get a python session on the api container
cmds:
- docker compose exec api sh -c "python"
dev:psql:
desc: postgres shell on the db container
cmds:
- |
docker compose exec db sh -c \
"psql -U {{.POSTGRES_USER}} -d {{.POSTGRES_DB}}"
dev:sh:
desc: get a bash session on the api container
cmds:
- docker compose exec api sh -c "bash"
crypt:hash:
desc: generate a random cryptographic hash
cmds:
- openssl rand -hex {{.CLI_ARGS}}
db:dump:
desc: dump the database to a file
cmds:
- |
docker compose exec db sh -c \
"pg_dump -U {{.POSTGRES_USER}} {{.POSTGRES_DB}}" > {{.CLI_ARGS}}
db:init:
desc: initialise the database schema
cmds:
- docker compose exec api sh -c "poetry run initdb"
db:rev:
desc: create a database migration, pass a string as commit string
cmds:
- |
docker compose exec api sh -c \
"alembic -c /opt/$PROJ_NAME/alembic.ini revision \
--autogenerate -m {{.CLI_ARGS}}"
db:migrate:
desc: migrates models to HEAD
cmds:
- |
docker compose exec api sh -c \
"alembic -c /opt/$PROJ_NAME/alembic.ini upgrade head"
db:alembic:
desc: arbitrary alembic command in the container
cmds:
- |
docker compose exec api sh -c \
"alembic -c /opt/$PROJ_NAME/alembic.ini {{.CLI_ARGS}}"
db:alembic:heads:
desc: shows the HEAD SHA for alembic migrations
cmds:
- |
docker compose exec api sh -c \
"alembic -c /opt/$PROJ_NAME/alembic.ini heads"
db:alembic:attach:
desc: join the database container to alembic migrations
summary: |
This is useful if you have nuked your database and re-initialised
the schema and want to join back to the head alembic migrations.
We will attempt to create the alebmic_version table and populate
the version_num field with the current head value.
vars:
HEAD_SHA:
sh: "task db:alembic:heads | sed -e 's/ (head)//g'"
cmds:
- |
docker compose exec db sh -c "psql \
-U {{.POSTGRES_USER}} \
-d {{.POSTGRES_DB}} -c \" \
CREATE TABLE IF NOT EXISTS alembic_version ( version_num VARCHAR ); \
INSERT INTO alembic_version ( version_num ) VALUES ( '{{.HEAD_SHA}}' );\""
version:
cmds:
- |
docker compose exec api sh \
-c "python -c \"from {{.PROJ_NAME}} import __version__; print(__version__)\""
# version:next:
# cmds:
# - |
# git describe --tags --abbrev=0 | \
# awk -F. '{$NF = $NF + 1;} 1' | \
# sed 's/ /./g' | \
# tee .version
eject:
prompt: "Are you sure you want to eject the template?"
desc: eject the project from a template
summary: |
This process will remove any references to the Anomaly labs template,
it specifically will set the package name to your project name, fix
any references in configuration files to the labs project.
Finally it will remove references to all alembic migrations
Ejecting the template should only ever be done once!
preconditions:
# The project is not labs
- test $PROJ_NAME != "labs"
cmds:
- ls
#- rm src/labs/alembic/versions/*.py
#- FROM="labs"; TO=$PROJ_NAME; for FROM_DIR in `find . -name $FROM`; do if [ -d $FROM_DIR ]; then TARGET_DIR=`echo $FROM_DIR | sed "s/$FROM/$TO/g"`; echo $FROM_DIR ">" $TARGET_DIR; mv $FROM_DIR $TARGET_DIR; fi ; done; for SRC_FILE in `ls **/*.py **/Makefile **/*.yml **/Dockerfile **/*.dockerfile **/alembic.ini **/.env* **/README.md `; do sed -i '' "s/$FROM/$TO/g" $SRC_FILE; done