funkwerk / compose_format Goto Github PK
View Code? Open in Web Editor NEWformat docker compose files using recipes from best practices
License: MIT License
format docker compose files using recipes from best practices
License: MIT License
compose_format does not support the key 'shm_size' which is added in compose file version 3
I tried the image but it doesn't work. See following history (shell from host-system):
root@localhost: cat docker-compose.yml | docker run -i funkwerk/compose_format
Traceback (most recent call last):
File "/bin/compose_format", line 2, in <module>
from compose_format import ComposeFormat
File "/usr/lib/python3.5/site-packages/compose_format/__init__.py", line 1, in <module>
from ruamel.yaml import RoundTripDumper, RoundTripLoader, dump, load
ImportError: cannot import name 'RoundTripDumper'
root@localhost:/var/docker/source/main# docker --version
Docker version 19.03.2, build 6a30dfc
version: '3.3'
services:
nifi:
container_name: nifi
image: apache/nifi:1.7.1
environment:
NIFI_WEB_HTTP_PORT: '8443'
NIFI_WEB_PROXY_HOST: '0.0.0.0'
volumes:
- type: bind
source: ./certs
target: /opt/certs
- type: volume
target: /opt/nifi/nifi-1.7.1/conf
- type: volume
target: /opt/nifi/nifi-1.7.1/content_repository
- type: volume
target: /opt/nifi/nifi-1.7.1/database_repository
- type: volume
target: /opt/nifi/nifi-1.7.1/flowfile_repository
- type: volume
target: /opt/nifi/nifi-1.7.1/provenance_repository
- type: volume
target: /opt/nifi/nifi-1.7.1/logs
- type: volume
target: /opt/nifi/nifi-1.7.1/data
restart: always
network_mode: "host"
ports:
- 8443:8443
Give following error with the docker command:
Traceback (most recent call last):
File "/bin/compose_format", line 28, in <module>
formatted = formatter.format_string(data, strict=not args.non_strict)
File "/usr/lib/python3.5/site-packages/compose_format/__init__.py", line 77, in format_string
data = self.reorder(load(data, RoundTripLoader), strict=strict)
File "/usr/lib/python3.5/site-packages/compose_format/__init__.py", line 98, in reorder
ComposeFormat.reorder(item, strict)
File "/usr/lib/python3.5/site-packages/compose_format/__init__.py", line 98, in reorder
ComposeFormat.reorder(item, strict)
File "/usr/lib/python3.5/site-packages/compose_format/__init__.py", line 98, in reorder
ComposeFormat.reorder(item, strict)
File "/usr/lib/python3.5/site-packages/compose_format/__init__.py", line 101, in reorder
data.sort()
TypeError: unorderable types: CommentedMap() < CommentedMap()
Some configuration values should be quoted. Pls, take a look at this snippet:
version: '3'
services:
mysql:
image: mysql:latest
environment:
MYSQL_DATABASE: test
MYSQL_PASSWORD: test
# See: https://hub.docker.com/_/mysql
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: test
Linter removes quoting (MYSQL_RANDOM_ROOT_PASSWORD: yes
), so using this config will trigger an error services.mysql.environment.MYSQL_RANDOM_ROOT_PASSWORD contains true, which is an invalid type, it should be a string, number, or a null
. This means that it is not possible to leave value type specification after this linter usage.
Also, it breaks type specification like this !!str yes
.
Sorry, I am not familiar with ruamel.yaml
and can not create a proper pull request. Maybe do you know how to fix it?
There is a new service key profiles
since docker-compose v1.28: https://stackoverflow.com/a/65922688.
Using it leads to an error:
AssertionError: key: profiles not known
When I try do use it on my docker-compose.yaml
file, which is perfectly valid for the docker-compose command, I get:
Traceback (most recent call last):
File "/home/ser/.local/bin/compose_format", line 35, in <module>
if not formatter.format(path, replace=args.replace, strict=not args.non_strict):
File "/home/ser/.local/lib/python3.10/site-packages/compose_format/__init__.py", line 68, in format
formatted = self.format_string(data, replace=replace, strict=strict)
File "/home/ser/.local/lib/python3.10/site-packages/compose_format/__init__.py", line 78, in format_string
data = self.reorder(load(data, RoundTripLoader), strict=strict)
File "/home/ser/.local/lib/python3.10/site-packages/compose_format/__init__.py", line 99, in reorder
ComposeFormat.reorder(item, strict)
File "/home/ser/.local/lib/python3.10/site-packages/compose_format/__init__.py", line 99, in reorder
ComposeFormat.reorder(item, strict)
File "/home/ser/.local/lib/python3.10/site-packages/compose_format/__init__.py", line 99, in reorder
ComposeFormat.reorder(item, strict)
[Previous line repeated 1 more time]
File "/home/ser/.local/lib/python3.10/site-packages/compose_format/__init__.py", line 103, in reorder
data[i] = ComposeFormat.fix_sexadecimal_numbers(value)
File "/home/ser/.local/lib/python3.10/site-packages/compose_format/__init__.py", line 113, in fix_sexadecimal_numbers
match = re.match(SEXADECIMAL_NUMBER, value)
File "/usr/lib/python3.10/re.py", line 190, in match
return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object
See https://docs.docker.com/compose/compose-file/#extension-fields
Mine does not work with compose_format
:
version: '3.8'
x-common: &common
env_file:
- public.env
services:
app:
<<: *common
environment:
- APP_ENV=test
build:
context: .
...
place single quotes around system ports like '21:21'
docker-compose reference:
Note: When mapping ports in the HOST:CONTAINER format, you may experience erroneous results when using a container port lower than 60, because YAML will parse numbers in the format xx:yy as sexagesimal (base 60). For this reason, we recommend always explicitly specifying your port mappings as strings.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.