Taskfile to universal task runner który pozwala zdefiniować zadania raz i uruchamiać je wszędzie:
- Lokalnie (Docker Compose)
- Produkcja (VPS przez SSH)
- CI/CD (GitHub Actions, GitLab CI, Jenkins)
┌────────────────────────────────────────────────────────┐
│ Taskfile.yml │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Variables │ │Environments │ │ Platforms │ │
│ │ (zmienne) │ │ (envs) │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ ┌───────────────────────────────────────────────────┐ │
│ │ Tasks │ │
│ │ - init - deploy - ci-generate │ │
│ │ - build - validate - test │ │
│ │ - push - status - logs │ │
│ └───────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ Local │ │ VPS │ │ CI/CD │
│ Docker │ │ SSH │ │ GitHub │
└────────────┘ └────────────┘ └────────────┘
# Generuj pliki dla różnych platform CI/CD
taskfile run ci-generate
# Powstaną:
# .github/workflows/deploy.yml (GitHub Actions)
# .gitlab-ci.yml (GitLab CI)Jak to działa:
Task ci-generate tworzy gotowe konfiguracje które:
- Instalują taskfile w runnerze CI
- Używają tych samych komend co lokalnie (
taskfile run deploy) - Pobierają VPS_IP/VPS_USER z secrets
# Walidacja w izolowanym kontenerze
taskfile run validate-deploy
# Walidacja w VM (Vagrant)
taskfile run validate-vm
# Pełna walidacja (Docker + testy)
taskfile run validate-all
# Sprawdzenie wymagań przed deploy
taskfile run preflightJak to działa:
validate-deploy:
- Buduje obraz Docker:
docker build -t app-validate - Uruchamia kontener na porcie 9999
- Wykonuje health check:
curl http://localhost:9999/health - Sprząta: zatrzymuje i usuwa kontener
validate-vm:
- Tworzy Vagrantfile (Ubuntu VM)
- Instaluje Podman w VM
- Deployuje przez SSH do VM
- Testuje na
http://localhost:9999
# Setup VPS (instalacja Podman, firewall)
taskfile --env prod run vps-setup
# Deploy web
taskfile --env prod --platform web run deploy
# Deploy desktop + web
taskfile --env prod run deploy-allJak to działa:
Twoja maszyna VPS (przez SSH)
│ │
├── ssh VPS_IP ────────►│
│ │
├── docker build │
├── docker push ───────►│ podman pull
│ │
└── ssh restart ───────►│ podman run
# Tworzy .env z .env.example
taskfile run init
# Sprawdza konfigurację
taskfile run env-check# 1. Clone repo
git clone https://github.com/example/app.git
cd app
# 2. Init (stworzy .env)
taskfile run init
# 3. Edytuj .env
nano .env
# VPS_IP=123.456.789.012
# 4. Walidacja
taskfile run validate-all
# 5. Deploy
taskfile --env prod run deploy-all# Lokalny development
taskfile run dev # Start lokalnie
taskfile run test # Uruchom testy
taskfile run preflight # Sprawdź czy wszystko OK
# Generuj CI/CD
taskfile run ci-generate
git add .github/workflows/
git commit -m "Add CI/CD"
# Deploy na VPS
taskfile --env prod run deploy-allGitHub Actions (auto-generowany):
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install taskfile
- run: taskfile --env prod run deploy
env:
VPS_IP: ${{ secrets.VPS_IP }}GitLab CI (auto-generowany):
stages:
- deploy
deploy:
stage: deploy
script:
- pip install taskfile
- taskfile --env prod run deploy
only:
- main| Funkcja | Opis | Komenda |
|---|---|---|
| Multi-env | local/prod z różnymi konfiguracjami | --env prod |
| Multi-platform | web/desktop z różnymi deployami | --platform web |
| Variables | Kaskadowe zmienne: global → env → platform → CLI | --var KEY=value |
| @remote | Prefix dla komend SSH | @remote podman ps |
| deps | Zależności między taskami | deps: [init, build] |
| condition | Warunkowe wykonanie | condition: "test -f file" |
| Dry-run | Podgląd bez wykonania | --dry-run |
variables:
# Global (domyślne dla wszystkich)
APP_NAME: my-app
TAG: latest
environments:
local:
variables:
DOMAIN: localhost # Nadpisuje dla local
prod:
variables:
DOMAIN: ${VPS_IP} # Nadpisuje dla prod
# CLI nadpisuje wszystko:
# taskfile --env prod --var TAG=v1.0.0 run deploy- Parse: Wczytuje Taskfile.yml
- Resolve: Oblicza zmienne (global → env → platform → CLI)
- Filter: Wybiera taski pasujące do
--envi--platform - Execute: Uruchamia komendy:
@remote→ wykonuje przez SSHdeps: []→ uruchamia zależności pierwszeignore_errors: true→ kontynuuje mimo błędu
taskfile run validate-deployCo się dzieje:
Docker Build ──► Docker Run ──► Health Check ──► Cleanup
│ │ │ │
30s-2m Start app curl /health docker rm
taskfile run validate-vmCo się dzieje:
Vagrant Up ──► Install Podman ──► Deploy ──► Test ──► Destroy
│ │ │ │ │
2-5 min apt-get Same as curl vagrant
prod /health destroy
# Dodaj staging do Taskfile.yml
environments:
staging:
ssh_host: staging.example.com
container_runtime: podmantaskfile --env staging run deploy# W task ci-generate
ci-generate:
cmds:
- |
# Jenkins
cat > Jenkinsfile << 'EOF'
pipeline {
agent any
stages {
stage('Deploy') {
steps {
sh 'pip install taskfile'
sh 'taskfile --env prod run deploy'
}
}
}
}
EOFenvironments:
staging:
desc: Staging environment
ssh_host: ${STAGING_IP}
ssh_user: deploy
container_runtime: podman
variables:
DOMAIN: staging.example.comtaskfile --env staging run deployTaskfile pozwala:
- ✅ Jedna konfiguracja → działa lokalnie, na VPS i w CI/CD
- ✅ Walidacja przed deploy → Docker lub VM
- ✅ Auto-generowanie → .env, CI/CD files
- ✅ Szybki deploy → wystarczy IP VPS + SSH key
Minimalny setup:
echo "VPS_IP=123.456.789.012" > .env
taskfile --env prod run deploy-all