Socket
Socket
Sign inDemoInstall

dockerfile-ast

Package Overview
Dependencies
2
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dockerfile-ast

Parse a Dockerfile into an array of instructions and comments.


Version published
Maintainers
1
Install size
637 kB
Created

Changelog

Source

[0.6.1] - 2023-09-10

Fixed

  • consider empty tags correctly when a FROM instruction also has a digest specified (#113)

Readme

Source

Dockerfile AST

Node.js Builds Coverage Status Build Dependencies License: MIT npm downloads per week

The dockerfile-ast NPM module is a Dockerfile parser written in TypeScript. The module provides full programmatic access to a parsed Dockerfile.

Supported features:

  • escaped newline detection
    • escape parser directive considered when parsing
  • comments preserved
    • inlined comments in multiline instructions preserved
  • continuous empty newlines honoured (albeit discouraged as of Docker CE 17.09)
  • ARG and ENV variable lookup and resolution

Unsupported:

  • \r as a a line delimiter
    • only \r\n and \n are supported as being line delimiters
    • if a \r is detected the parser assumes that it is followed by a \n

Development Instructions

If you wish to build and compile this project, you must first install Node.js if you have not already done so. After you have installed Node.js and cloned the repository with Git, you may now proceed to build and compile the project with the following commands:

npm install
npm run build
npm test

If you are planning to change the code, use npm run watch to get the TypeScript files transpiled on-the-fly as they are modified.

Installation Instructions

To add this library as a dependency to your project, please add dockerfile-ast as a dependency in your package.json file.

Using this Module

import { DockerfileParser } from 'dockerfile-ast';

const content =
`FROM alpine
ExposE 8080`

let dockerfile = DockerfileParser.parse(content);
let instructions = dockerfile.getInstructions();
for (let instruction of instructions) {
  // FROM
  // EXPOSE
  console.log(instruction.getKeyword());
  // FROM
  // ExposE
  console.log(instruction.getInstruction());
}

Keywords

FAQs

Last updated on 10 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc