James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 1 | # |
| 2 | # Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | |
| 6 | # Default build type is 'production'. Use 'dev' if supplying custom Arm NN / ACL repos from host |
| 7 | ARG BUILD_TYPE=production |
| 8 | |
| 9 | ARG UBUNTU_VERSION=18.04 |
| 10 | FROM ubuntu:${UBUNTU_VERSION} AS build-production |
| 11 | |
| 12 | ENV DEBIAN_FRONTEND noninteractive |
| 13 | |
| 14 | # Install basic packages for Docker container (not specific to Arm NN) |
| 15 | RUN apt-get update && \ |
| 16 | apt-get install -y --no-install-recommends \ |
| 17 | ca-certificates \ |
| 18 | locales \ |
| 19 | vim \ |
| 20 | && \ |
| 21 | apt-get clean && \ |
| 22 | rm -rf /var/lib/apt/lists/* |
| 23 | |
| 24 | # Set locale for Docker container |
| 25 | RUN locale-gen en_GB.UTF-8 && \ |
| 26 | update-locale LC_ALL=en_GB.UTF-8 LANG=en_GB.UTF-8 |
| 27 | ENV LANG en_GB.UTF-8 |
| 28 | ENV LC_ALL en_GB.UTF-8 |
| 29 | |
| 30 | WORKDIR /root |
| 31 | |
| 32 | # Install system-wide packages specific to Arm NN |
| 33 | COPY ./scripts/install-packages.sh . |
| 34 | RUN ./install-packages.sh |
| 35 | |
| 36 | # Define user for non-root processes (overwriteable during 'docker build' with --build-arg) |
| 37 | ARG USER_ID=1000 |
| 38 | ARG GROUP_ID=1000 |
| 39 | |
| 40 | # Create non-root user 'arm-user' based on $USER_ID and $GROUP_ID above |
| 41 | RUN addgroup --gid $GROUP_ID arm-user |
| 42 | RUN useradd --create-home --shell /bin/bash --uid $USER_ID --gid $GROUP_ID arm-user |
| 43 | |
| 44 | # Switch to non-root user |
| 45 | USER arm-user |
| 46 | WORKDIR /home/arm-user |
| 47 | |
| 48 | # Copy scripts required by Setup into WORKDIR |
| 49 | COPY --chown=arm-user:arm-user ./scripts/validation.sh . |
| 50 | COPY --chown=arm-user:arm-user ./scripts/common.sh . |
| 51 | COPY --chown=arm-user:arm-user ./scripts/setup-armnn.sh . |
| 52 | |
| 53 | # Run setup-armnn.sh: download and install Arm NN dependencies |
| 54 | ARG SETUP_ARGS="" |
| 55 | RUN echo "SETUP_ARGS: $SETUP_ARGS" |
| 56 | RUN ./setup-armnn.sh $SETUP_ARGS |
| 57 | |
| 58 | # This build-dev stage (inherits 'build-production' stage) is only used in final image if $BUILD_TYPE is 'dev' |
| 59 | FROM build-production as build-dev |
| 60 | |
| 61 | # Create directory for source repos in WORKDIR |
| 62 | RUN mkdir -p source/armnn source/acl |
| 63 | |
| 64 | # Copy custom armnn/acl source repos from the build-tool directory on the host, if they exist (optional) |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 65 | # The 'acl' repo must be provided if --neon-backend or --cl-backend is given in the BUILD_ARGS, otherwise only custom "armnn" is required |
| 66 | # If custom repos not provided, the build-armnn.sh script will automatically download the latest release branches of Arm NN and ACL |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 67 | # Copies Dockerfile to ensure COPY works - at least one file must exist for COPY to work |
| 68 | COPY --chown=arm-user:arm-user ./docker/Dockerfile ./armnn* ./source/armnn/ |
| 69 | COPY --chown=arm-user:arm-user ./docker/Dockerfile ./acl* ./source/acl/ |
| 70 | |
| 71 | # Final stage which inherits either 'build-production' or 'build-dev' stage |
| 72 | FROM build-${BUILD_TYPE} as final |
| 73 | |
| 74 | # Copy build script into WORKDIR |
| 75 | COPY --chown=arm-user:arm-user ./scripts/build-armnn.sh . |
| 76 | |
| 77 | # Run build-armnn.sh: build Arm NN and ACL |
| 78 | ARG BUILD_ARGS="" |
| 79 | RUN echo "BUILD_ARGS: $BUILD_ARGS" |
| 80 | RUN ./build-armnn.sh $BUILD_ARGS |