Commit a51448e8 authored by Manuel's avatar Manuel

adapted build.py to work with flutter projects

parent eb70925f
...@@ -35,6 +35,23 @@ def get_dockerfile_paths_and_names() -> Dict[str, str]: ...@@ -35,6 +35,23 @@ def get_dockerfile_paths_and_names() -> Dict[str, str]:
return command_args return command_args
def is_flutter_project(path: str) -> bool:
test_file_path = f"{path}/pubspec.yaml"
return os.path.exists(test_file_path)
class cd:
"""Context manager for changing the current working directory"""
def __init__(self, newPath):
self.newPath = os.path.expanduser(newPath)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
if __name__ == '__main__': if __name__ == '__main__':
p_image_name = None p_image_name = None
...@@ -60,6 +77,20 @@ if __name__ == '__main__': ...@@ -60,6 +77,20 @@ if __name__ == '__main__':
path = command_arg['path'] path = command_arg['path']
image_name = f"{DOCKERHUB_REPO_OWNER}/{command_arg['name']}" image_name = f"{DOCKERHUB_REPO_OWNER}/{command_arg['name']}"
if is_flutter_project(path):
with cd(path):
print(f"> flutter build web")
os.system(f"flutter build web")
print(f"> docker image build -t {image_name} {path}")
exit_val = os.system(f"docker image build -t {image_name} {path}")
if exit_val != 0:
error = exit_val
else:
print(f"> docker push {image_name}")
exit_val = os.system(f"docker push {image_name}")
else:
# copy Dockerfile into root dir to have access to modules folder # copy Dockerfile into root dir to have access to modules folder
shutil.copy2(os.path.join(path, DOCKER_BUILD_NAME), ROOT) shutil.copy2(os.path.join(path, DOCKER_BUILD_NAME), ROOT)
......
FROM nginx:latest FROM nginx:latest
EXPOSE 80 EXPOSE 80
COPY ./build/web/ /usr/share/nginx/html/ COPY ./src/dashboard/build/web/ /usr/share/nginx/html/
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment