File size: 1,580 Bytes
ff293b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Opt-in Docker build smoke test for Phase 1 deployment readiness."""

from __future__ import annotations

import os
import shutil
import subprocess
from pathlib import Path

import pytest

ROOT = Path(__file__).resolve().parents[1]


@pytest.mark.skipif(
    shutil.which("docker") is None or os.environ.get("GHOSTEXEC_RUN_DOCKER_BUILD") != "1",
    reason="Set GHOSTEXEC_RUN_DOCKER_BUILD=1 and ensure docker is installed to run this test.",
)
def test_server_dockerfile_builds():
    daemon = subprocess.run(
        ["docker", "version"],
        cwd=str(ROOT),
        capture_output=True,
        text=True,
        timeout=60,
        check=False,
    )
    if daemon.returncode != 0:
        pytest.skip("Docker daemon is unavailable on this machine.")

    image_tag = "ghostexec-env:ci"
    build_cmd = ["docker", "build", "-t", image_tag, "."]
    built = subprocess.run(
        build_cmd,
        cwd=str(ROOT),
        capture_output=True,
        text=True,
        timeout=900,
        check=False,
    )
    assert built.returncode == 0, (
        "docker build failed\n"
        f"stdout:\n{built.stdout}\n"
        f"stderr:\n{built.stderr}\n"
    )

    inspect_cmd = ["docker", "image", "inspect", image_tag]
    inspected = subprocess.run(
        inspect_cmd,
        cwd=str(ROOT),
        capture_output=True,
        text=True,
        timeout=120,
        check=False,
    )
    assert inspected.returncode == 0, (
        f"image inspect failed for {image_tag}\n"
        f"stdout:\n{inspected.stdout}\n"
        f"stderr:\n{inspected.stderr}\n"
    )