YAML
Format lizibil pentru configurari, CI/CD, Docker si Kubernetes
Ce este YAML?
YAML (YAML Ain't Markup Language) este un format de serializare a datelor, optimizat pentru:
- Citire usoara de catre oameni
- Fisiere de configurare
- Pipeline-uri CI/CD (GitHub Actions, GitLab CI)
- Docker Compose si Kubernetes
YAML vs JSON
YAML:
nume: Maria
varsta: 15
esteElev: true
JSON echivalent:
{
"nume": "Maria",
"varsta": 15,
"esteElev": true
}
💡 YAML este mai curat! Fara acolade, fara ghilimele pentru chei, fara virgule.
Sintaxa de Baza
# Acesta este un comentariu
string: text simplu
string_ghilimele: "text cu ghilimele"
numar: 42
decimal: 3.14
boolean: true
null_value: null
⚠️ Atentie la indentare! YAML foloseste spatii (nu tab-uri) pentru structura. De obicei 2 spatii.
Liste (Arrays)
# Lista simpla
clase:
- 5A
- 6B
- 7A
# Lista inline
note: [10, 9, 8, 10]
Obiecte Imbricate
elev:
nume: Ion Popescu
clasa: 7A
note:
romana: 9
matematica: 10
informatica: 10
Text Multi-linie
# Pastreaza newlines (|)
descriere: |
Aceasta este prima linie.
Aceasta este a doua linie.
Fiecare linie ramane separata.
# Concateneaza liniile (>)
paragraf: >
Acest text lung va fi
concatenat intr-o
singura linie.
Exemplu: GitHub Actions
name: CI Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run tests
run: npm test
Exemplu: Docker Compose
version: "3.8"
services:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./html:/usr/share/nginx/html
database:
image: postgres:14
environment:
POSTGRES_DB: myapp
POSTGRES_USER: admin
Reguli Importante
| Regula | Detalii |
|---|---|
| Indentare | Foloseste 2 spatii, NU tab-uri |
| Chei | Nu au nevoie de ghilimele (de obicei) |
| Comentarii | Incep cu # |
| Boolean | true/false sau yes/no |
| Liste | Incep cu - (dash + spatiu) |
Unde se foloseste YAML?
| Context | Fisier |
|---|---|
| GitHub Actions | .github/workflows/*.yml |
| Docker Compose | docker-compose.yml |
| Kubernetes | deployment.yaml |
| Ansible | playbook.yml |
| Jekyll/Hugo | Front matter in Markdown |