From f36a438f893e78894175954b91d4dc4770632529 Mon Sep 17 00:00:00 2001 From: andretoyama-msft Date: Fri, 28 Jul 2023 12:18:20 -0300 Subject: [PATCH 1/7] Add pipeline config and Dockerfiles for Debian11 --- .../linux/du/docker/doclient-lite-docker.yml | 18 ++++++ .../build/linux/du/docker/dopapt-docker.yml | 18 ++++++ .../build/linux/du/docker/dosdkcpp-docker.yml | 18 ++++++ azure-pipelines/publishing/github-release.yml | 12 ++++ build/docker/debian11/amd64/Dockerfile | 39 ++++++++++++ build/docker/debian11/arm32/Dockerfile | 45 ++++++++++++++ build/docker/debian11/arm64/Dockerfile | 62 +++++++++++++++++++ 7 files changed, 212 insertions(+) create mode 100644 build/docker/debian11/amd64/Dockerfile create mode 100644 build/docker/debian11/arm32/Dockerfile create mode 100644 build/docker/debian11/arm64/Dockerfile diff --git a/azure-pipelines/build/linux/du/docker/doclient-lite-docker.yml b/azure-pipelines/build/linux/du/docker/doclient-lite-docker.yml index 38db4f67..688eaa7c 100644 --- a/azure-pipelines/build/linux/du/docker/doclient-lite-docker.yml +++ b/azure-pipelines/build/linux/du/docker/doclient-lite-docker.yml @@ -43,6 +43,24 @@ jobs: imageVersion: ${{variables.containerImageVersion}} stepsTemplate: 'doclient-lite-docker-steps.yml' +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_arm32' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'doclient-lite-docker-steps.yml' + +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_arm64' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'doclient-lite-docker-steps.yml' + +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_x64' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'doclient-lite-docker-steps.yml' + - template: ../templates/do-docker-jobs.yml parameters: targetOsArch: 'ubuntu1804_arm64' # azure pipelines does not support '.' in display names diff --git a/azure-pipelines/build/linux/du/docker/dopapt-docker.yml b/azure-pipelines/build/linux/du/docker/dopapt-docker.yml index 10be67e9..f48bbf05 100644 --- a/azure-pipelines/build/linux/du/docker/dopapt-docker.yml +++ b/azure-pipelines/build/linux/du/docker/dopapt-docker.yml @@ -43,6 +43,24 @@ jobs: imageVersion: ${{variables.containerImageVersion}} stepsTemplate: 'dopapt-docker-steps.yml' +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_arm32' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'dopapt-docker-steps.yml' + +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_arm64' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'dopapt-docker-steps.yml' + +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_x64' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'dopapt-docker-steps.yml' + - template: ../templates/do-docker-jobs.yml parameters: targetOsArch: 'ubuntu1804_arm64' diff --git a/azure-pipelines/build/linux/du/docker/dosdkcpp-docker.yml b/azure-pipelines/build/linux/du/docker/dosdkcpp-docker.yml index a8a2d44b..12e51b25 100644 --- a/azure-pipelines/build/linux/du/docker/dosdkcpp-docker.yml +++ b/azure-pipelines/build/linux/du/docker/dosdkcpp-docker.yml @@ -43,6 +43,24 @@ jobs: imageVersion: ${{variables.containerImageVersion}} stepsTemplate: 'dosdkcpp-docker-steps.yml' +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_arm32' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'dosdkcpp-docker-steps.yml' + +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_arm64' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'dosdkcpp-docker-steps.yml' + +- template: ../templates/do-docker-jobs.yml + parameters: + targetOsArch: 'debian11_x64' + imageVersion: ${{variables.containerImageVersion}} + stepsTemplate: 'dosdkcpp-docker-steps.yml' + - template: ../templates/do-docker-jobs.yml parameters: targetOsArch: 'ubuntu1804_arm64' diff --git a/azure-pipelines/publishing/github-release.yml b/azure-pipelines/publishing/github-release.yml index d065e4eb..65872e5a 100644 --- a/azure-pipelines/publishing/github-release.yml +++ b/azure-pipelines/publishing/github-release.yml @@ -80,6 +80,18 @@ stages: parameters: targetOsArch: 'debian10_x64' imageVersion: ${{variables.containerImageVersion}} + - template: templates/release-docker-build-steps.yml + parameters: + targetOsArch: 'debian11_arm32' + imageVersion: ${{variables.containerImageVersion}} + - template: templates/release-docker-build-steps.yml + parameters: + targetOsArch: 'debian11_arm64' + imageVersion: ${{variables.containerImageVersion}} + - template: templates/release-docker-build-steps.yml + parameters: + targetOsArch: 'debian11_x64' + imageVersion: ${{variables.containerImageVersion}} - stage: release condition: succeeded() diff --git a/build/docker/debian11/amd64/Dockerfile b/build/docker/debian11/amd64/Dockerfile new file mode 100644 index 00000000..b00d97f0 --- /dev/null +++ b/build/docker/debian11/amd64/Dockerfile @@ -0,0 +1,39 @@ +# Dockerfile for building DO client components for Debian 11 amd64 +# First, install the docker extension for VSCode. Then you can right-click on this file +# and choose Build Image. Give it a name and it will build the image. +# +# Alternatively, use the command line: +# Copy the build script to the build directory: +# cp /build/scripts/bootstrap.sh /build/docker/debian11/amd64 +# +# After running the above, you can build the image by running in the current dockerfile directory: +# sudo docker build -t debian11_amd64 . --no-cache --network=host +# +# Open interactive terminal into the image in a container: +# docker run -ti --rm --entrypoint=/bin/bash -v :/code -v :/build +# Example: +# sudo docker run -ti --rm --entrypoint=/bin/bash -v ~/code/do-client/:/code debian11_amd64 + +FROM mcr.microsoft.com/mirror/docker/library/debian:buster@sha256:3b6053ca925336c804e2d3f080af177efcdc9f51198a627569bfc7c7e730ef7e + +SHELL [ "/bin/bash", "-c"] + +COPY bootstrap.sh /tmp/bootstrap.sh + +WORKDIR /tmp/ + +RUN chmod +x bootstrap.sh +RUN ./bootstrap.sh --install build + + +VOLUME /code +WORKDIR /code + +ENTRYPOINT [ "/bin/bash", "-c" ] + +# We specify an empty command so that we can pass options to the ENTRYPOINT command. +# This is a bit of a Dockerfile quirk where if the ENTRYPOINT value is defined, +# then CMD becomes the default options passed to ENTRYPOINT. +# In this case we don't have any desired default arguments. +# However, we have to specify CMD to enable passing of command line parameters to ENTRYPOINT in the first place. +CMD [ ] diff --git a/build/docker/debian11/arm32/Dockerfile b/build/docker/debian11/arm32/Dockerfile new file mode 100644 index 00000000..2772a437 --- /dev/null +++ b/build/docker/debian11/arm32/Dockerfile @@ -0,0 +1,45 @@ +# Dockerfile for building DO client components for Debian 11 arm32 +# First, install the docker extension for VSCode. Then you can right-click on this file +# and choose Build Image. Give it a name and it will build the image. +# +# Open interactive terminal into the image in a container: +# docker run -ti --rm --entrypoint=/bin/bash -v :/code -v :/build +# Example: +# docker run -ti --rm --entrypoint=/bin/bash -v D:\do-client-lite:/code -v D:\temp\build_client_lite\arm-linux-debug:/build custom-debian11-arm32 + +FROM mcr.microsoft.com/mirror/docker/library/debian:buster@sha256:819b11bd0ade30fbc72f4b83593d0d126b2f3329b053495833219213fe37714d + +SHELL [ "/bin/bash", "-c"] + +# QEMU is a Linux emulator which enables cross-arch support in docker +# In order to build this image on a Linux host, need to install QEMU: +# +# sudo apt-get install qemu-user +# update-binfmts --display +# sudo apt install qemu binfmt-support qemu-user-static +# cp /usr/bin/qemu-arm-static /build/docker/debian11/arm32 +# +# Then copy the build script to the build directory +# cp /build/scripts/bootstrap.sh /build/docker/debian11/arm32 +# +# After running the above, you can build the image by running in the current dockerfile directory +# sudo docker build -t . --no-cache --network=host + +COPY qemu-arm-static /usr/bin/qemu-arm-static +COPY bootstrap.sh /tmp/bootstrap.sh + +WORKDIR /tmp/ +RUN chmod +x bootstrap.sh +RUN ./bootstrap.sh --install build + +VOLUME /code +WORKDIR /code + +ENTRYPOINT [ "/bin/bash", "-c" ] + +# We specify an empty command so that we can pass options to the ENTRYPOINT command. +# This is a bit of a Dockerfile quirk where if the ENTRYPOINT value is defined, +# then CMD becomes the default options passed to ENTRYPOINT. +# In this case we don't have any desired default arguments. +# However, we have to specify CMD to enable passing of command line parameters to ENTRYPOINT in the first place. +CMD [ ] diff --git a/build/docker/debian11/arm64/Dockerfile b/build/docker/debian11/arm64/Dockerfile new file mode 100644 index 00000000..b64669c0 --- /dev/null +++ b/build/docker/debian11/arm64/Dockerfile @@ -0,0 +1,62 @@ +# Dockerfile for building DO client components for Debian 11 arm64 +# First, install the docker extension for VSCode. Then you can right-click on this file +# and choose Build Image. Give it a name and it will build the image. +# +# Open interactive terminal into the image in a container: +# docker run -ti --rm --entrypoint=/bin/bash -v :/code -v :/build +# Example: +# docker run -ti --rm --entrypoint=/bin/bash -v D:\do-client-lite:/code -v D:\temp\build_client_lite\arm-linux-debug:/build custom-debian11-arm64 + +FROM mcr.microsoft.com/mirror/docker/library/debian:buster@sha256:de3c0d12dd75f1a47595ff0ce78f2d30d6ca95c3ad66af06c8815d1f9b8e208d + +SHELL [ "/bin/bash", "-c"] + +# QEMU is a Linux emulator which enables cross-arch support in docker +# In order to build this image on a Linux host, need to install QEMU: +# +# sudo apt-get install qemu-user +# update-binfmts --display +# sudo apt install qemu binfmt-support qemu-user-static +# cp /usr/bin/qemu-arm-static /build/docker/debian11/arm64 +# +# Then copy the build script to the build directory +# cp /build/scripts/bootstrap.sh /build/docker/debian11/arm64 +# +# open bootstrap.sh and change the function installQemu to the following: +# +# function installQemu +# { +# echo "[INFO] Installing Qemu for cross-arch support" +# # Install qemu for cross-arch support +# apt-get -y install qemu binfmt-support qemu-user-static +# +# # Register qemu with docker to more easily run cross-arch containers +# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes +# } +# After building the image yoou can return the bootstrap.sh file to the original state + +# After running the above, you can build the image by running in the current dockerfile directory +# sudo docker build -t debian11_arm64 . --no-cache --network=host + +COPY qemu-arm-static /usr/bin/qemu-arm-static +COPY bootstrap.sh /tmp/bootstrap.sh + +WORKDIR /tmp/ +RUN chmod +x bootstrap.sh +RUN ./bootstrap.sh --install build + +VOLUME /code +WORKDIR /code + +ENTRYPOINT [ "/bin/bash", "-c" ] + +# We specify an empty command so that we can pass options to the ENTRYPOINT command. +# This is a bit of a Dockerfile quirk where if the ENTRYPOINT value is defined, +# then CMD becomes the default options passed to ENTRYPOINT. +# In this case we don't have any desired default arguments. +# However, we have to specify CMD to enable passing of command line parameters to ENTRYPOINT in the first place. +CMD [ ] + + +# docker push doclientcontainerregistry.azurecr.io/debian11_arm64:0.8.0 +# docker tag doclient:debian11-arm64 doclientcontainerregistry.azurecr.io/debian11_arm64:0.8.0 \ No newline at end of file From fdbccae1984bdeda88b7d3c573e293f40650b00f Mon Sep 17 00:00:00 2001 From: andretoyama-msft Date: Fri, 28 Jul 2023 17:07:16 -0300 Subject: [PATCH 2/7] test parallel removel for pipelines --- build/build.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/build/build.py b/build/build.py index e514696a..e763c307 100644 --- a/build/build.py +++ b/build/build.py @@ -104,10 +104,10 @@ def __init__(self): ) '''Option to control resource usage when running on a Raspberry Pi''' - self.parser.add_argument( - '--parallel', dest='parallel', type=int, - help='Control the number of parallel build processes or threads' - ) + # self.parser.add_argument( + # '--parallel', dest='parallel', type=int, + # help='Control the number of parallel build processes or threads' + # ) '''Agent only''' self.parser.add_argument( @@ -428,7 +428,7 @@ def __init__(self, script_args): self.static_analysis = self.script_args.static_analysis self.build_for_snap = self.script_args.build_for_snap self.search_prefix = self.script_args.search_prefix - self.parallel = self.script_args.parallel + # self.parallel = self.script_args.parallel @property def platform(self): @@ -469,12 +469,12 @@ def run(self): def package(self): subprocess.call(['/bin/bash', '-c', 'cd {} && cpack .'.format(self.build_path)]) - @property - def build_options(self): - build_options_linux = super().build_options - if (self.parallel): - build_options_linux += ['--parallel', str(self.parallel)] - return build_options_linux + # @property + # def build_options(self): + # build_options_linux = super().build_options + # if (self.parallel): + # build_options_linux += ['--parallel', str(self.parallel)] + # return build_options_linux class WindowsBuildRunner(BuildRunnerBase): """Windows BuildRunner class.""" From b9ece0a2d46c2dd86f52e95aac5a2704c548ef82 Mon Sep 17 00:00:00 2001 From: andretoyama-msft Date: Wed, 2 Aug 2023 15:03:40 -0300 Subject: [PATCH 3/7] test new ACR service connection --- .../build/linux/du/templates/doclient-lite-docker-steps.yml | 4 ++-- .../build/linux/du/templates/dopapt-docker-steps.yml | 4 ++-- .../build/linux/du/templates/dosdkcpp-docker-steps.yml | 4 ++-- build/docker/debian11/arm64/Dockerfile | 6 +----- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml b/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml index f03bf8c1..857db0d0 100644 --- a/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry + containerRegistry: doclientcontainerregistry-test repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry + containerRegistry: doclientcontainerregistry-test arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml b/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml index be74d4a3..6c3924b4 100644 --- a/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry + containerRegistry: doclientcontainerregistry-test repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry + containerRegistry: doclientcontainerregistry-test arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml b/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml index 80f4f309..0aea4203 100644 --- a/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry + containerRegistry: doclientcontainerregistry-test repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry + containerRegistry: doclientcontainerregistry-test arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/build/docker/debian11/arm64/Dockerfile b/build/docker/debian11/arm64/Dockerfile index b64669c0..7f890f23 100644 --- a/build/docker/debian11/arm64/Dockerfile +++ b/build/docker/debian11/arm64/Dockerfile @@ -55,8 +55,4 @@ ENTRYPOINT [ "/bin/bash", "-c" ] # then CMD becomes the default options passed to ENTRYPOINT. # In this case we don't have any desired default arguments. # However, we have to specify CMD to enable passing of command line parameters to ENTRYPOINT in the first place. -CMD [ ] - - -# docker push doclientcontainerregistry.azurecr.io/debian11_arm64:0.8.0 -# docker tag doclient:debian11-arm64 doclientcontainerregistry.azurecr.io/debian11_arm64:0.8.0 \ No newline at end of file +CMD [ ] \ No newline at end of file From db240bad495c8f2d3d496ec76a5b26a4ce8ca0db Mon Sep 17 00:00:00 2001 From: andretoyama-msft Date: Mon, 7 Aug 2023 15:48:07 -0300 Subject: [PATCH 4/7] test new ACR service connection --- .../build/linux/du/templates/doclient-lite-docker-steps.yml | 4 ++-- .../build/linux/du/templates/dopapt-docker-steps.yml | 4 ++-- .../build/linux/du/templates/dosdkcpp-docker-steps.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml b/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml index 857db0d0..879681a9 100644 --- a/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry-test + containerRegistry: doclientcontainerregistry-GeGarcia repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry-test + containerRegistry: doclientcontainerregistry-GeGarcia arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml b/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml index 6c3924b4..886f263d 100644 --- a/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry-test + containerRegistry: doclientcontainerregistry-GeGarcia repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry-test + containerRegistry: doclientcontainerregistry-GeGarcia arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml b/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml index 0aea4203..5765b042 100644 --- a/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry-test + containerRegistry: doclientcontainerregistry-GeGarcia repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry-test + containerRegistry: doclientcontainerregistry-GeGarcia arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 From 003ba7c2cdc2431339e0a02727f8780ddbab9557 Mon Sep 17 00:00:00 2001 From: andretoyama-msft Date: Mon, 7 Aug 2023 17:42:18 -0300 Subject: [PATCH 5/7] rename ACR service connection --- .../templates/doclient-lite-docker-steps.yml | 4 ++-- .../du/templates/dopapt-docker-steps.yml | 4 ++-- .../du/templates/dosdkcpp-docker-steps.yml | 4 ++-- build/build.py | 22 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml b/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml index 879681a9..bb893c52 100644 --- a/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry-GeGarcia + containerRegistry: doclient-dockercontainerregistry-buildpipeline repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry-GeGarcia + containerRegistry: doclient-dockercontainerregistry-buildpipeline arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml b/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml index 886f263d..03378862 100644 --- a/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry-GeGarcia + containerRegistry: doclient-dockercontainerregistry-buildpipeline repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry-GeGarcia + containerRegistry: doclient-dockercontainerregistry-buildpipeline arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml b/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml index 5765b042..d35f340c 100644 --- a/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclientcontainerregistry-GeGarcia + containerRegistry: doclient-dockercontainerregistry-buildpipeline repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclientcontainerregistry-GeGarcia + containerRegistry: doclient-dockercontainerregistry-buildpipeline arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/build/build.py b/build/build.py index e763c307..e514696a 100644 --- a/build/build.py +++ b/build/build.py @@ -104,10 +104,10 @@ def __init__(self): ) '''Option to control resource usage when running on a Raspberry Pi''' - # self.parser.add_argument( - # '--parallel', dest='parallel', type=int, - # help='Control the number of parallel build processes or threads' - # ) + self.parser.add_argument( + '--parallel', dest='parallel', type=int, + help='Control the number of parallel build processes or threads' + ) '''Agent only''' self.parser.add_argument( @@ -428,7 +428,7 @@ def __init__(self, script_args): self.static_analysis = self.script_args.static_analysis self.build_for_snap = self.script_args.build_for_snap self.search_prefix = self.script_args.search_prefix - # self.parallel = self.script_args.parallel + self.parallel = self.script_args.parallel @property def platform(self): @@ -469,12 +469,12 @@ def run(self): def package(self): subprocess.call(['/bin/bash', '-c', 'cd {} && cpack .'.format(self.build_path)]) - # @property - # def build_options(self): - # build_options_linux = super().build_options - # if (self.parallel): - # build_options_linux += ['--parallel', str(self.parallel)] - # return build_options_linux + @property + def build_options(self): + build_options_linux = super().build_options + if (self.parallel): + build_options_linux += ['--parallel', str(self.parallel)] + return build_options_linux class WindowsBuildRunner(BuildRunnerBase): """Windows BuildRunner class.""" From 047870ac19c240241fcc017eba0d4a77b204da92 Mon Sep 17 00:00:00 2001 From: andretoyama-msft Date: Wed, 9 Aug 2023 17:50:54 -0300 Subject: [PATCH 6/7] add gtest support to debian11 --- .../linux/du/docker/doclient-lite-docker.yml | 10 +- .../templates/doclient-lite-docker-steps.yml | 4 +- .../du/templates/dopapt-docker-steps.yml | 4 +- .../du/templates/dosdkcpp-docker-steps.yml | 4 +- build/docker/debian11/arm32/bootstrap.sh | 321 ++++++++++++++++++ build/docker/debian11/arm64/Dockerfile | 14 - build/scripts/bootstrap.sh | 4 +- 7 files changed, 334 insertions(+), 27 deletions(-) create mode 100644 build/docker/debian11/arm32/bootstrap.sh diff --git a/azure-pipelines/build/linux/du/docker/doclient-lite-docker.yml b/azure-pipelines/build/linux/du/docker/doclient-lite-docker.yml index 688eaa7c..cc2ce0db 100644 --- a/azure-pipelines/build/linux/du/docker/doclient-lite-docker.yml +++ b/azure-pipelines/build/linux/du/docker/doclient-lite-docker.yml @@ -33,31 +33,31 @@ jobs: - template: ../templates/do-docker-jobs.yml parameters: - targetOsArch: 'debian10_arm64' + targetOsArch: 'debian10_arm64' # azure pipelines does not support '.' in display names imageVersion: ${{variables.containerImageVersion}} stepsTemplate: 'doclient-lite-docker-steps.yml' - template: ../templates/do-docker-jobs.yml parameters: - targetOsArch: 'debian10_x64' + targetOsArch: 'debian10_x64' # azure pipelines does not support '.' in display names imageVersion: ${{variables.containerImageVersion}} stepsTemplate: 'doclient-lite-docker-steps.yml' - template: ../templates/do-docker-jobs.yml parameters: - targetOsArch: 'debian11_arm32' + targetOsArch: 'debian11_arm32' # azure pipelines does not support '.' in display names imageVersion: ${{variables.containerImageVersion}} stepsTemplate: 'doclient-lite-docker-steps.yml' - template: ../templates/do-docker-jobs.yml parameters: - targetOsArch: 'debian11_arm64' + targetOsArch: 'debian11_arm64' # azure pipelines does not support '.' in display names imageVersion: ${{variables.containerImageVersion}} stepsTemplate: 'doclient-lite-docker-steps.yml' - template: ../templates/do-docker-jobs.yml parameters: - targetOsArch: 'debian11_x64' + targetOsArch: 'debian11_x64' # azure pipelines does not support '.' in display names imageVersion: ${{variables.containerImageVersion}} stepsTemplate: 'doclient-lite-docker-steps.yml' diff --git a/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml b/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml index bb893c52..dac13467 100644 --- a/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/doclient-lite-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclient-dockercontainerregistry-buildpipeline + containerRegistry: doclient-dockercontainerregistry-buildpipeline # name of the service connection that connect the pipeline to the ACR repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclient-dockercontainerregistry-buildpipeline + containerRegistry: doclient-dockercontainerregistry-buildpipeline # name of the service connection that connect the pipeline to the ACR arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml b/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml index 03378862..6be79d12 100644 --- a/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dopapt-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclient-dockercontainerregistry-buildpipeline + containerRegistry: doclient-dockercontainerregistry-buildpipeline # name of the service connection that connect the pipeline to the ACR repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclient-dockercontainerregistry-buildpipeline + containerRegistry: doclient-dockercontainerregistry-buildpipeline # name of the service connection that connect the pipeline to the ACR arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml b/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml index d35f340c..583e426f 100644 --- a/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml +++ b/azure-pipelines/build/linux/du/templates/dosdkcpp-docker-steps.yml @@ -14,14 +14,14 @@ steps: displayName: Login to ACR inputs: command: login - containerRegistry: doclient-dockercontainerregistry-buildpipeline + containerRegistry: doclient-dockercontainerregistry-buildpipeline # name of the service connection that connect the pipeline to the ACR repository: $(parameters.targetOsArch) - task: Docker@2 displayName: Pull latest build image inputs: command: pull - containerRegistry: doclient-dockercontainerregistry-buildpipeline + containerRegistry: doclient-dockercontainerregistry-buildpipeline # name of the service connection that connect the pipeline to the ACR arguments: 'doclientcontainerregistry.azurecr.io/${{parameters.targetOsArch}}:${{parameters.imageVersion}}' - task: CmdLine@2 diff --git a/build/docker/debian11/arm32/bootstrap.sh b/build/docker/debian11/arm32/bootstrap.sh new file mode 100644 index 00000000..c86e5ba9 --- /dev/null +++ b/build/docker/debian11/arm32/bootstrap.sh @@ -0,0 +1,321 @@ +#! /bin/bash + +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# Note: /bin/bash on macOS is very old, this script needs atleast bash 4 to be run +# bash 4 can be installed to the user directory via homebrew on mac +# And can be run as '/usr/local/bin/bash ./bootstrap.sh' + +### +# This script handles provisioning of build environments for the Delivery Optimization client components on supported platforms +### + +# Treat all command failures as fatal +set -e + +# Defaults +INSTALL=all + +OS="" +DISTRO="" +VER="" +ARCH="" + +function usage { + cat < + --install # Which command to run, supported commands: build, developertools, containertools, qemu, all. Default is all +EOM +} + +function parseArgs { + arg_Positional=() + while [[ $# -gt 0 ]]; do + case $1 in + --help | -h) + usage + shift + exit 0 + ;; + --install | -i) + INSTALL="${2,,}" + echo -e "[INFO] Install command to run set to: ${INSTALL}" + shift + ;; + *) + arg_Positional+=("$1") + shift + ;; + esac + done +} + +function installBuildDependencies +{ + echo "[INFO] Installing build dependencies" + + if [ $OS == "macos" ]; + then + # Need to install homebrew to get all the above stuff + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + brew install cmake ninja g++ gdb gdbserver python3 git curl unzip tar pkg-config + + ./install-vcpkg-deps.sh ~/deliveryoptimization_tools/ + elif [ $OS == "linux" ]; + then + + apt-get install -y make build-essential g++ gdb gdbserver gcc git wget + apt-get install -y python3 ninja-build + apt-get install -y libboost-program-options-dev + apt-get install -y libproxy-dev libssl-dev uuid-dev libcurl4-openssl-dev + apt-get install -y cmake libmsgsl-dev + apt-get install -y file # Required by CPack for packaging and by default is not installed on Ubuntu 22.04 + + + rm -rf /tmp/gtest + mkdir /tmp/gtest + pushd /tmp/gtest + + if [[ ($DISTRO == "ubuntu" && ($VER == "20.04" || $VER == "22.04")) || ($DISTRO == "debian" && ($VER == "10" || $VER == "11")) ]]; + then + if [[ $VER == "22.04" ]]; then release="v1.13.0"; else release="release-1.10.0"; fi; + + # The latest native-version of gtest on the latest versions of ubuntu and debian currently has a bug where + # CMakeLists doesn't declare an install target, causing 'make install' to fail. + # Clone from source and use release-1.10.0 instead, since gtest is a source package anyways. + git clone https://github.com/google/googletest.git . + git checkout $release + mkdir cmake + cd cmake + cmake /tmp/gtest + make + make install + else + # libgtest-dev is a source package and requires manual installation + apt-get -y install libgtest-dev + cmake /usr/src/gtest + make + make install + fi + + popd + rm -rf /tmp/gtest + + else + echo "[INFO] Builds not supported on this platform, no dependencies installed" + fi +} + +function installDeveloperTools +{ + echo "[INFO] Installing developer tools" + if [ $OS == "macos" ]; + then + brew install cpplint + elif [ $OS == "linux" ]; + then + apt install python3-pip + + # Installs to a non-standard location so add to PATH manually + export PATH=$PATH:~/.local/bin + else + echo "[INFO] Developer tools not supported on this platform" + fi +} + +function installContainerTools +{ + if [ $OS == "linux" ]; + then + apt-get install -y curl + + echo "[INFO] Installing Docker" + # Install docker to enable building cross-arch for arm + # Instructions located at: https://docs.docker.com/engine/install/ubuntu/ + curl -fsSL https://get.docker.com -o get-docker.sh + sh get-docker.sh + else + echo "[INFO] Container builds not supported on this platform" + fi +} + +function installQemu +{ + if [ $OS == "linux" ]; + then + echo "[INFO] Installing Qemu for cross-arch support" + # Install qemu for cross-arch support + apt-get -y install qemu binfmt-support qemu-user-static + + # Register qemu with docker to more easily run cross-arch containers + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + else + echo "[INFO] Emulated builds not supported on this platform" + fi +} + +function installAll +{ + echo "Setting up development environment for do-client" + installBuildDependencies + installDeveloperTools + installContainerTools + installQemu +} + +function isSupportedLinux() +{ + if [[ ($DISTRO == "ubuntu" && ($VER == "18.04" || $VER == "20.04" || $VER == "22.04")) + || ($DISTRO == "debian" && ($VER == "10" || $VER == "11")) ]]; + then + return 0 + else + return 1 + fi +} + +function isSupportedMacOS() +{ + # No specific version check needed at present + return 0 +} + +# From DU project: https://github.com/Azure/iot-hub-device-update/blob/main/scripts/install-deps.sh +function determine_machine_architecture() +{ + local arch='' + arch="$(uname -m)" + local ret_val=$? + if [[ $ret_val != 0 ]]; then + echo "Failed to get cpu architecture." + return 1 + else + if [[ $arch == aarch64* || $arch == armv8* ]]; then + ARCH="arm64" + elif [[ $arch == armv7* || $arch == 'arm' ]]; then + ARCH="arm32" + elif [[ $arch == 'x86_64' || $arch == 'amd64' ]]; then + ARCH="amd64" + else + echo "Machine architecture '$arch' is not supported." + return 1 + fi + fi +} + +function determine_linux_distro() +{ + # Checking distro name and version + if [ -r /etc/os-release ]; then + # freedesktop.org and systemd + DISTRO=$(grep "^ID\s*=\s*" /etc/os-release | sed -e "s/^ID\s*=\s*//") + VER=$(grep "^VERSION_ID=" /etc/os-release | sed -e "s/^VERSION_ID=//") + VER=$(sed -e 's/^"//' -e 's/"$//' <<< "$VER") + elif type lsb_release > /dev/null 2>&1; then + # linuxbase.org + DISTRO=$(lsb_release -si) + VER=$(lsb_release -sr) + elif [ -f /etc/lsb-release ]; then + # For some versions of Debian/Ubuntu without lsb_release command + DISTRO=$(grep DISTRIB_ID /etc/lsb-release | awk -F'=' '{ print $2 }') + VER=$(grep DISTRIB_RELEASE /etc/lsb-release | awk -F'=' '{ print $2 }') + elif [ -f /etc/debian_version ]; then + # Older Debian/Ubuntu/etc. + DISTRO=Debian + VER=$(cat /etc/debian_version) + else + # Fall back to uname, e.g. "Linux ", also works for BSD, etc. + DISTRO=$(uname -s) + VER=$(uname -r) + fi + + # Convert to lowercase + DISTRO="$(echo "$DISTRO" | tr '[:upper:]' '[:lower:]')" +} + +function determine_osx_ver() +{ + echo "Not implemented yet" + return 1 +} + +function determine_os_and_arch() +{ + if [[ $OSTYPE == linux* ]]; then + echo "Running on a linux-based OS" + OS="linux" + determine_linux_distro || return 1 + elif [[ $OSTYPE == darwin* ]]; then + echo "Running on MacOS" + OS="macos" + determine_osx_ver || return 1 + else + echo "Unsupported OS '$OSTYPE'" + return 1 + fi + + determine_machine_architecture || return 1 +} + +function isSupportedOS() +{ + if [ $OS == "linux" ]; then + if ! isSupportedLinux; then + echo "Unsupported Linux distro/version" + return 1 + fi + elif [ $OS == "macos" ]; then + if ! isSupportedMacOS; then + echo "Unsupported MacOS version" + return 1 + fi + else + echo "Unsupported OS and/or Version" + return 1 + fi + return 0 +} + +main() +{ + determine_os_and_arch || return 1 + + echo "OS = $OS" + echo "DISTRO = $DISTRO" + echo "VER = $VER" + echo "ARCH = $ARCH" + + isSupportedOS || return 1 + + parseArgs "$@" + + if [ $OS == "linux" ]; then + echo "[INFO] Updating package manager" + apt-get update -y --fix-missing + fi + + echo "[INFO] Running install command: $INSTALL" + case $INSTALL in + all) + installAll + ;; + build) + installBuildDependencies + ;; + developertools) + installDeveloperTools + ;; + containertools) + installContainerTools + ;; + qemu) + installQemu + ;; + esac + + echo "[INFO] Finished bootstrapping" +} + +main "$@" diff --git a/build/docker/debian11/arm64/Dockerfile b/build/docker/debian11/arm64/Dockerfile index 7f890f23..2511a64c 100644 --- a/build/docker/debian11/arm64/Dockerfile +++ b/build/docker/debian11/arm64/Dockerfile @@ -21,20 +21,6 @@ SHELL [ "/bin/bash", "-c"] # # Then copy the build script to the build directory # cp /build/scripts/bootstrap.sh /build/docker/debian11/arm64 -# -# open bootstrap.sh and change the function installQemu to the following: -# -# function installQemu -# { -# echo "[INFO] Installing Qemu for cross-arch support" -# # Install qemu for cross-arch support -# apt-get -y install qemu binfmt-support qemu-user-static -# -# # Register qemu with docker to more easily run cross-arch containers -# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -# } -# After building the image yoou can return the bootstrap.sh file to the original state - # After running the above, you can build the image by running in the current dockerfile directory # sudo docker build -t debian11_arm64 . --no-cache --network=host diff --git a/build/scripts/bootstrap.sh b/build/scripts/bootstrap.sh index f9453bd5..c86e5ba9 100755 --- a/build/scripts/bootstrap.sh +++ b/build/scripts/bootstrap.sh @@ -78,11 +78,11 @@ function installBuildDependencies mkdir /tmp/gtest pushd /tmp/gtest - if [[ ($DISTRO == "ubuntu" && ($VER == "20.04" || $VER == "22.04")) || ($DISTRO == "debian" && $VER == "10") ]]; + if [[ ($DISTRO == "ubuntu" && ($VER == "20.04" || $VER == "22.04")) || ($DISTRO == "debian" && ($VER == "10" || $VER == "11")) ]]; then if [[ $VER == "22.04" ]]; then release="v1.13.0"; else release="release-1.10.0"; fi; - # The latest native-version of gtest on ubuntu2004 and debian10 currently has a bug where + # The latest native-version of gtest on the latest versions of ubuntu and debian currently has a bug where # CMakeLists doesn't declare an install target, causing 'make install' to fail. # Clone from source and use release-1.10.0 instead, since gtest is a source package anyways. git clone https://github.com/google/googletest.git . From db1dd71558b9270dcba7f33081b3eaa59d24f5f9 Mon Sep 17 00:00:00 2001 From: andretoyama-msft <106272532+andretoyama-msft@users.noreply.github.com> Date: Wed, 9 Aug 2023 17:52:22 -0300 Subject: [PATCH 7/7] Delete bootstrap.sh --- build/docker/debian11/arm32/bootstrap.sh | 321 ----------------------- 1 file changed, 321 deletions(-) delete mode 100644 build/docker/debian11/arm32/bootstrap.sh diff --git a/build/docker/debian11/arm32/bootstrap.sh b/build/docker/debian11/arm32/bootstrap.sh deleted file mode 100644 index c86e5ba9..00000000 --- a/build/docker/debian11/arm32/bootstrap.sh +++ /dev/null @@ -1,321 +0,0 @@ -#! /bin/bash - -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -# Note: /bin/bash on macOS is very old, this script needs atleast bash 4 to be run -# bash 4 can be installed to the user directory via homebrew on mac -# And can be run as '/usr/local/bin/bash ./bootstrap.sh' - -### -# This script handles provisioning of build environments for the Delivery Optimization client components on supported platforms -### - -# Treat all command failures as fatal -set -e - -# Defaults -INSTALL=all - -OS="" -DISTRO="" -VER="" -ARCH="" - -function usage { - cat < - --install # Which command to run, supported commands: build, developertools, containertools, qemu, all. Default is all -EOM -} - -function parseArgs { - arg_Positional=() - while [[ $# -gt 0 ]]; do - case $1 in - --help | -h) - usage - shift - exit 0 - ;; - --install | -i) - INSTALL="${2,,}" - echo -e "[INFO] Install command to run set to: ${INSTALL}" - shift - ;; - *) - arg_Positional+=("$1") - shift - ;; - esac - done -} - -function installBuildDependencies -{ - echo "[INFO] Installing build dependencies" - - if [ $OS == "macos" ]; - then - # Need to install homebrew to get all the above stuff - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - brew install cmake ninja g++ gdb gdbserver python3 git curl unzip tar pkg-config - - ./install-vcpkg-deps.sh ~/deliveryoptimization_tools/ - elif [ $OS == "linux" ]; - then - - apt-get install -y make build-essential g++ gdb gdbserver gcc git wget - apt-get install -y python3 ninja-build - apt-get install -y libboost-program-options-dev - apt-get install -y libproxy-dev libssl-dev uuid-dev libcurl4-openssl-dev - apt-get install -y cmake libmsgsl-dev - apt-get install -y file # Required by CPack for packaging and by default is not installed on Ubuntu 22.04 - - - rm -rf /tmp/gtest - mkdir /tmp/gtest - pushd /tmp/gtest - - if [[ ($DISTRO == "ubuntu" && ($VER == "20.04" || $VER == "22.04")) || ($DISTRO == "debian" && ($VER == "10" || $VER == "11")) ]]; - then - if [[ $VER == "22.04" ]]; then release="v1.13.0"; else release="release-1.10.0"; fi; - - # The latest native-version of gtest on the latest versions of ubuntu and debian currently has a bug where - # CMakeLists doesn't declare an install target, causing 'make install' to fail. - # Clone from source and use release-1.10.0 instead, since gtest is a source package anyways. - git clone https://github.com/google/googletest.git . - git checkout $release - mkdir cmake - cd cmake - cmake /tmp/gtest - make - make install - else - # libgtest-dev is a source package and requires manual installation - apt-get -y install libgtest-dev - cmake /usr/src/gtest - make - make install - fi - - popd - rm -rf /tmp/gtest - - else - echo "[INFO] Builds not supported on this platform, no dependencies installed" - fi -} - -function installDeveloperTools -{ - echo "[INFO] Installing developer tools" - if [ $OS == "macos" ]; - then - brew install cpplint - elif [ $OS == "linux" ]; - then - apt install python3-pip - - # Installs to a non-standard location so add to PATH manually - export PATH=$PATH:~/.local/bin - else - echo "[INFO] Developer tools not supported on this platform" - fi -} - -function installContainerTools -{ - if [ $OS == "linux" ]; - then - apt-get install -y curl - - echo "[INFO] Installing Docker" - # Install docker to enable building cross-arch for arm - # Instructions located at: https://docs.docker.com/engine/install/ubuntu/ - curl -fsSL https://get.docker.com -o get-docker.sh - sh get-docker.sh - else - echo "[INFO] Container builds not supported on this platform" - fi -} - -function installQemu -{ - if [ $OS == "linux" ]; - then - echo "[INFO] Installing Qemu for cross-arch support" - # Install qemu for cross-arch support - apt-get -y install qemu binfmt-support qemu-user-static - - # Register qemu with docker to more easily run cross-arch containers - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - else - echo "[INFO] Emulated builds not supported on this platform" - fi -} - -function installAll -{ - echo "Setting up development environment for do-client" - installBuildDependencies - installDeveloperTools - installContainerTools - installQemu -} - -function isSupportedLinux() -{ - if [[ ($DISTRO == "ubuntu" && ($VER == "18.04" || $VER == "20.04" || $VER == "22.04")) - || ($DISTRO == "debian" && ($VER == "10" || $VER == "11")) ]]; - then - return 0 - else - return 1 - fi -} - -function isSupportedMacOS() -{ - # No specific version check needed at present - return 0 -} - -# From DU project: https://github.com/Azure/iot-hub-device-update/blob/main/scripts/install-deps.sh -function determine_machine_architecture() -{ - local arch='' - arch="$(uname -m)" - local ret_val=$? - if [[ $ret_val != 0 ]]; then - echo "Failed to get cpu architecture." - return 1 - else - if [[ $arch == aarch64* || $arch == armv8* ]]; then - ARCH="arm64" - elif [[ $arch == armv7* || $arch == 'arm' ]]; then - ARCH="arm32" - elif [[ $arch == 'x86_64' || $arch == 'amd64' ]]; then - ARCH="amd64" - else - echo "Machine architecture '$arch' is not supported." - return 1 - fi - fi -} - -function determine_linux_distro() -{ - # Checking distro name and version - if [ -r /etc/os-release ]; then - # freedesktop.org and systemd - DISTRO=$(grep "^ID\s*=\s*" /etc/os-release | sed -e "s/^ID\s*=\s*//") - VER=$(grep "^VERSION_ID=" /etc/os-release | sed -e "s/^VERSION_ID=//") - VER=$(sed -e 's/^"//' -e 's/"$//' <<< "$VER") - elif type lsb_release > /dev/null 2>&1; then - # linuxbase.org - DISTRO=$(lsb_release -si) - VER=$(lsb_release -sr) - elif [ -f /etc/lsb-release ]; then - # For some versions of Debian/Ubuntu without lsb_release command - DISTRO=$(grep DISTRIB_ID /etc/lsb-release | awk -F'=' '{ print $2 }') - VER=$(grep DISTRIB_RELEASE /etc/lsb-release | awk -F'=' '{ print $2 }') - elif [ -f /etc/debian_version ]; then - # Older Debian/Ubuntu/etc. - DISTRO=Debian - VER=$(cat /etc/debian_version) - else - # Fall back to uname, e.g. "Linux ", also works for BSD, etc. - DISTRO=$(uname -s) - VER=$(uname -r) - fi - - # Convert to lowercase - DISTRO="$(echo "$DISTRO" | tr '[:upper:]' '[:lower:]')" -} - -function determine_osx_ver() -{ - echo "Not implemented yet" - return 1 -} - -function determine_os_and_arch() -{ - if [[ $OSTYPE == linux* ]]; then - echo "Running on a linux-based OS" - OS="linux" - determine_linux_distro || return 1 - elif [[ $OSTYPE == darwin* ]]; then - echo "Running on MacOS" - OS="macos" - determine_osx_ver || return 1 - else - echo "Unsupported OS '$OSTYPE'" - return 1 - fi - - determine_machine_architecture || return 1 -} - -function isSupportedOS() -{ - if [ $OS == "linux" ]; then - if ! isSupportedLinux; then - echo "Unsupported Linux distro/version" - return 1 - fi - elif [ $OS == "macos" ]; then - if ! isSupportedMacOS; then - echo "Unsupported MacOS version" - return 1 - fi - else - echo "Unsupported OS and/or Version" - return 1 - fi - return 0 -} - -main() -{ - determine_os_and_arch || return 1 - - echo "OS = $OS" - echo "DISTRO = $DISTRO" - echo "VER = $VER" - echo "ARCH = $ARCH" - - isSupportedOS || return 1 - - parseArgs "$@" - - if [ $OS == "linux" ]; then - echo "[INFO] Updating package manager" - apt-get update -y --fix-missing - fi - - echo "[INFO] Running install command: $INSTALL" - case $INSTALL in - all) - installAll - ;; - build) - installBuildDependencies - ;; - developertools) - installDeveloperTools - ;; - containertools) - installContainerTools - ;; - qemu) - installQemu - ;; - esac - - echo "[INFO] Finished bootstrapping" -} - -main "$@"