build: Use task as build tool

This commit is contained in:
Carsten Sprung 2020-09-22 23:37:45 +02:00
parent 391d8b34e5
commit e1ea18912b
6 changed files with 89 additions and 25 deletions

View file

@ -1,2 +0,0 @@
alias dc-all="docker-compose -f docker-compose.yml */docker-compose.yml(P:-f:)"
alias dc-dev="dc-all -f docker-compose.dev.yml"

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.env .env
.task
# templates # templates
gitea/app.ini gitea/app.ini

View file

@ -4,24 +4,18 @@
All data is stored in `$BASE_DIR` (defaults to `/srv`), one subfolder per service. All data is stored in `$BASE_DIR` (defaults to `/srv`), one subfolder per service.
## Secrets ## Secrets & Configuration
Copy from `.env.example` and fill in your values. Copy from `.env.example` and fill in your values.
## Templating
```bash
./template.sh
```
## Deploy ## Deploy
```bash ```bash
source .aliases ./task up
dc-all up -d
``` ```
:warning: These aliases do only work in `zsh`! For other shells use List other tasks
```bash ```bash
docker-compose -f docker-compose.yml -f {subfolder1}/docker-compose.yml -f {subfolder2}/docker-compose.yml -f ... up -d` ./task -l
``` ```

83
Taskfile.yml Normal file
View file

@ -0,0 +1,83 @@
# https://taskfile.dev
version: '3'
dotenv: ['.env']
vars:
ACTIVE_SERVICES:
bitwarden
drone
drone-runner
echo
gitea
nextcloud
proxy
RELEVANT_SERVICES: "{{coalesce .SERVICES .ACTIVE_SERVICES}}"
DOCKER_COMPOSE_FILES:
sh: find -wholename "*/docker-compose.yml"
DCF: -f docker-compose.yml -f {{.DOCKER_COMPOSE_FILES | splitLines | join " -f "}}
silent: True
tasks:
validate:
desc: Check .env for missing variables
cmds:
- |
{{with .MISSING_VARS | splitLines}}
echo Warning: missing vars in .env:
{{range .}}
echo " {{. | trimSuffix "="}}"
{{end}}
{{end}}
vars:
MISSING_VARS:
sh: grep -e "^[^#].*=$" .env || exit 0
template:
desc: Fill in variables in *.template.* files
deps: [validate]
cmds:
- |
find -name "*.template.*" | while read -r f
do
echo "templating $f"
envsubst < $f > ${f/.template/}
done
sources:
- ./**/*.template.*
- .env
pull:
desc: Pull latest docker images
cmds:
- docker-compose {{.DCF}} pull {{coalesce .SERVICES .ACTIVE_SERVICES}}
up:
desc: Deploy given or active services
deps: [template]
cmds:
- docker-compose {{.DCF}} up -d {{coalesce .SERVICES .ACTIVE_SERVICES}}
stop:
desc: Stop given or all services
cmds:
- docker-compose {{.DCF}} stop {{coalesce .SERVICES .ACTIVE_SERVICES}}
down:
desc: Stop and remove all services
cmds:
- docker-compose {{.DCF}} down
logs:
desc: Tail logs of given or all services
deps: [template]
cmds:
- docker-compose {{.DCF}} logs -f {{coalesce .SERVICES .ACTIVE_SERVICES}}
upgrade:
desc: Pull and re-deploy active services
cmds:
- task: pull
- task: up

BIN
task Executable file

Binary file not shown.

View file

@ -1,12 +0,0 @@
#!/bin/zsh
echo "== Loading variables"
set -a
source .env
set +a
find . -name "*.template.*" | while read -r f
do
echo "== Processing $f"
envsubst < $f > ${f/.template/}
done