1

i need to generate a simple pretty standard docker compose content and update existing docker compose file with it. this yaml parser is looking good but couln't figure out the question mark thing it produces in its output.

here is my docker compose template file content:

version: "3.9"
name: "org"
services:
    memory:
        image: redis/redis-stack:7.2.0-v7
        # ...
networks:
    default:
        name: org
        external: true

im trying to add a new service to it:

import { readFile, writeFile } from 'node:fs/promises'
import { parseDocument } from 'yaml'

const doc = parseDocument(await readFile('./docker-compose.yml', 'utf8'))

doc.addIn(['services'], {
    'my-service': {
        'image': '${CONTAINER_CONN_STR}:${APP_VERSION:-latest}',
        'ports': ['${GDEVOPS_APP_PORT}:${APP_PORT}']
    }
})

await writeFile('./sample.yml', String(doc))

the output sample.yaml looks like this:

version: "3.9"
name: "org"
services:
    memory:
        image: redis/redis-stack:7.2.0-v7
        # ...
  ? my-service:
      image: ${CONTAINER_CONN_STR}:${APP_VERSION:-latest}
      ports:
        - ${GDEVOPS_APP_PORT}:${APP_PORT}
networks:
    default:
        name: org
        external: true

how can i get rid of that question mark in front of my service?

1 Answer 1

0

Pass option {simpleKeys: true} to the string generation, in your case:

await writeFile('./sample.yml', String(doc, {simpleKeys: true}))

From the documentation:

simpleKeys    boolean     false   Require keys to be scalars
                                  and always use implicit rather
                                  than explicit notation.

The question mark is named "explicit mapping key" in contrary to an "implict mapping key"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.