You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/11/25 05:14:36 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #19819: Rewrite image building tests to Python

uranusjr commented on a change in pull request #19819:
URL: https://github.com/apache/airflow/pull/19819#discussion_r756576698



##########
File path: docker_tests/test_examples_of_prod_image_building.py
##########
@@ -0,0 +1,64 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import glob
+import os
+import re
+from functools import lru_cache
+from pathlib import Path
+
+import pytest
+import requests
+
+from docker_tests.command_utils import run_command
+from docker_tests.constants import SOURCE_ROOT
+
+DOCKER_EXAMPLES_DIR = SOURCE_ROOT / "docs" / "docker-stack" / "docker-examples"
+
+
+@lru_cache(maxsize=None)
+def get_latest_airflow_version_released():
+    response = requests.get('https://pypi.org/pypi/apache-airflow/json')
+    response.raise_for_status()
+    return response.json()['info']['version']
+
+
+@pytest.mark.skipif(
+    os.environ.get('CI') == "true",
+    reason="Skipping the script builds on CI! They take very long time to build.",
+)
+@pytest.mark.parametrize("script_file", glob.glob(f"{DOCKER_EXAMPLES_DIR}/**/*.sh", recursive=True))
+def test_shell_script_example(script_file):
+    run_command(["bash", script_file])
+
+
+@pytest.mark.parametrize("dockerfile", glob.glob(f"{DOCKER_EXAMPLES_DIR}/**/Dockerfile", recursive=True))
+def test_dockerfile_example(dockerfile):
+    rel_dockerfile_path = Path(dockerfile).relative_to(DOCKER_EXAMPLES_DIR)
+    image_name = str(rel_dockerfile_path).lower().replace("/", "-")
+    content = Path(dockerfile).read_text()
+    new_content = re.sub(
+        r'FROM apache/airflow:.*', fr'FROM apache/airflow:{get_latest_airflow_version_released()}', content
+    )
+    try:
+        run_command(
+            ["docker", "build", ".", "--tag", image_name, '-f', '-'],
+            cwd=str(Path(dockerfile).parent),
+            input=new_content.encode(),
+        )

Review comment:
       I think this leaves dangling intermediate images if the command fails. Is this intended?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org