Add Makefile including spec download target

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2020-10-21 10:45:41 +02:00 committed by Ulysses Souza
parent a24843e1e4
commit 675c9674e1
8 changed files with 104 additions and 23 deletions

View File

@ -45,13 +45,14 @@ COPY docker-compose-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["sh", "/usr/local/bin/docker-compose-entrypoint.sh"] ENTRYPOINT ["sh", "/usr/local/bin/docker-compose-entrypoint.sh"]
COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker
WORKDIR /code/ WORKDIR /code/
# FIXME(chris-crone): virtualenv 16.3.0 breaks build, force 16.2.0 until fixed RUN pip install \
RUN pip install virtualenv==20.0.30 virtualenv==20.0.30 \
RUN pip install tox==3.19.0 tox==3.19.0
COPY requirements-dev.txt .
COPY requirements-indirect.txt . COPY requirements-indirect.txt .
COPY requirements.txt . COPY requirements.txt .
COPY requirements-dev.txt . RUN pip install -r requirements.txt -r requirements-indirect.txt -r requirements-dev.txt
COPY .pre-commit-config.yaml . COPY .pre-commit-config.yaml .
COPY tox.ini . COPY tox.ini .
COPY setup.py . COPY setup.py .

57
Makefile Normal file
View File

@ -0,0 +1,57 @@
TAG = "docker-compose:alpine-$(shell git rev-parse --short HEAD)"
GIT_VOLUME = "--volume=$(shell pwd)/.git:/code/.git"
DOCKERFILE ?="Dockerfile"
DOCKER_BUILD_TARGET ?="build"
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
BUILD_SCRIPT = linux
endif
ifeq ($(UNAME_S),Darwin)
BUILD_SCRIPT = osx
endif
COMPOSE_SPEC_SCHEMA_PATH = "compose/config/config_schema_compose_spec.json"
COMPOSE_SPEC_RAW_URL = "https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"
all: cli
cli: download-compose-spec ## Compile the cli
./script/build/$(BUILD_SCRIPT)
download-compose-spec: ## Download the compose-spec schema from it's repo
curl -so $(COMPOSE_SPEC_SCHEMA_PATH) $(COMPOSE_SPEC_RAW_URL)
cache-clear: ## Clear the builder cache
@docker builder prune --force --filter type=exec.cachemount --filter=unused-for=24h
base-image: ## Builds base image
docker build -f $(DOCKERFILE) -t $(TAG) --target $(DOCKER_BUILD_TARGET) .
lint: base-image ## Run linter
docker run --rm \
--tty \
$(GIT_VOLUME) \
$(TAG) \
tox -e pre-commit
test-unit: base-image ## Run tests
docker run --rm \
--tty \
$(GIT_VOLUME) \
$(TAG) \
pytest -v tests/unit/
test: ## Run all tests
./script/test/default
pre-commit: lint test-unit cli
help: ## Show help
@echo Please specify a build target. The choices are:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
FORCE:
.PHONY: all cli download-compose-spec cache-clear base-image lint test-unit test pre-commit help

View File

