Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow local builds #256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fboss/oss/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ RUN dnf install git sudo lsof -y
# Use /var/FBOSS as the set location to clone the git repository and store the outputs of the build.
WORKDIR /var/FBOSS/

RUN git clone https://github.com/facebook/fboss.git
RUN mkdir -p /var/FBOSS/fboss
COPY . fboss
WORKDIR fboss

RUN rm -rf build/deps/github_hashes/
Expand Down
28 changes: 25 additions & 3 deletions fboss/oss/scripts/docker-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
OPT_ARG_NO_DOCKER_OUTPUT = "--no-docker-output"
OPT_ARG_NO_SYSTEM_DEPS = "--no-system-deps"
OPT_ARG_ADD_BUILD_ENV_VAR = "--env-var"
OPT_ARG_LOCAL = "--local"

FBOSS_IMAGE_NAME = "fboss_image"
FBOSS_CONTAINER_NAME = "FBOSS_BUILD_CONTAINER"
CONTAINER_SCRATCH_PATH = "/var/FBOSS/tmp_bld_dir"


def get_linux_type() -> tuple[str | None, str | None, str | None]:
def get_linux_type() -> tuple[Optional[str], Optional[str], Optional[str]]:
try:
with open("/etc/os-release") as f:
data = f.read()
Expand Down Expand Up @@ -138,6 +139,13 @@ def parse_args():
"This is particularly useful as some CMake targets are hidden behind flags, e.g. BUILD_SAI_FAKE=1"
),
)
parser.add_argument(
OPT_ARG_LOCAL,
required=False,
help="Compiles using the local clone of the FBOSS git repository. By default, a separate clone of the repository with the head commit is used.",
default=False,
action="store_true",
)

return parser.parse_args()

Expand All @@ -162,8 +170,18 @@ def build_docker_image(docker_dir_path: str):
f"Attempting to build docker image from {docker_dir_path}/Dockerfile. You can run `sudo tail -f {log_path}` in order to follow along."
)
with os.fdopen(fd, "w") as output:
dockerfile_path = os.path.join(docker_dir_path, "Dockerfile")
cp = subprocess.run(
["sudo", "docker", "build", docker_dir_path, "-t", FBOSS_IMAGE_NAME],
[
"sudo",
"docker",
"build",
".",
"-t",
FBOSS_IMAGE_NAME,
"-f",
dockerfile_path,
],
stdout=output,
stderr=subprocess.STDOUT,
)
Expand All @@ -175,10 +193,11 @@ def build_docker_image(docker_dir_path: str):

def run_fboss_build(
scratch_path: str,
target: str | None,
target: Optional[str],
docker_output: bool,
use_system_deps: bool,
env_vars: list[str],
use_local: bool,
):
cmd_args = ["sudo", "docker", "run"]
# Add build environment variables, if any.
Expand Down Expand Up @@ -216,6 +235,8 @@ def run_fboss_build(
if target is not None:
build_cmd.append("--cmake-target")
build_cmd.append(target)
if use_local:
build_cmd.extend(["--src-dir", "."])
build_cmd.append("fboss")
cmd_args.extend(build_cmd)
build_cp = subprocess.run(cmd_args)
Expand Down Expand Up @@ -267,6 +288,7 @@ def main():
args.docker_output,
args.use_system_deps,
args.env_vars,
args.local,
)

cleanup_fboss_build_container()
Expand Down
12 changes: 11 additions & 1 deletion fboss/oss/scripts/github_actions/docker-unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ def build_docker_image(docker_dir_path: str):
f"Attempting to build docker image from {docker_dir_path}/Dockerfile. You can run `sudo tail -f {log_path}` in order to follow along."
)
with os.fdopen(fd, "w") as output:
dockerfile_path = os.path.join(docker_dir_path, "Dockerfile")
cp = subprocess.run(
["sudo", "docker", "build", docker_dir_path, "-t", FBOSS_IMAGE_NAME],
[
"sudo",
"docker",
"build",
".",
"-t",
FBOSS_IMAGE_NAME,
"-f",
dockerfile_path,
],
stdout=output,
stderr=subprocess.STDOUT,
)
Expand Down
Loading