-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathstart
More file actions
executable file
·70 lines (60 loc) · 2.31 KB
/
start
File metadata and controls
executable file
·70 lines (60 loc) · 2.31 KB
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
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# This code is a Qiskit project.
#
# (C) Copyright IBM 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
import subprocess
import sys
from pathlib import Path
from typing import Iterable
# Get the latest digest by running `docker pull icr.io/qc-open-source-docs-public/preview:latest`.
IMAGE_DIGEST = "sha256:5336ed8710d3822e6409381e7c4a6d60d7860a2228e22a0f2b2de26c68f54a0b"
# Docker on Windows uses `/` rather than `\`, so we need to call `.as_posix()`:
# https://medium.com/@kale.miller96/how-to-mount-your-current-working-directory-to-your-docker-container-in-windows-74e47fa104d7
PWD = Path(__file__).parent.as_posix()
IMAGE = f"icr.io/qc-open-source-docs-public/preview@{IMAGE_DIGEST}"
def skip_apis(working_directory: str) -> Iterable[str]:
"""Mounts an empty directory to /docs/api/ to effectively exclude it"""
if "--apis" in sys.argv:
return ()
print("Skipping non-functions API docs for speed; use --apis to include them")
return (
"-v", "/home/node/app/docs/api",
# Even when skipping APIs, we still include the functions APIs
"-v", f"{working_directory}/docs/api/functions:/home/node/app/docs/api/functions"
)
def main() -> None:
if "--pull-only" in sys.argv:
subprocess.run(["docker", "pull", IMAGE], check=True)
sys.exit(0)
# Keep this aligned with the Dockerfile at the root of the repository.
cmd = [
"docker",
"run",
"-v",
f"{PWD}/docs:/home/node/app/content/docs",
"-v",
f"{PWD}/learning:/home/node/app/content/learning",
*skip_apis(PWD),
"-v",
f"{PWD}/public:/home/node/app/packages/preview/public",
"-p",
"3000:3000",
# Needed for ctrl-c to shut down the container.
"--init",
"--rm",
IMAGE,
]
subprocess.run(cmd, check=True)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
raise SystemExit(1)