Dnaron
How to reuse code in taskfile?
Another idea might be to call the task shell from within the task:
But now
version: 3
tasks:
install:
deps: [ file-permission, composer-install, migration, es-create, seed, es-index, yarn-install, yarn-prod, install-passport, install-push ]
up: docker compose up -d
bash: {{.TASK_EXE}} in-docker -- bash
composer-install: {{.TASK_EXE}} in-docker -- composer install
migration: {{.TASK_EXE}} in-docker -- php artisan migrate --force
seed: {{.TASK_EXE}} in-docker -- php artisan db:seed
yarn-install: {{.TASK_EXE}} in-docker -- yarn install
yarn-prod: {{.TASK_EXE}} in-docker -- yarn run prod
yarn-watch: {{.TASK_EXE}} in-docker -- yarn run watch
es-create: {{.TASK_EXE}} in-docker -- php artisan es:create --force
es-index: {{.TASK_EXE}} in-docker -- php artisan es:index --force
install-passport: {{.TASK_EXE}} in-docker -- php artisan passport:install
install-push: {{.TASK_EXE}} in-docker -- php artisan webpush:vapid
cache-config:
{{.TASK_EXE}} in-docker -- php artisan config:cache
{{.TASK_EXE}} in-docker -- php artisan route:cache
file-permission:
{{.TASK_EXE}} in-docker -- chmod -R 777 storage/
{{.TASK_EXE}} in-docker -- chmod 777 bootstrap/cache/
in-docker:
docker compose exec -T -u nginx php {{.CLI_ARGS}}
version: 3
tasks:
install:
deps: [ file-permission, composer-install, migration, es-create, seed, es-index, yarn-install, yarn-prod, install-passport, install-push ]
up: docker compose up -d
bash: {{.TASK_EXE}} in-docker -- bash
composer-install: {{.TASK_EXE}} in-docker -- composer install
migration: {{.TASK_EXE}} in-docker -- php artisan migrate --force
seed: {{.TASK_EXE}} in-docker -- php artisan db:seed
yarn-install: {{.TASK_EXE}} in-docker -- yarn install
yarn-prod: {{.TASK_EXE}} in-docker -- yarn run prod
yarn-watch: {{.TASK_EXE}} in-docker -- yarn run watch
es-create: {{.TASK_EXE}} in-docker -- php artisan es:create --force
es-index: {{.TASK_EXE}} in-docker -- php artisan es:index --force
install-passport: {{.TASK_EXE}} in-docker -- php artisan passport:install
install-push: {{.TASK_EXE}} in-docker -- php artisan webpush:vapid
cache-config:
{{.TASK_EXE}} in-docker -- php artisan config:cache
{{.TASK_EXE}} in-docker -- php artisan route:cache
file-permission:
{{.TASK_EXE}} in-docker -- chmod -R 777 storage/
{{.TASK_EXE}} in-docker -- chmod 777 bootstrap/cache/
in-docker:
docker compose exec -T -u nginx php {{.CLI_ARGS}}
in-docker
is not internal (i would like to keep it internal) and it feels a litle too hacky :/11 replies
How to reuse code in taskfile?
I also tried extracting the command as var, like this:
but then I get an error:
version: 3
tasks:
install:
deps: [ file-permission, composer-install, migration, es-create, seed, es-index, yarn-install, yarn-prod, install-passport, install-push ]
up: docker compose up -d
bash: {{.IN_DOCKER}} bash
composer-install: {{.IN_DOCKER}} composer install
migration: {{.IN_DOCKER}} php artisan migrate --force
seed: {{.IN_DOCKER}} php artisan db:seed
yarn-install: {{.IN_DOCKER}} yarn install
yarn-prod: {{.IN_DOCKER}} yarn run prod
yarn-watch: {{.IN_DOCKER}} yarn run watch
es-create: {{.IN_DOCKER}} php artisan es:create --force
es-index: {{.IN_DOCKER}} php artisan es:index --force
install-passport: {{.IN_DOCKER}} php artisan passport:install
install-push: {{.IN_DOCKER}} php artisan webpush:vapid
cache-config:
- {{.IN_DOCKER}} php artisan config:cache
- {{.IN_DOCKER}} php artisan route:cache
file-permission:
- {{.IN_DOCKER}} -T php chmod -R 777 storage/
- {{.IN_DOCKER}} -T php chmod 777 bootstrap/cache/
vars:
IN_DOCKER: docker compose exec -T -u nginx php
version: 3
tasks:
install:
deps: [ file-permission, composer-install, migration, es-create, seed, es-index, yarn-install, yarn-prod, install-passport, install-push ]
up: docker compose up -d
bash: {{.IN_DOCKER}} bash
composer-install: {{.IN_DOCKER}} composer install
migration: {{.IN_DOCKER}} php artisan migrate --force
seed: {{.IN_DOCKER}} php artisan db:seed
yarn-install: {{.IN_DOCKER}} yarn install
yarn-prod: {{.IN_DOCKER}} yarn run prod
yarn-watch: {{.IN_DOCKER}} yarn run watch
es-create: {{.IN_DOCKER}} php artisan es:create --force
es-index: {{.IN_DOCKER}} php artisan es:index --force
install-passport: {{.IN_DOCKER}} php artisan passport:install
install-push: {{.IN_DOCKER}} php artisan webpush:vapid
cache-config:
- {{.IN_DOCKER}} php artisan config:cache
- {{.IN_DOCKER}} php artisan route:cache
file-permission:
- {{.IN_DOCKER}} -T php chmod -R 777 storage/
- {{.IN_DOCKER}} -T php chmod 777 bootstrap/cache/
vars:
IN_DOCKER: docker compose exec -T -u nginx php
task: Failed to parse taskfile.yaml:
yaml: line 3: did not find expected key
task: Failed to parse taskfile.yaml:
yaml: line 3: did not find expected key
11 replies
How to reuse code in taskfile?
Now, I know I can extract those commands using internal command and vars, and I did that but look how verbose it becomes! It's soo long:
version: 3
tasks:
install:
deps: [ file-permission, composer-install, migration, es-create, seed, es-index, yarn-install, yarn-prod, install-passport, install-push ]
up:
docker compose up -d
bash:
cmd: run-in-docker
vars:
DOCKER_COMMAND: docker compose exec -u nginx php bash
composer-install:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php composer install
migration:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan migrate --force
seed:
cmd: run-in-docker
vars:
DOCKER_COMMAND: artisan db:seed
yarn-install:
cmd: run-in-docker
vars:
DOCKER_COMMAND: yarn install
yarn-prod:
cmd: run-in-docker
vars:
DOCKER_COMMAND: yarn run prod
yarn-watch:
cmd: run-in-docker
vars:
DOCKER_COMMAND: yarn run watch
es-create:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan es:create --force
es-index:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan es:index --force
install-passport:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan passport:install
install-push:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan webpush:vapid
cache-config:
cmds:
- task: run-in-docker
vars:
DOCKER_COMMAND: php artisan config:cache
- task: run-in-docker
vars:
DOCKER_COMMAND: php artisan route:cache
file-permission:
cmds:
- task: run-in-docker
vars:
DOCKER_COMMAND: chmod -R 777 storage/
- task: run-in-docker
vars:
DOCKER_COMMAND: chmod 777 bootstrap/cache/
run-in-docker:
internal: true
cmds:
- docker compose exec -T -u nginx {{.DOCKER_COMMAND}}
version: 3
tasks:
install:
deps: [ file-permission, composer-install, migration, es-create, seed, es-index, yarn-install, yarn-prod, install-passport, install-push ]
up:
docker compose up -d
bash:
cmd: run-in-docker
vars:
DOCKER_COMMAND: docker compose exec -u nginx php bash
composer-install:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php composer install
migration:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan migrate --force
seed:
cmd: run-in-docker
vars:
DOCKER_COMMAND: artisan db:seed
yarn-install:
cmd: run-in-docker
vars:
DOCKER_COMMAND: yarn install
yarn-prod:
cmd: run-in-docker
vars:
DOCKER_COMMAND: yarn run prod
yarn-watch:
cmd: run-in-docker
vars:
DOCKER_COMMAND: yarn run watch
es-create:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan es:create --force
es-index:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan es:index --force
install-passport:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan passport:install
install-push:
cmd: run-in-docker
vars:
DOCKER_COMMAND: php artisan webpush:vapid
cache-config:
cmds:
- task: run-in-docker
vars:
DOCKER_COMMAND: php artisan config:cache
- task: run-in-docker
vars:
DOCKER_COMMAND: php artisan route:cache
file-permission:
cmds:
- task: run-in-docker
vars:
DOCKER_COMMAND: chmod -R 777 storage/
- task: run-in-docker
vars:
DOCKER_COMMAND: chmod 777 bootstrap/cache/
run-in-docker:
internal: true
cmds:
- docker compose exec -T -u nginx {{.DOCKER_COMMAND}}
11 replies
How to reuse code in taskfile?
Sure!
Tasklist is great! It's so much better than
You can see that most of them all begin with
make
. I especially like the listing of all possible lists, the silent mode, the deps
, the dir
, and the shorthand for cmd
, all of that is awesome.
Currently, I have a file like this:
version: 3
tasks:
install:
deps: [ file-permission, composer-install, migration, es-create, seed, es-index, yarn-install, yarn-prod, install-passport, install-push ]
up: docker compose up -d
bash: docker compose exec -u nginx php bash
bash-root: docker compose exec -u root php bash
composer-install: docker compose exec -T -u nginx php composer install
migration: docker compose exec -T -u nginx php php artisan migrate --force
seed: docker compose exec -T -u nginx php php artisan db:seed
yarn-install: docker compose exec -T -u nginx php yarn install
yarn-prod: docker compose exec -T -u nginx php yarn run prod
yarn-watch: docker compose exec -T -u nginx php yarn run watch
es-create: docker compose exec -T -u nginx php php artisan es:create --force
es-index: docker compose exec -T -u nginx php php artisan es:index --force
install-passport: docker compose exec -T -u nginx php php artisan passport:install
install-push: docker compose exec -T -u nginx php php artisan webpush:vapid
cache-config:
docker compose exec -T -u nginx php php artisan config:cache
docker compose exec -T -u nginx php php artisan route:cache
file-permission:
docker compose exec -T php chmod -R 777 storage/
docker compose exec -T php chmod 777 bootstrap/cache/
version: 3
tasks:
install:
deps: [ file-permission, composer-install, migration, es-create, seed, es-index, yarn-install, yarn-prod, install-passport, install-push ]
up: docker compose up -d
bash: docker compose exec -u nginx php bash
bash-root: docker compose exec -u root php bash
composer-install: docker compose exec -T -u nginx php composer install
migration: docker compose exec -T -u nginx php php artisan migrate --force
seed: docker compose exec -T -u nginx php php artisan db:seed
yarn-install: docker compose exec -T -u nginx php yarn install
yarn-prod: docker compose exec -T -u nginx php yarn run prod
yarn-watch: docker compose exec -T -u nginx php yarn run watch
es-create: docker compose exec -T -u nginx php php artisan es:create --force
es-index: docker compose exec -T -u nginx php php artisan es:index --force
install-passport: docker compose exec -T -u nginx php php artisan passport:install
install-push: docker compose exec -T -u nginx php php artisan webpush:vapid
cache-config:
docker compose exec -T -u nginx php php artisan config:cache
docker compose exec -T -u nginx php php artisan route:cache
file-permission:
docker compose exec -T php chmod -R 777 storage/
docker compose exec -T php chmod 777 bootstrap/cache/
docker compose exec -T -u nginx php
. I wish there was some clean way to extract the reused parts.11 replies