@ -1,14 +1,16 @@
{ {
"$schema": "http://json-schema.org/draft/2019-09/schema#", "$schema": "http://json-schema.org/draft/2019-09/schema#",
"id": "config_schema_compose_spec.json", "id": "compose_spec.json",
"type": "object", "type": "object",
"title": "Compose Specification", "title": "Compose Specification",
"description": "The Compose file is a YAML file defining a multi-containers based application.", "description": "The Compose file is a YAML file defining a multi-containers based application.",
"properties": { "properties": {
"version": { "version": {
"type": "string", "type": "string",
"description": "Version of the Compose specification used. Tools not implementing required version MUST reject the configuration file." "description": "Version of the Compose specification used. Tools not implementing required version MUST reject the configuration file."
}, },
"services": { "services": {
"id": "#/properties/services", "id": "#/properties/services",
"type": "object", "type": "object",
@ -19,6 +21,7 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"networks": { "networks": {
"id": "#/properties/networks", "id": "#/properties/networks",
"type": "object", "type": "object",
@ -28,6 +31,7 @@
} }
} }
}, },
"volumes": { "volumes": {
"id": "#/properties/volumes", "id": "#/properties/volumes",
"type": "object", "type": "object",
@ -38,6 +42,7 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"secrets": { "secrets": {
"id": "#/properties/secrets", "id": "#/properties/secrets",
"type": "object", "type": "object",
@ -48,6 +53,7 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"configs": { "configs": {
"id": "#/properties/configs", "id": "#/properties/configs",
"type": "object", "type": "object",
@ -59,12 +65,16 @@
"additionalProperties": false "additionalProperties": false
} }
}, },
"patternProperties": {"^x-": {}}, "patternProperties": {"^x-": {}},
"additionalProperties": false, "additionalProperties": false,
"definitions": { "definitions": {
"service": { "service": {
"id": "#/definitions/service", "id": "#/definitions/service",
"type": "object", "type": "object",
"properties": { "properties": {
"deploy": {"$ref": "#/definitions/deployment"}, "deploy": {"$ref": "#/definitions/deployment"},
"build": { "build": {
@ -190,7 +200,6 @@
"device_cgroup_rules": {"$ref": "#/definitions/list_of_strings"}, "device_cgroup_rules": {"$ref": "#/definitions/list_of_strings"},
"devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"dns": {"$ref": "#/definitions/string_or_list"}, "dns": {"$ref": "#/definitions/string_or_list"},
"dns_opt": {"type": "array","items": {"type": "string"}, "uniqueItems": true}, "dns_opt": {"type": "array","items": {"type": "string"}, "uniqueItems": true},
"dns_search": {"$ref": "#/definitions/string_or_list"}, "dns_search": {"$ref": "#/definitions/string_or_list"},
"domainname": {"type": "string"}, "domainname": {"type": "string"},
@ -211,12 +220,12 @@
}, },
"uniqueItems": true "uniqueItems": true
}, },
"extends": { "extends": {
"oneOf": [ "oneOf": [
{"type": "string"}, {"type": "string"},
{ {
"type": "object", "type": "object",
"properties": { "properties": {
"service": {"type": "string"}, "service": {"type": "string"},
"file": {"type": "string"} "file": {"type": "string"}
@ -245,6 +254,7 @@
"links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"logging": { "logging": {
"type": "object", "type": "object",
"properties": { "properties": {
"driver": {"type": "string"}, "driver": {"type": "string"},
"options": { "options": {
@ -258,7 +268,7 @@
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
}, },
"mac_address": {"type": "string"}, "mac_address": {"type": "string"},
"mem_limit": {"type": "string"}, "mem_limit": {"type": ["number", "string"]},
"mem_reservation": {"type": ["string", "integer"]}, "mem_reservation": {"type": ["string", "integer"]},
"mem_swappiness": {"type": "integer"}, "mem_swappiness": {"type": "integer"},
"memswap_limit": {"type": ["number", "string"]}, "memswap_limit": {"type": ["number", "string"]},
@ -425,9 +435,9 @@
"additionalProperties": false, "additionalProperties": false,
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
} }
], ]
"uniqueItems": true },
} "uniqueItems": true
}, },
"volumes_from": { "volumes_from": {
"type": "array", "type": "array",
@ -558,6 +568,7 @@
"additionalProperties": false, "additionalProperties": false,
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
}, },
"generic_resources": { "generic_resources": {
"id": "#/definitions/generic_resources", "id": "#/definitions/generic_resources",
"type": "array", "type": "array",
@ -578,6 +589,7 @@
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
} }
}, },
"network": { "network": {
"id": "#/definitions/network", "id": "#/definitions/network",
"type": ["object", "null"], "type": ["object", "null"],
@ -607,10 +619,10 @@
"additionalProperties": false, "additionalProperties": false,
"patternProperties": {"^.+$": {"type": "string"}} "patternProperties": {"^.+$": {"type": "string"}}
} }
} },
}, "additionalProperties": false,
"additionalProperties": false, "patternProperties": {"^x-": {}}
"patternProperties": {"^x-": {}} }
}, },
"options": { "options": {
"type": "object", "type": "object",
@ -640,6 +652,7 @@
"additionalProperties": false, "additionalProperties": false,
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
}, },
"volume": { "volume": {
"id": "#/definitions/volume", "id": "#/definitions/volume",
"type": ["object", "null"], "type": ["object", "null"],
@ -668,6 +681,7 @@
"additionalProperties": false, "additionalProperties": false,
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
}, },
"secret": { "secret": {
"id": "#/definitions/secret", "id": "#/definitions/secret",
"type": "object", "type": "object",
@ -693,6 +707,7 @@
"additionalProperties": false, "additionalProperties": false,
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
}, },
"config": { "config": {
"id": "#/definitions/config", "id": "#/definitions/config",
"type": "object", "type": "object",
@ -714,17 +729,20 @@
"additionalProperties": false, "additionalProperties": false,
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
}, },
"string_or_list": { "string_or_list": {
"oneOf": [ "oneOf": [
{"type": "string"}, {"type": "string"},
{"$ref": "#/definitions/list_of_strings"} {"$ref": "#/definitions/list_of_strings"}
] ]
}, },
"list_of_strings": { "list_of_strings": {
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"type": "string"},
"uniqueItems": true "uniqueItems": true
}, },
"list_or_dict": { "list_or_dict": {
"oneOf": [ "oneOf": [
{ {
@ -739,6 +757,7 @@
{"type": "array", "items": {"type": "string"}, "uniqueItems": true} {"type": "array", "items": {"type": "string"}, "uniqueItems": true}
] ]
}, },
"blkio_limit": { "blkio_limit": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -755,6 +774,7 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"constraints": { "constraints": {
"service": { "service": {
"id": "#/definitions/constraints/service", "id": "#/definitions/constraints/service",

View File

@ -502,13 +502,13 @@ def get_schema_path():
def load_jsonschema(version): def load_jsonschema(version):
suffix = "compose_spec" name = "compose_spec"
if version == V1: if version == V1:
suffix = "v1" name = "config_schema_v1"
filename = os.path.join( filename = os.path.join(
get_schema_path(), get_schema_path(),
"config_schema_{}.json".format(suffix)) "{}.json".format(name))
if not os.path.exists(filename): if not os.path.exists(filename):
raise ConfigurationError( raise ConfigurationError(

View File

@ -23,8 +23,8 @@ exe = EXE(pyz,
'DATA' 'DATA'
), ),
( (
'compose/config/config_schema_compose_spec.json', 'compose/config/compose_spec.json',
'compose/config/config_schema_compose_spec.json', 'compose/config/compose_spec.json',
'DATA' 'DATA'
), ),
( (

View File

@ -32,8 +32,8 @@ coll = COLLECT(exe,
'DATA' 'DATA'
), ),
( (
'compose/config/config_schema_compose_spec.json', 'compose/config/compose_spec.json',
'compose/config/config_schema_compose_spec.json', 'compose/config/compose_spec.json',
'DATA' 'DATA'
), ),
( (

View File

@ -7,3 +7,4 @@ mock==3.0.5
pytest==6.0.1; python_version >= '3.5' pytest==6.0.1; python_version >= '3.5'
pytest==4.6.5; python_version < '3.5' pytest==4.6.5; python_version < '3.5'
pytest-cov==2.10.1 pytest-cov==2.10.1
PyYAML==5.3.1

View File

@ -238,7 +238,9 @@ class ConfigTest(unittest.TestCase):
) )
) )
assert 'Invalid top-level property "web"' in excinfo.exconly() assert "compose.config.errors.ConfigurationError: " \
"The Compose file 'filename.yml' is invalid because:\n" \
"'web' does not match any of the regexes: '^x-'" in excinfo.exconly()
assert VERSION_EXPLANATION in excinfo.exconly() assert VERSION_EXPLANATION in excinfo.exconly()
def test_named_volume_config_empty(self): def test_named_volume_config_empty(self):