diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-12-02 01:45:21 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-12-02 02:42:50 +0300 |
commit | 9c43d58f75cf086b744cf4fe2ae180e8f37e4a0c (patch) | |
tree | 9f88a486917d371d099cd712efd91b4c122d209d /library/recipes | |
parent | 32fb6dda1feb24f9ab69ece5df0cb9ec238ca5e6 (diff) | |
download | ydb-9c43d58f75cf086b744cf4fe2ae180e8f37e4a0c.tar.gz |
Intermediate changes
Diffstat (limited to 'library/recipes')
66 files changed, 715 insertions, 12 deletions
diff --git a/library/recipes/docker_compose/example/Dockerfile b/library/recipes/docker_compose/example/Dockerfile new file mode 100644 index 0000000000..8e67d74e89 --- /dev/null +++ b/library/recipes/docker_compose/example/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +RUN pip install -r requirements.txt +CMD ["python", "app.py"] diff --git a/library/recipes/docker_compose/example/app.py b/library/recipes/docker_compose/example/app.py new file mode 100644 index 0000000000..77afcc9b6a --- /dev/null +++ b/library/recipes/docker_compose/example/app.py @@ -0,0 +1,17 @@ +import time + +import redis +from flask import Flask + + +app = Flask(__name__) +cache = redis.Redis(host='redis', port=6379) + + +@app.route('/') +def hello(): + return 'Hello World!' + + +if __name__ == "__main__": + app.run(host="0.0.0.0", debug=True) diff --git a/library/recipes/docker_compose/example/docker-compose.yml b/library/recipes/docker_compose/example/docker-compose.yml new file mode 100644 index 0000000000..780f263945 --- /dev/null +++ b/library/recipes/docker_compose/example/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.4' +services: + web: + build: + context: . + network: host + ports: + - "5000:5000" + redis: + image: "redis:alpine@sha256:66ccc75f079ab9059c900e9545bbd271bff78a66f94b45827e6901f57fb973f1" diff --git a/library/recipes/docker_compose/example/requirements.txt b/library/recipes/docker_compose/example/requirements.txt new file mode 100644 index 0000000000..1a5dc97b12 --- /dev/null +++ b/library/recipes/docker_compose/example/requirements.txt @@ -0,0 +1,2 @@ +flask +redis diff --git a/library/recipes/docker_compose/example/test.py b/library/recipes/docker_compose/example/test.py new file mode 100644 index 0000000000..c6769eab7f --- /dev/null +++ b/library/recipes/docker_compose/example/test.py @@ -0,0 +1,7 @@ +import urllib.request + + +def test_compose_works(): + request = urllib.request.urlopen("http://localhost:5000") + response = request.read().decode(request.headers.get_content_charset()) + assert 'Hello World!' in response diff --git a/library/recipes/docker_compose/example/ya.make b/library/recipes/docker_compose/example/ya.make new file mode 100644 index 0000000000..96029ca075 --- /dev/null +++ b/library/recipes/docker_compose/example/ya.make @@ -0,0 +1,19 @@ +PY3TEST() + +TEST_SRCS( + test.py +) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox +) + +END() diff --git a/library/recipes/docker_compose/example_network_go/Dockerfile b/library/recipes/docker_compose/example_network_go/Dockerfile new file mode 100644 index 0000000000..96fa38bd48 --- /dev/null +++ b/library/recipes/docker_compose/example_network_go/Dockerfile @@ -0,0 +1 @@ +FROM ubuntu:xenial diff --git a/library/recipes/docker_compose/example_network_go/docker-compose.yml b/library/recipes/docker_compose/example_network_go/docker-compose.yml new file mode 100644 index 0000000000..4122b00537 --- /dev/null +++ b/library/recipes/docker_compose/example_network_go/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.4' +services: + test: + build: + context: . + redis: + image: "redis:alpine@sha256:66ccc75f079ab9059c900e9545bbd271bff78a66f94b45827e6901f57fb973f1" + hostname: redis + +networks: + default: + external: + name: example_network_go_test diff --git a/library/recipes/docker_compose/example_network_go/go_test.go b/library/recipes/docker_compose/example_network_go/go_test.go new file mode 100644 index 0000000000..76d37ede76 --- /dev/null +++ b/library/recipes/docker_compose/example_network_go/go_test.go @@ -0,0 +1,21 @@ +package example + +import ( + "context" + "testing" + + "github.com/go-redis/redis/v8" + "github.com/stretchr/testify/require" +) + +func TestFoo(t *testing.T) { + c := redis.NewUniversalClient( + &redis.UniversalOptions{ + Addrs: []string{"redis:6379"}, + }, + ) + + sc := c.Ping(context.Background()) + require.NoError(t, sc.Err()) + t.Log(sc) +} diff --git a/library/recipes/docker_compose/example_network_go/recipe-config.yml b/library/recipes/docker_compose/example_network_go/recipe-config.yml new file mode 100644 index 0000000000..cef53ef20c --- /dev/null +++ b/library/recipes/docker_compose/example_network_go/recipe-config.yml @@ -0,0 +1,5 @@ +test-host: test + +networks: + example_network_go_test: + ipv6: true diff --git a/library/recipes/docker_compose/example_network_go/ya.make b/library/recipes/docker_compose/example_network_go/ya.make new file mode 100644 index 0000000000..569d6290f4 --- /dev/null +++ b/library/recipes/docker_compose/example_network_go/ya.make @@ -0,0 +1,19 @@ +GO_TEST() + +GO_TEST_SRCS(go_test.go) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +SET(RECIPE_CONFIG_FILE library/recipes/docker_compose/example_network_go/recipe-config.yml) +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox + ya:dirty +) + +END() diff --git a/library/recipes/docker_compose/example_test_container/Dockerfile b/library/recipes/docker_compose/example_test_container/Dockerfile new file mode 100644 index 0000000000..be2ca6ee27 --- /dev/null +++ b/library/recipes/docker_compose/example_test_container/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu:xenial +ADD . /code diff --git a/library/recipes/docker_compose/example_test_container/docker-compose.yml b/library/recipes/docker_compose/example_test_container/docker-compose.yml new file mode 100644 index 0000000000..6a3af8615b --- /dev/null +++ b/library/recipes/docker_compose/example_test_container/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3.4' +services: + test: + build: + context: . + redis: + image: "redis:alpine@sha256:66ccc75f079ab9059c900e9545bbd271bff78a66f94b45827e6901f57fb973f1" diff --git a/library/recipes/docker_compose/example_test_container/test.py b/library/recipes/docker_compose/example_test_container/test.py new file mode 100644 index 0000000000..980943f48a --- /dev/null +++ b/library/recipes/docker_compose/example_test_container/test.py @@ -0,0 +1,5 @@ +import os + + +def test_compose_works(): + assert os.path.exists("/code") diff --git a/library/recipes/docker_compose/example_test_container/ya.make b/library/recipes/docker_compose/example_test_container/ya.make new file mode 100644 index 0000000000..89f6b21a97 --- /dev/null +++ b/library/recipes/docker_compose/example_test_container/ya.make @@ -0,0 +1,19 @@ +PY3TEST() + +TEST_SRCS(test.py) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +SET(DOCKER_TEST_HOST test) +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox + ya:dirty +) + +END() diff --git a/library/recipes/docker_compose/example_test_container_go/Dockerfile b/library/recipes/docker_compose/example_test_container_go/Dockerfile new file mode 100644 index 0000000000..be2ca6ee27 --- /dev/null +++ b/library/recipes/docker_compose/example_test_container_go/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu:xenial +ADD . /code diff --git a/library/recipes/docker_compose/example_test_container_go/docker-compose.yml b/library/recipes/docker_compose/example_test_container_go/docker-compose.yml new file mode 100644 index 0000000000..6a3af8615b --- /dev/null +++ b/library/recipes/docker_compose/example_test_container_go/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3.4' +services: + test: + build: + context: . + redis: + image: "redis:alpine@sha256:66ccc75f079ab9059c900e9545bbd271bff78a66f94b45827e6901f57fb973f1" diff --git a/library/recipes/docker_compose/example_test_container_go/go_test.go b/library/recipes/docker_compose/example_test_container_go/go_test.go new file mode 100644 index 0000000000..1771ccfc38 --- /dev/null +++ b/library/recipes/docker_compose/example_test_container_go/go_test.go @@ -0,0 +1,13 @@ +package example + +import ( + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestFoo(t *testing.T) { + _, err := os.Stat("/code") + require.NoError(t, err) +} diff --git a/library/recipes/docker_compose/example_test_container_go/ya.make b/library/recipes/docker_compose/example_test_container_go/ya.make new file mode 100644 index 0000000000..dd31291009 --- /dev/null +++ b/library/recipes/docker_compose/example_test_container_go/ya.make @@ -0,0 +1,19 @@ +GO_TEST() + +GO_TEST_SRCS(go_test.go) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +SET(DOCKER_TEST_HOST test) +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox + ya:dirty +) + +END() diff --git a/library/recipes/docker_compose/example_with_context/docker-compose.yml b/library/recipes/docker_compose/example_with_context/docker-compose.yml new file mode 100644 index 0000000000..d92d094247 --- /dev/null +++ b/library/recipes/docker_compose/example_with_context/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.4' +services: + sweb: + build: + context: $main + network: host + ports: + - "5000:5000" + redis: + image: "redis:alpine@sha256:66ccc75f079ab9059c900e9545bbd271bff78a66f94b45827e6901f57fb973f1" diff --git a/library/recipes/docker_compose/example_with_context/docker-context.yml b/library/recipes/docker_compose/example_with_context/docker-context.yml new file mode 100644 index 0000000000..19adc96fad --- /dev/null +++ b/library/recipes/docker_compose/example_with_context/docker-context.yml @@ -0,0 +1,5 @@ +main: + - build://devtools/dummy_arcadia/hello_world/hello_world: bin/hello + - arcadia://library/recipes/docker_compose/example/Dockerfile: Dockerfile + - arcadia://library/recipes/docker_compose/example/app.py: app.py + - arcadia://library/recipes/docker_compose/example/requirements.txt: requirements.txt diff --git a/library/recipes/docker_compose/example_with_context/test.py b/library/recipes/docker_compose/example_with_context/test.py new file mode 100644 index 0000000000..b7f13fb105 --- /dev/null +++ b/library/recipes/docker_compose/example_with_context/test.py @@ -0,0 +1,9 @@ +import urllib.request + + +def test_compose_works(): + # import pdb; pdb.set_trace() + + request = urllib.request.urlopen("http://localhost:5000") + response = request.read().decode(request.headers.get_content_charset()) + assert 'Hello World!' in response diff --git a/library/recipes/docker_compose/example_with_context/ya.make b/library/recipes/docker_compose/example_with_context/ya.make new file mode 100644 index 0000000000..b1dde5e827 --- /dev/null +++ b/library/recipes/docker_compose/example_with_context/ya.make @@ -0,0 +1,29 @@ +PY3TEST() + +TEST_SRCS( + test.py +) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +SET(DOCKER_CONTEXT_FILE library/recipes/docker_compose/example_with_context/docker-context.yml) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox +) + +DATA( + arcadia/library/recipes/docker_compose/example +) + +DEPENDS( + devtools/dummy_arcadia/hello_world +) + +END() diff --git a/library/recipes/docker_compose/example_with_recipe_config/Dockerfile b/library/recipes/docker_compose/example_with_recipe_config/Dockerfile new file mode 100644 index 0000000000..1079e205b5 --- /dev/null +++ b/library/recipes/docker_compose/example_with_recipe_config/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu:xenial +ADD . /app diff --git a/library/recipes/docker_compose/example_with_recipe_config/docker-compose.yml b/library/recipes/docker_compose/example_with_recipe_config/docker-compose.yml new file mode 100644 index 0000000000..20419b32eb --- /dev/null +++ b/library/recipes/docker_compose/example_with_recipe_config/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3.4' +services: + test: + build: + context: $main + diff --git a/library/recipes/docker_compose/example_with_recipe_config/recipe-config.yml b/library/recipes/docker_compose/example_with_recipe_config/recipe-config.yml new file mode 100644 index 0000000000..278ceb6521 --- /dev/null +++ b/library/recipes/docker_compose/example_with_recipe_config/recipe-config.yml @@ -0,0 +1,10 @@ +test-host: test # name of container to execute test in + +context: # contexts to build images + main: + - build://devtools/dummy_arcadia/hello_world/hello_world: bin/hello + - arcadia://library/recipes/docker_compose/example_with_recipe_config/Dockerfile: Dockerfile + +save: + test: + - /tmp/output
\ No newline at end of file diff --git a/library/recipes/docker_compose/example_with_recipe_config/test.py b/library/recipes/docker_compose/example_with_recipe_config/test.py new file mode 100644 index 0000000000..08c4d7b6e5 --- /dev/null +++ b/library/recipes/docker_compose/example_with_recipe_config/test.py @@ -0,0 +1,12 @@ +import os +import logging + +import yatest.common + + +def test(): + os.makedirs("/tmp/output") + with open("/tmp/output/out.txt", "w") as f: + res = yatest.common.execute("/app/bin/hello") + f.write("/bin/hello stdout: {}".format(res.std_out)) + logging.info("out: %s", res.std_out) diff --git a/library/recipes/docker_compose/example_with_recipe_config/ya.make b/library/recipes/docker_compose/example_with_recipe_config/ya.make new file mode 100644 index 0000000000..3ab2889a01 --- /dev/null +++ b/library/recipes/docker_compose/example_with_recipe_config/ya.make @@ -0,0 +1,27 @@ +PY3TEST() + +OWNER(g:yatool) + +TEST_SRCS( + test.py +) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +SET(RECIPE_CONFIG_FILE library/recipes/docker_compose/example_with_recipe_config/recipe-config.yml) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox +) + +DEPENDS( + devtools/dummy_arcadia/hello_world +) + +END() diff --git a/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/Dockerfile b/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/Dockerfile new file mode 100644 index 0000000000..be2ca6ee27 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu:xenial +ADD . /code diff --git a/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/docker-compose.yml b/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/docker-compose.yml new file mode 100644 index 0000000000..5eef027d27 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.4' +services: + test: + user: $CURRENT_UID + build: + context: . + redis: + image: "redis:alpine@sha256:66ccc75f079ab9059c900e9545bbd271bff78a66f94b45827e6901f57fb973f1" diff --git a/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/test.py b/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/test.py new file mode 100644 index 0000000000..980943f48a --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/test.py @@ -0,0 +1,5 @@ +import os + + +def test_compose_works(): + assert os.path.exists("/code") diff --git a/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/ya.make b/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/ya.make new file mode 100644 index 0000000000..4e623da45d --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/invalid_test_container_name/ya.make @@ -0,0 +1,24 @@ +PY3TEST() + +OWNER(g:yatool) + +TEST_SRCS( + test.py +) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +SET(DOCKER_TEST_HOST not_existing_container_name) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox + ya:dirty +) + +END() diff --git a/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/Dockerfile b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/Dockerfile new file mode 100644 index 0000000000..be2ca6ee27 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu:xenial +ADD . /code diff --git a/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/docker-compose.yml b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/docker-compose.yml new file mode 100644 index 0000000000..39a25fc869 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3.4' +services: + test: + user: $CURRENT_UID + build: + context: . + command: 'echo "say hello"' + redis: + image: "redis:alpine@sha256:66ccc75f079ab9059c900e9545bbd271bff78a66f94b45827e6901f57fb973f1" diff --git a/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/test.py b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/test.py new file mode 100644 index 0000000000..980943f48a --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/test.py @@ -0,0 +1,5 @@ +import os + + +def test_compose_works(): + assert os.path.exists("/code") diff --git a/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/ya.make b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/ya.make new file mode 100644 index 0000000000..6ea9fdfc8a --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_command/ya.make @@ -0,0 +1,24 @@ +PY3TEST() + +OWNER(g:yatool) + +TEST_SRCS( + test.py +) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +SET(DOCKER_TEST_HOST test) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox + ya:dirty +) + +END() diff --git a/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/Dockerfile b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/Dockerfile new file mode 100644 index 0000000000..be2ca6ee27 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu:xenial +ADD . /code diff --git a/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/docker-compose.yml b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/docker-compose.yml new file mode 100644 index 0000000000..798539866c --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.4' +services: + test: + build: + context: . + user: 'root:root' + redis: + image: "redis:alpine@sha256:66ccc75f079ab9059c900e9545bbd271bff78a66f94b45827e6901f57fb973f1" diff --git a/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/test.py b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/test.py new file mode 100644 index 0000000000..980943f48a --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/test.py @@ -0,0 +1,5 @@ +import os + + +def test_compose_works(): + assert os.path.exists("/code") diff --git a/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/ya.make b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/ya.make new file mode 100644 index 0000000000..6ea9fdfc8a --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_container_with_existing_user/ya.make @@ -0,0 +1,24 @@ +PY3TEST() + +OWNER(g:yatool) + +TEST_SRCS( + test.py +) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +SET(DOCKER_TEST_HOST test) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox + ya:dirty +) + +END() diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/docker-compose.yml b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/docker-compose.yml new file mode 100644 index 0000000000..73f93866e9 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3.4' +services: + srv1: + build: srv1 + srv2: + build: srv2 diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv1/Dockerfile b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv1/Dockerfile new file mode 100644 index 0000000000..3b871be284 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv1/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +CMD ["python", "app.py"] diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv1/app.py b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv1/app.py new file mode 100644 index 0000000000..244a421fe3 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv1/app.py @@ -0,0 +1,2 @@ +if __name__ == "__main__": + pass diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv2/Dockerfile b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv2/Dockerfile new file mode 100644 index 0000000000..3b871be284 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv2/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +CMD ["python", "app.py"] diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv2/app.py b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv2/app.py new file mode 100644 index 0000000000..cfff70f109 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/srv2/app.py @@ -0,0 +1,6 @@ +import time + + +if __name__ == "__main__": + while True: + time.sleep(1) diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/test.py b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/test.py new file mode 100644 index 0000000000..fe819e6c1a --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/test.py @@ -0,0 +1,2 @@ +def test_simple(): + return diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/ya.make b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/ya.make new file mode 100644 index 0000000000..01260fb7e5 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_exit_0/ya.make @@ -0,0 +1,21 @@ +PY3TEST() + +OWNER(g:yatool) + +TEST_SRCS( + test.py +) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox +) + +END() diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/docker-compose.yml b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/docker-compose.yml new file mode 100644 index 0000000000..73f93866e9 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3.4' +services: + srv1: + build: srv1 + srv2: + build: srv2 diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv1/Dockerfile b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv1/Dockerfile new file mode 100644 index 0000000000..3b871be284 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv1/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +CMD ["python", "app.py"] diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv1/app.py b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv1/app.py new file mode 100644 index 0000000000..55b1ce720e --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv1/app.py @@ -0,0 +1,5 @@ +import sys + + +if __name__ == "__main__": + sys.exit(5) diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv2/Dockerfile b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv2/Dockerfile new file mode 100644 index 0000000000..3b871be284 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv2/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +CMD ["python", "app.py"] diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv2/app.py b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv2/app.py new file mode 100644 index 0000000000..cfff70f109 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/srv2/app.py @@ -0,0 +1,6 @@ +import time + + +if __name__ == "__main__": + while True: + time.sleep(1) diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/test.py b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/test.py new file mode 100644 index 0000000000..fe819e6c1a --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/test.py @@ -0,0 +1,2 @@ +def test_simple(): + return diff --git a/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/ya.make b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/ya.make new file mode 100644 index 0000000000..01260fb7e5 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/data/test_recipe_container_fail/ya.make @@ -0,0 +1,21 @@ +PY3TEST() + +OWNER(g:yatool) + +TEST_SRCS( + test.py +) + +# To use docker-compose.yml from another directory, set DOCKER_COMPOSE_FILE variable with Arcadia relative path to the file +# and do not forget to add the directory to the DATA macro, e.g.: +# SET(DOCKER_COMPOSE_FILE library/recipes/docker_compose/test/docker-compose-1.yml) +# DATA(arcadia/library/recipes/docker_compose/test) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/recipe.inc) + +TAG( + ya:external + ya:force_sandbox +) + +END() diff --git a/library/recipes/docker_compose/test/acceptance/test_docker_compose.py b/library/recipes/docker_compose/test/acceptance/test_docker_compose.py new file mode 100644 index 0000000000..8253f63392 --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/test_docker_compose.py @@ -0,0 +1,92 @@ +# coding: utf-8 + +import os + +import test.tests.common as tests_common +import yatest.common + + +class TestDockerCompose(tests_common.YaTest): + + def test_run(self): + res = self.run_ya_make_test(cwd=yatest.common.source_path("library/recipes/docker_compose/example"), args=["-A", "--test-type", "py3test"]) + assert res.get_tests_count() == 1 + assert res.get_suites_count() == 1 + + res.verify_test("test.py", "test_compose_works", "OK") + for output_type in ['std_out', 'std_err']: + assert os.path.exists(os.path.join( + res.output_root, "library/recipes/docker_compose/example", + "test-results", "py3test", "testing_out_stuff", "containers", "example_redis_1", "container_{}.log".format(output_type) + )) + assert os.path.exists(os.path.join( + res.output_root, "library/recipes/docker_compose/example", + "test-results", "py3test", "testing_out_stuff", "containers", "example_web_1", "container_{}.log".format(output_type) + )) + + def test_run_with_context(self): + res = self.run_ya_make_test(cwd=yatest.common.source_path("library/recipes/docker_compose/example_with_context"), args=["-A", "--test-type", "py3test"]) + assert res.get_tests_count() == 1 + assert res.get_suites_count() == 1 + + res.verify_test("test.py", "test_compose_works", "OK") + + def test_run_test_in_container(self): + with open("stdin", "wb") as stdin: + # need to pass stdin as docker-compose exec needs it (it runs `docker exec --interactive`) + res = self.run_ya_make_test( + cwd=yatest.common.source_path("library/recipes/docker_compose/example_test_container"), args=["-A", "--test-type", "py3test"], stdin=stdin) + assert res.get_tests_count() == 1 + assert res.get_suites_count() == 1 + + res.verify_test("test.py", "test_compose_works", "OK") + + def test_invalid_test_container_name(self): + res = self.run_ya_make_test(cwd=yatest.common.test_source_path("data/invalid_test_container_name"), args=["-A", "--test-type", "py3test"]) + assert res.get_tests_count() == 0 + assert res.get_suites_count() == 1 + assert "Service with name 'not_existing_container_name' was not found to be setup as a host for running test" in res.err + + def test_container_with_existing_command(self): + res = self.run_ya_make_test(cwd=yatest.common.test_source_path("data/test_container_with_existing_command"), args=["-A", "--test-type", "py3test"]) + assert res.get_tests_count() == 0 + assert res.get_suites_count() == 1 + assert "Test hosting service 'test' has `command` section which is not supported by testing framework" in res.err + + def test_container_with_existing_user(self): + res = self.run_ya_make_test(cwd=yatest.common.test_source_path("data/test_container_with_existing_user"), args=["-A", "--test-type", "py3test"]) + assert res.get_tests_count() == 0 + assert res.get_suites_count() == 1 + assert "Test hosting service 'test' has `user` section which is not supported by testing framework" in res.err + + def test_run_with_recipe_config(self): + with open("stdin", "wb") as stdin: + # need to pass stdin as docker-compose exec needs it (it runs `docker exec --interactive` + res = self.run_ya_make_test( + cwd=yatest.common.source_path("library/recipes/docker_compose/example_with_recipe_config"), + args=["-A", "--test-type", "py3test"], + stdin=stdin + ) + + assert res.get_tests_count() == 1 + assert res.get_suites_count() == 1 + + res.verify_test("test.py", "test", "OK") + + assert os.path.exists(os.path.join( + res.output_root, + "library/recipes/docker_compose/example_with_recipe_config/test-results/py3test/testing_out_stuff/containers/py3test_test_1/output/", + "out.txt", + )) + + def test_recipe_container_exit_0(self): + res = self.run_ya_make_test(cwd=yatest.common.test_source_path("data/test_recipe_container_exit_0"), + args=["-A", "--test-type", "py3test"]) + res.verify_test("test.py", "test_simple", "OK") + + def test_recipe_container_fail(self): + res = self.run_ya_make_test(cwd=yatest.common.test_source_path("data/test_recipe_container_fail"), + args=["-A", "--test-type", "py3test"]) + assert "DockerComposeRecipeException" in res.err + assert "Has failed containers" in res.err + assert "srv1" in res.err diff --git a/library/recipes/docker_compose/test/acceptance/ya.make b/library/recipes/docker_compose/test/acceptance/ya.make new file mode 100644 index 0000000000..069ac4257c --- /dev/null +++ b/library/recipes/docker_compose/test/acceptance/ya.make @@ -0,0 +1,40 @@ + +PY3TEST() + +TEST_SRCS( + test_docker_compose.py +) + +INCLUDE(${ARCADIA_ROOT}/library/recipes/docker_compose/large.inc) +INCLUDE(${ARCADIA_ROOT}/devtools/ya/chameleon_bin/recipe.inc) + +TAG( + ya:external + ya:force_sandbox + ya:dirty +) + +REQUIREMENTS( + container:4467981730 # bionic with fuse allowed + cpu:all + dns:dns64 +) + +DATA( + arcadia/library/recipes/docker_compose/example + arcadia/library/recipes/docker_compose/example_with_context + arcadia/library/recipes/docker_compose/example_test_container + arcadia/library/recipes/docker_compose/example_with_recipe_config +) + +PEERDIR( + devtools/ya/test/tests/lib/common +) + +DEPENDS( + devtools/ya/test/programs/test_tool/bin + devtools/ya/test/programs/test_tool/bin3 + devtools/ymake/bin +) + +END() diff --git a/library/recipes/docker_compose/test/ut/context.yml b/library/recipes/docker_compose/test/ut/context.yml new file mode 100644 index 0000000000..655bd657aa --- /dev/null +++ b/library/recipes/docker_compose/test/ut/context.yml @@ -0,0 +1,9 @@ +context1: + - arcadia://library/recipes/docker_compose/test/ut/data/dir1: dir1 + - arcadia://library/recipes/docker_compose/test/ut/data/dir2: dir1/dir2 + - arcadia://library/recipes/docker_compose/test/ut/data/file1.txt: file1.txt + - arcadia://library/recipes/docker_compose/test/ut/data/file2.txt: dir1/file2.txt + - build://devtools/dummy_arcadia/hello_world/hello_world: dir1/hello + +context2: + - arcadia://library/recipes/docker_compose/test/ut/data/file1.txt: file1.txt
\ No newline at end of file diff --git a/library/recipes/docker_compose/test/ut/data/dir1/file3.txt b/library/recipes/docker_compose/test/ut/data/dir1/file3.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/library/recipes/docker_compose/test/ut/data/dir1/file3.txt diff --git a/library/recipes/docker_compose/test/ut/data/dir2/file4.txt b/library/recipes/docker_compose/test/ut/data/dir2/file4.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/library/recipes/docker_compose/test/ut/data/dir2/file4.txt diff --git a/library/recipes/docker_compose/test/ut/data/file1.txt b/library/recipes/docker_compose/test/ut/data/file1.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/library/recipes/docker_compose/test/ut/data/file1.txt diff --git a/library/recipes/docker_compose/test/ut/data/file2.txt b/library/recipes/docker_compose/test/ut/data/file2.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/library/recipes/docker_compose/test/ut/data/file2.txt diff --git a/library/recipes/docker_compose/test/ut/init_dir/init.txt b/library/recipes/docker_compose/test/ut/init_dir/init.txt new file mode 100644 index 0000000000..a0a41ab1c0 --- /dev/null +++ b/library/recipes/docker_compose/test/ut/init_dir/init.txt @@ -0,0 +1 @@ +init.txt
\ No newline at end of file diff --git a/library/recipes/docker_compose/test/ut/test_docker_context.py b/library/recipes/docker_compose/test/ut/test_docker_context.py new file mode 100644 index 0000000000..2e8008afb6 --- /dev/null +++ b/library/recipes/docker_compose/test/ut/test_docker_context.py @@ -0,0 +1,31 @@ +import os +import yaml +import yatest.common + +import library.recipes.docker_compose.lib as lib + + +def test_create_context(): + root = yatest.common.work_path("context_root") + with open(yatest.common.test_source_path("context.yml")) as f: + ctx = yaml.safe_load(f) + context = lib._create_context(ctx, yatest.common.test_source_path("init_dir"), root) + assert "context1" in context + expected_context_paths = { + "context1": [ + "init.txt", + "dir1/file3.txt", + "dir1/dir2/file4.txt", + "file1.txt", + "dir1/file2.txt", + "dir1/hello", + ], + "context2": [ + "init.txt", + "file1.txt", + ] + } + for c, expected_paths in expected_context_paths.iteritems(): + assert c in context + for p in expected_paths: + assert os.path.exists(os.path.join(root, c, p)) diff --git a/library/recipes/docker_compose/test/ut/ya.make b/library/recipes/docker_compose/test/ut/ya.make new file mode 100644 index 0000000000..008bf2beed --- /dev/null +++ b/library/recipes/docker_compose/test/ut/ya.make @@ -0,0 +1,16 @@ +PY2TEST() + +TEST_SRCS( + test_docker_context.py +) + +PEERDIR( + contrib/python/PyYAML + library/recipes/docker_compose/lib +) + +DEPENDS( + devtools/dummy_arcadia/hello_world +) + +END() diff --git a/library/recipes/docker_compose/test/ya.make b/library/recipes/docker_compose/test/ya.make new file mode 100644 index 0000000000..1dd36ee3f6 --- /dev/null +++ b/library/recipes/docker_compose/test/ya.make @@ -0,0 +1,4 @@ +RECURSE( + acceptance + ut +) diff --git a/library/recipes/docker_compose/ya.make b/library/recipes/docker_compose/ya.make index c15b87945f..c4a05a80cf 100644 --- a/library/recipes/docker_compose/ya.make +++ b/library/recipes/docker_compose/ya.make @@ -12,15 +12,11 @@ PY_SRCS( END() - -IF (NOT OPENSOURCE OR OPENSOURCE_PROJECT == "ya" OR AUTOCHECK) - # Don't export tests and examples to customers - RECURSE_FOR_TESTS( - example - example_network_go - example_test_container - example_test_container_go - example_with_context - test - ) -ENDIF() +RECURSE_FOR_TESTS( + example + example_network_go + example_test_container + example_test_container_go + example_with_context + test +) |