container-server/tasks/compose.yml

114 lines
2.6 KiB
YAML

version: '3'
includes:
util:
taskfile: ./utils.yml
internal: true
dir: ..
vars:
COMPOSE_FILES:
sh: touch enabled ; find ./services -iname docker-compose.yml | grep -f enabled || exit 0
COMPOSE_ARGS: -f services/docker-compose.yml -f {{.COMPOSE_FILES | splitLines | join " -f "}}
tasks:
config:
desc: Show merged compose config
deps:
- util:template
cmds:
- "docker-compose {{.COMPOSE_ARGS}} config"
pull:
desc: Pull latest docker images
cmds:
- "docker-compose {{.COMPOSE_ARGS}} pull {{.CLI_ARGS}}"
build:
desc: Build latest docker images (if applicable)
cmds:
- "docker-compose {{.COMPOSE_ARGS}} build {{.CLI_ARGS}}"
up:
desc: Deploy given or active services
deps:
- util:template
cmds:
- "docker-compose {{.COMPOSE_ARGS}} up -d {{.CLI_ARGS}}"
run:
desc: Run a one-time command in a given services
deps:
- util:template
cmds:
- "docker-compose {{.COMPOSE_ARGS}} run --rm {{.CLI_ARGS}}"
restart:
desc: Restart given or active services
deps:
- util:template
cmds:
- "docker-compose {{.COMPOSE_ARGS}} restart {{.CLI_ARGS}}"
recreate:
desc: Recreate given or active services
deps:
- util:template
cmds:
- "docker-compose {{.COMPOSE_ARGS}} up -d --force-recreate {{.CLI_ARGS}}"
stop:
desc: Stop given or all services
cmds:
- "docker-compose {{.COMPOSE_ARGS}} stop {{.CLI_ARGS}}"
down:
desc: Stop and remove all services
cmds:
- "docker-compose {{.COMPOSE_ARGS}} down"
logs:
desc: Tail logs of given or all services
deps:
- util:template
cmds:
- "docker-compose {{.COMPOSE_ARGS}} logs --tail=50 --follow {{.CLI_ARGS}}"
upgrade:
desc: Pull and re-deploy active services
cmds:
- task: pull
- task: up
list:
desc: List current containers
cmds:
- docker ps -a --format 'table {{"{{.ID}}"}}\t{{"{{.Image}}"}}\t{{"{{.Names}}"}}\t{{"{{.CreatedAt}}"}}\t{{"{{.Status}}"}}\t{{"{{.Networks}}"}}'
uplogs:
desc: up & logs
cmds:
- task: up
- task: logs
headlogs:
desc: Head logs of given containers
cmds:
- |
for id in {{.CLI_ARGS}}; do
echo "=== $id ==="
echo
docker logs $id |& head -n 25
echo
done
headlogs-all:
desc: Head logs of all containers
cmds:
- |
for id in $(docker ps -q); do
echo "=== $(docker inspect $id --format='{{printf `{{.Name}}`}}') ==="
echo
docker logs $id |& head -n 25
echo
done