-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
218 lines (208 loc) · 9.17 KB
/
Taskfile.yml
File metadata and controls
218 lines (208 loc) · 9.17 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
version: 3
# Taskfile principal - Tâches globales et inclusions
# Charge automatiquement les variables depuis le fichier .env s'il existe
dotenv: [ '.env', '.env.example' ]
includes:
docker: ./taskfiles/docker/Taskfile.yml
utils: ./taskfiles/utils/Taskfile.yml
env: ./taskfiles/env/Taskfile.yml
nodejs: ./taskfiles/nodejs/Taskfile.yml
download: ./taskfiles/download/Taskfile.yml
vars:
# Variables avec valeurs par défaut depuis .env ou valeurs de fallback
PROJECT_NAME: '{{.PROJECT_NAME | default "docker"}}'
ENVIRONMENT: '{{.ENVIRONMENT | default "development"}}'
NODE_VERSION: '{{.NODE_VERSION | default "20"}}'
PHP_EXTENSIONS: "https://github.com/mlocati/docker-php-extension-installer/releases/download/2.9.13/install-php-extensions"
WORDPRESS_PHAR: "https://github.com/wp-cli/wp-cli/releases/download/v2.12.0/wp-cli-2.12.0.phar"
SYMFONY_CLI: "https://github.com/symfony-cli/symfony-cli/releases/download/v5.15.1/symfony-cli_5.15.1_amd64.deb"
VERSIONS: "7.4 8.0 8.1 8.2 8.3 8.4"
PKG56: 'wget git fish unzip zip'
PKG70: 'wget git fish unzip zip'
PKG71: 'wget git fish unzip zip'
PKG72: 'wget git fish unzip zip'
PKG73: 'wget git fish unzip zip'
PKG74: 'wget git fish unzip zip graphviz'
PKG80: 'wget git fish unzip zip graphviz'
PKG81: 'wget git fish unzip zip graphviz'
PKG82: 'wget git fish unzip zip graphviz'
PKG83: 'wget git fish unzip zip graphviz'
PKG84: 'wget git fish unzip zip graphviz'
PHPLISTEXTENSION56: '@composer amqp apcu bcmath blackfire exif gd imagick intl ldap mysqli opcache pdo_mysql pdo_pgsql redis shmop soap sockets tidy zip gnupg'
PHPLISTEXTENSION70: '@composer'
PHPLISTEXTENSION71: '@composer'
PHPLISTEXTENSION72: '@composer'
PHPLISTEXTENSION73: '@composer'
PHPLISTEXTENSION74: '@composer amqp apcu bcmath blackfire exif gd imagick intl ldap mysqli opcache pdo_mysql pdo_pgsql redis shmop soap sockets tidy zip gnupg'
PHPLISTEXTENSION80: '@composer amqp apcu bcmath blackfire exif gd imagick intl ldap mysqli opcache pdo_mysql pdo_pgsql redis shmop soap sockets tidy zip gnupg'
PHPLISTEXTENSION81: '@composer amqp apcu bcmath blackfire exif gd imagick intl ldap mysqli opcache pdo_mysql pdo_pgsql redis shmop soap sockets tidy zip gnupg'
PHPLISTEXTENSION82: '@composer amqp apcu bcmath blackfire exif gd imagick intl ldap mysqli opcache pdo_mysql pdo_pgsql redis shmop soap sockets tidy zip gnupg'
PHPLISTEXTENSION83: '@composer amqp apcu bcmath blackfire exif gd imagick intl ldap mysqli opcache pdo_mysql pdo_pgsql redis shmop soap sockets tidy zip gnupg'
PHPLISTEXTENSION84: '@composer amqp apcu bcmath blackfire exif gd imagick intl ldap mysqli opcache pdo_mysql pdo_pgsql redis shmop soap sockets tidy zip gnupg'
tasks:
default:
desc: "Affiche l'aide et les tâches disponibles"
silent: true
cmds:
- echo "🛠️ Collection de Taskfiles pour le développement"
- echo ""
- echo "Tâches globales disponibles :"
- task --list
- echo ""
info:
desc: "Affiche les informations du projet avec les variables d'environnement"
silent: true
cmds:
- |
export PROJECT_VERSION=$(jq -r .version package.json)
echo "🛠️ {{.PROJECT_NAME}} v$PROJECT_VERSION - Collection de Taskfiles"
echo "Environnement: {{.ENVIRONMENT}}"
echo "Node.js version: {{.NODE_VERSION}}"
help:
desc: "Affiche l'aide détaillée"
aliases: [ h ]
silent: true
cmds:
- task: default
create:
desc: "Construit les images Docker définies dans les Taskfiles inclus"
silent: true
preconditions:
- sh: command -v docker
msg: "Docker n'est pas installé ou accessible"
vars:
FOLDER: '{{.FOLDER | default ""}}'
VERSION: '{{.VERSION | default ""}}'
NUMBER: '{{.NUMBER | default ""}}'
cmds:
- |
declare -A EXT_MAP
EXT_MAP["5.6"]="{{.PHPLISTEXTENSION56}}"
EXT_MAP["7.0"]="{{.PHPLISTEXTENSION70}}"
EXT_MAP["7.1"]="{{.PHPLISTEXTENSION71}}"
EXT_MAP["7.2"]="{{.PHPLISTEXTENSION72}}"
EXT_MAP["7.3"]="{{.PHPLISTEXTENSION73}}"
EXT_MAP["7.4"]="{{.PHPLISTEXTENSION74}}"
EXT_MAP["8.0"]="{{.PHPLISTEXTENSION80}}"
EXT_MAP["8.1"]="{{.PHPLISTEXTENSION81}}"
EXT_MAP["8.2"]="{{.PHPLISTEXTENSION82}}"
EXT_MAP["8.3"]="{{.PHPLISTEXTENSION83}}"
EXT_MAP["8.4"]="{{.PHPLISTEXTENSION84}}"
declare -A PKG_MAP
PKG_MAP["5.6"]="{{.PKG56}}"
PKG_MAP["7.0"]="{{.PKG70}}"
PKG_MAP["7.1"]="{{.PKG71}}"
PKG_MAP["7.2"]="{{.PKG72}}"
PKG_MAP["7.3"]="{{.PKG73}}"
PKG_MAP["7.4"]="{{.PKG74}}"
PKG_MAP["8.0"]="{{.PKG80}}"
PKG_MAP["8.1"]="{{.PKG81}}"
PKG_MAP["8.2"]="{{.PKG82}}"
PKG_MAP["8.3"]="{{.PKG83}}"
PKG_MAP["8.4"]="{{.PKG84}}"
# Extraction version pour docker pull :
# - si x.y.0 => x.y
# - sinon garder la version complète (ex : 5.6.20 => 5.6.20)
if echo "{{.VERSION}}" | grep -Eq '^[0-9]+\.[0-9]+\.0$'; then
BASE_VERSION=$(echo "{{.VERSION}}" | sed -E 's/^([0-9]+\.[0-9]+)\.0$/\1/')
else
BASE_VERSION="{{.VERSION}}"
fi
echo ""
echo "Verification de l'image de base php:${BASE_VERSION}-{{.FOLDER}}"
if ! docker manifest inspect php:${BASE_VERSION}-{{.FOLDER}} > /dev/null 2>&1; then
echo "Erreur : Impossible de récupérer l'image php:${BASE_VERSION}-{{.FOLDER}}" >&2
else
mkdir -p build/{{.FOLDER}}/{{.VERSION}}
cp images/{{.FOLDER}}/Dockerfile build/{{.FOLDER}}/{{.VERSION}}/Dockerfile
sed -i "s#VERSIONIMAGE#php:${BASE_VERSION}-{{.FOLDER}}#" build/{{.FOLDER}}/{{.VERSION}}/Dockerfile
sed -i 's#PHPEXTENSIONS#{{.PHP_EXTENSIONS}}#' build/{{.FOLDER}}/{{.VERSION}}/Dockerfile
EXT="${EXT_MAP["{{.NUMBER}}"]}"
sed -i "s#PHPLISTEXTENSION#${EXT}#" build/{{.FOLDER}}/{{.VERSION}}/Dockerfile;
EXT="${PKG_MAP["{{.NUMBER}}"]}"
sed -i "s#PKGINSTALL#${EXT}#" build/{{.FOLDER}}/{{.VERSION}}/Dockerfile;
sed -i 's#SYMFONYCLI#{{.SYMFONY_CLI}}#' build/{{.FOLDER}}/{{.VERSION}}/Dockerfile
sed -i 's#WORDPRESSPHAR#{{.WORDPRESS_PHAR}}#' build/{{.FOLDER}}/{{.VERSION}}/Dockerfile
echo "Dockerfile créé dans build/{{.FOLDER}}/{{.VERSION}}/Dockerfile"
fi
matrix:
desc: "Génère une matrice JSON pour les versions PHP à utiliser dans GitHub Actions"
silent: true
vars:
VERSIONS: "{{.VERSIONS}}"
cmds:
- |
for version in {{.VERSIONS}}; do
echo ""
echo "Génération de la matrice pour PHP $version"
if [ ! -f matrix_$version.json ]; then
echo "https://www.php.net/releases/index.php?json&version=$version&max=1000"
wget -O php_versions$version.json "https://www.php.net/releases/index.php?json&version=$version&max=1000"
jq -r '{versions: (keys)}' php_versions$version.json > matrix_$version.json
rm -rf php_versions$version.json
else
echo "Le fichier matrix_$version.json existe déjà, génération ignorée."
fi
done
build:
desc: "Construit les images Docker définies dans les Taskfiles inclus"
silent: true
preconditions:
- sh: command -v docker
msg: "Docker n'est pas installé ou accessible"
vars:
VERSIONS: "{{.VERSIONS}}"
FOLDERS: "apache fpm"
cmds:
- rm -rf build
- |
VARIANTS=("" "-xdebug" "-wordpress" "-wordpress-xdebug" "-symfony" "-symfony-xdebug")
for number in {{.VERSIONS}}; do
for version in $(jq -r '.versions[]' matrix_$number.json); do
for folder in {{.FOLDERS}}; do
task create FOLDER=$folder VERSION=$version NUMBER=$number || true
if [ -f build/$folder/$version/Dockerfile ]; then
echo "Création des images a partir du Dockerfile build/$folder/$version/Dockerfile"
for variant in "${VARIANTS[@]}"; do
image="php:$version-$folder${variant}"
tag="koromerzhin/php:$version-$folder${variant}"
target="build-$folder${variant}"
echo ""
echo "Verification de l'image koromerzhin/$image"
if ! docker manifest inspect koromerzhin/$image > /dev/null 2>&1; then
echo "Image koromerzhin/$image non trouvée localement, lancement du build."
docker build -t $tag build/$folder/$version --target $target || true
else
echo "Image koromerzhin/$image déjà présente localement, build ignoré."
fi
done
else
echo "Le fichier build/$folder/$version/Dockerfile n'existe pas, build ignoré."
fi
done
done
done
push:
desc: "Pousse toutes les images Docker vers Docker Hub"
preconditions:
- sh: command -v docker
msg: "Docker n'est pas installé ou accessible"
silent: true
cmds:
- |
if [ -n "$(docker images -q koromerzhin/php)" ]; then
echo "Images koromerzhin/php trouvées, lancement du push."
docker push koromerzhin/php -a
else
echo "Aucune image koromerzhin/php trouvée localement, push ignoré."
fi
exec:
vars:
VERSIONS: "{{.VERSIONS}}"
cmds:
- task: matrix
vars:
VERSIONS: "{{.VERSIONS}}"
- task: build
vars:
VERSIONS: "{{.VERSIONS}}"