-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.toml
174 lines (149 loc) · 3.88 KB
/
Makefile.toml
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
162
163
164
165
166
167
168
169
170
171
172
173
174
[config]
default_to_workspace = false
min_version = "0.36.9"
[tasks.format-rust]
args = ["fmt"]
command = "cargo"
dependencies = ["install-rustfmt"]
[tasks.lint-rust-format]
args = ["fmt", "--all", "--", "--check"]
command = "cargo"
dependencies = ["install-rustfmt"]
[tasks.lint-rust]
args = [
"clippy",
"--workspace",
"--locked",
"--all-targets",
"--",
"-D",
"clippy::all",
"-D",
"warnings",
]
command = "cargo"
dependencies = ["install-clippy"]
[tasks.lint-toml]
args = ["lint"]
command = "taplo"
dependencies = ["install-taplo-cli"]
[tasks.format-toml]
args = ["fmt"]
command = "taplo"
dependencies = ["install-taplo-cli"]
[tasks.lint]
dependencies = ["lint-rust-format", "lint-rust", "lint-toml"]
[tasks.format]
dependencies = ["format-rust", "format-toml"]
[tasks.backend-build]
args = ["build"]
command = "cargo"
cwd = "./backend/"
[tasks.backend-start]
dependencies = ["backend-build"]
args = ["run"]
command = "cargo"
cwd = "./backend/"
[tasks.backend-dev]
args = ["watch", "-x", "run"]
command = "cargo"
cwd = "./backend/"
[tasks.client-build]
args = ["build"]
command = "trunk"
cwd = "./client/"
[tasks.client-start]
dependencies = ["client-build"]
args = ["serve"]
command = "trunk"
cwd = "./client/"
[tasks.database-build]
description = "Build database dockerimage"
cwd = "./database/"
script = '''
echo "👷 Building database image"
echo "🔎 Checking if \`Docker\` is installed..."
if ! docker --version; then
echo "\n❌ Docker could not be found\n"
echo "Exiting task"
exit 1
fi
docker build -t ${DB_DOCKER_IMAGE} .
'''
[tasks.database-start]
description = "Run database"
dependencies = ["database-build"]
cwd = "./database/"
script = '''
echo "🏎️ Running database container"
if ! docker ps -a | grep -q ${DB_CONTAINER}; then
docker run --restart=always -d \
--env-file=.env \
-v ${DATA_DIRECTORY}:/var/lib/mysql \
--name ${DB_CONTAINER} \
${DB_DOCKER_IMAGE}
else
docker start ${DB_CONTAINER}
fi
'''
[tasks.database-query]
description = "Query database container. Takes a query as argument"
script = '''
echo "❓ Query database container"
if docker ps | grep -q ${DB_CONTAINER}; then
DB_USERNAME=$(grep 'MYSQL_ADMIN_USERNAME=' ${DB_HOME}/.env | cut -d'=' -f2)
DB_PASSWORD=$(grep 'MYSQL_ADMIN_PASSWORD=' ${DB_HOME}/.env | cut -d'=' -f2)
if [ ! ${DB_USERNAME} ] || [ ! ${DB_PASSWORD} ]; then
echo "❗️ DB_USERNAME and DB_PASSWORD not defined in database .env file"
exit 1
fi
QUERY=$1
docker exec -i ${DB_CONTAINER} mysql -u${DB_USERNAME} -p${DB_PASSWORD} ${DB_NAME} -e "${QUERY}"
else
echo "❗️ No database found"
fi
'''
[tasks.database-stop]
description = "Stop database container"
cwd = "./database/"
command = "docker"
args = ["stop", "${DB_CONTAINER}"]
[tasks.database-clean]
description = "Clean database"
script = '''
echo "🏎️ Cleaning database container"
while true; do
read -p "Want to delete the database volume? Enter 'y' or 'n': " ANSWER
if [ "${ANSWER}" == "y" ]; then
echo "📀 Deleting database"
rm -rf ${DATA_DIRECTORY}
break
elif [ "${ANSWER}" == "n" ]; then
break
fi
done
if docker ps -a | grep -q ${DB_CONTAINER}; then
echo "🧹 cleaning database container"
if docker ps | grep -q ${DB_CONTAINER}; then
docker stop ${DB_CONTAINER} > /dev/null && docker rm ${DB_CONTAINER}
else
docker rm ${DB_CONTAINER}
fi
fi
if docker image list | grep -q ${DB_DOCKER_IMAGE}; then
echo "🧹 cleaning database image"
docker image rm ${DB_DOCKER_IMAGE}
fi
'''
[tasks.install-clippy]
install_crate = { rustup_component_name = "clippy" }
[tasks.install-rustfmt]
install_crate = { rustup_component_name = "rustfmt" }
[tasks.install-taplo-cli]
install_crate = { crate_name = "taplo-cli", binary = "taplo", test_arg = "--help" }
[env]
DB_NAME = "la_charcuterie_en_ligne"
DB_DOCKER_IMAGE = "db-image-${DB_NAME}"
DB_CONTAINER = "db-${DB_NAME}"
DATA_DIRECTORY = "${PWD}/database/data"
DB_HOME = "./database"