Last active
January 15, 2019 03:24
-
-
Save goodwillcoding/9c536748ba80da2eeebd to your computer and use it in GitHub Desktop.
Patch to send compile to remote machine if Linux arch does match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/nixops/backends/__init__.py b/nixops/backends/__init__.py | |
index 86ed0f4..c52e9d3 100644 | |
--- a/nixops/backends/__init__.py | |
+++ b/nixops/backends/__init__.py | |
@@ -93,6 +93,17 @@ class MachineState(nixops.resources.ResourceState): | |
except nixops.ssh_util.SSHCommandFailed: | |
return None | |
+ def get_os_arch(self): | |
+ """Get the machine's OS archicture.""" | |
+ try: | |
+ res = self.run_command("uname -m", capture_stdout=True, timeout=15).rstrip() | |
+ assert len(res) >= 3 | |
+ return res | |
+ except nixops.ssh_util.SSHConnectionFailed: | |
+ return None | |
+ except nixops.ssh_util.SSHCommandFailed: | |
+ return None | |
+ | |
# FIXME: Move this to ResourceState so that other kinds of | |
# resources can be checked. | |
def check(self): | |
diff --git a/nixops/deployment.py b/nixops/deployment.py | |
index b504577..61128a6 100644 | |
--- a/nixops/deployment.py | |
+++ b/nixops/deployment.py | |
@@ -551,7 +551,7 @@ class Deployment(object): | |
}) | |
- # Add SSH public host keys for all machines in network | |
+ # Add SSH public host keys for all machines in network | |
for m2 in active_machines.itervalues(): | |
if hasattr(m2, 'public_host_key') and m2.public_host_key: | |
# Using references to files in same tempdir for now, until NixOS has support | |
@@ -627,10 +627,21 @@ class Deployment(object): | |
names = map(lambda m: m.name, selected) | |
+ # get unique values for all of the possible arches (or None if) | |
+ # arch can not be retrieved | |
+ machine_arches = set(machine.get_os_arch() for machine in selected) | |
+ # if we could retrieve some of the target machine arches or if any | |
+ # targer machine's archs is different then the host machine then | |
+ # always build remove | |
+ build_remote = False | |
+ if len(machine_arches) > 1 or (platform.machine() not in machine_arches): | |
+ build_remote = True | |
+ self.logger.log("building everything on target machine(s)") | |
+ | |
# If we're not running on Linux, then perform the build on the | |
# target machines. FIXME: Also enable this if we're on 32-bit | |
# and want to deploy to 64-bit. | |
- if platform.system() != 'Linux' and os.environ.get('NIX_REMOTE') != 'daemon': | |
+ if build_remote == True and os.environ.get('NIX_REMOTE') != 'daemon': | |
if os.environ.get('NIX_REMOTE_SYSTEMS') == None: | |
remote_machines = [] | |
for m in sorted(selected, key=lambda m: m.index): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment