oak-dockerfile

Crates.iooak-dockerfile
lib.rsoak-dockerfile
version0.0.1
created_at2025-10-20 16:34:31.654832+00
updated_at2026-01-23 04:27:31.683402+00
descriptionDockerfile container configuration language parser with support for container image building and management.
homepagehttps://github.com/ygg-lang/oaks
repositoryhttps://github.com/ygg-lang/oaks
max_upload_size
id1892300
size65,621
publisher (github:ygg-lang:publisher)

documentation

https://docs.rs/oak-dockerfile

README

Oak Dockerfile Parser

Crates.io Documentation

High-performance incremental Dockerfile parser for the oak ecosystem with flexible configuration, optimized for container configuration and image building.

🎯 Overview

Oak Dockerfile is a robust parser for Dockerfile, designed to handle complete Dockerfile syntax including modern features. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for container configuration and image building.

✨ Features

  • Complete Dockerfile Syntax: Supports all Dockerfile features including modern specifications
  • Full AST Generation: Generates comprehensive Abstract Syntax Trees
  • Lexer Support: Built-in tokenization with proper span information
  • Error Recovery: Graceful handling of syntax errors with detailed diagnostics

🚀 Quick Start

Basic example:

use oak_dockerfile::{Parser, DockerfileLanguage, SourceText};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let parser = Parser::new();
    let source = SourceText::new(r#"
FROM alpine:latest
RUN apk add --no-cache bash
COPY . /app
WORKDIR /app
CMD ["bash"]
    "#);
    
    let result = parser.parse(&source);
    println!("Parsed Dockerfile successfully.");
    Ok(())
}

📋 Parsing Examples

Basic Dockerfile Parsing

use oak_dockerfile::{Parser, DockerfileLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
FROM node:14-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
"#);

let result = parser.parse(&source);
println!("Dockerfile parsed successfully.");

Multi-stage Build Parsing

use oak_dockerfile::{Parser, DockerfileLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
# Build stage
FROM golang:1.19-alpine AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /app

# Runtime stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app .
EXPOSE 8080
CMD ["./app"]
"#);

let result = parser.parse(&source);
println!("Multi-stage Dockerfile parsed successfully.");

🔧 Advanced Features

Token-Level Parsing

use oak_dockerfile::{Parser, DockerfileLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new("FROM alpine:latest");
let result = parser.parse(&source);
println!("Token parsing completed.");

Error Handling

use oak_dockerfile::{Parser, DockerfileLanguage, SourceText};

let parser = Parser::new();
let source = SourceText::new(r#"
FROM alpine:latest
RUN apk add --no-cache bash
COPY . /app
WORKDIR /app
CMD ["bash"
# Missing closing bracket
"#);

let result = parser.parse(&source);
if let Some(errors) = result.result.err() {
    println!("Parse errors found: {:?}", errors);
} else {
    println!("Parsed successfully.");
}

🏗️ AST Structure

The parser generates a comprehensive AST with the following main structures:

  • Dockerfile: Root container for Dockerfile documents
  • Instruction: Dockerfile instructions (FROM, RUN, COPY, etc.)
  • Argument: Instruction arguments and parameters
  • Stage: Build stages in multi-stage builds
  • Comment: Dockerfile comments

📊 Performance

  • Streaming: Parse large Dockerfiles without loading entirely into memory
  • Incremental: Re-parse only changed sections
  • Memory Efficient: Smart AST node allocation
  • Fast Recovery: Quick error recovery for better IDE integration

🔗 Integration

Oak Dockerfile integrates seamlessly with:

  • Container Analysis: Analyze Dockerfiles for security and best practices
  • CI/CD Pipelines: Integrate with build and deployment workflows
  • IDE Support: Language server protocol compatibility
  • Security Scanning: Identify potential security issues in Dockerfiles
  • Optimization: Suggest optimizations for Dockerfile structure

📚 Examples

Check out the examples directory for comprehensive examples:

  • Complete Dockerfile parsing
  • Multi-stage build analysis
  • Security vulnerability detection
  • Integration with development workflows

🤝 Contributing

Contributions are welcome!

Please feel free to submit pull requests at the project repository or open issues.

Commit count: 80

cargo fmt