From c1f1da9fffd3c0a17e8f250378da5d756b118ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eystein=20M=C3=A5l=C3=B8y=20Stenberg?= Date: Wed, 28 Nov 2018 13:44:20 -0800 Subject: [PATCH 1/5] merged docker/ directory into root directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eystein Måløy Stenberg --- docker/.dockerignore => .dockerignore | 0 docker/Dockerfile => Dockerfile | 0 README.md | 76 +++++++++++++++++++ docker/docker-build => docker-build | 0 ...cker-entrypoint.sh => docker-entrypoint.sh | 0 ...er-mender-convert => docker-mender-convert | 0 docker/README.md | 74 ------------------ 7 files changed, 76 insertions(+), 74 deletions(-) rename docker/.dockerignore => .dockerignore (100%) rename docker/Dockerfile => Dockerfile (100%) rename docker/docker-build => docker-build (100%) rename docker/docker-entrypoint.sh => docker-entrypoint.sh (100%) rename docker/docker-mender-convert => docker-mender-convert (100%) delete mode 100644 docker/README.md diff --git a/docker/.dockerignore b/.dockerignore similarity index 100% rename from docker/.dockerignore rename to .dockerignore diff --git a/docker/Dockerfile b/Dockerfile similarity index 100% rename from docker/Dockerfile rename to Dockerfile diff --git a/README.md b/README.md index 26a214c..08bf747 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,82 @@ image by restructuring partition table and injecting the necessary files. To start using Mender, we recommend that you begin with the Getting started section in [the Mender documentation](https://docs.mender.io/). + +## Docker environment for mender-convert + +In order to correctly set up partitions and bootloaders, mender-convert has many dependencies, +and their version and name vary between Linux distributions. + +To make using mender-convert easier, a reference setup using a Ubuntu 18.04 Docker container +is provided. + +You need to [install Docker Engine](https://docs.docker.com/install) to use this environment. + + +### Build the mender-convert container image + +To build a container based on Ubuntu 18.04 with all required dependencies for mender-convert, +copy this directory to your workstation and change the current directory to it. + +Then run + +```bash +./docker-build +``` + +This will create a container image you can use to run mender-convert. + + +### Use the mender-convert container image + +Create a directory `input` under the directory where you copied these files (`docker-build`, `docker-mender-convert`, etc.): + +```bash +mkdir input +``` + +Then put your raw disk image into `input`, e.g. + +```bash +mv ~/Downloads/2018-11-13-raspbian-stretch.img input/2018-11-13-raspbian-stretch.img +``` + +You can run mender-convert from inside the container with your desired options, e.g. + + +```bash +DEVICE_TYPE="raspberrypi3" +RAW_DISK_IMAGE="input/2018-11-13-raspbian-stretch.img" + +ARTIFACT_NAME="2018-11-13-raspbian-stretch" +MENDER_DISK_IMAGE="2018-11-13-raspbian-stretch.sdimg" +TENANT_TOKEN="" + +./docker-mender-convert from-raw-disk-image \ + --raw-disk-image $RAW_DISK_IMAGE \ + --mender-disk-image $MENDER_DISK_IMAGE \ + --device-type $DEVICE_TYPE \ + --mender-client /mender \ + --artifact-name $ARTIFACT_NAME \ + --bootloader-toolchain arm-linux-gnueabihf \ + --server-url "https://hosted.mender.io" \ + --tenant-token $TENANT_TOKEN +``` + +Note that the default Mender client is the latest stable and cross-compiled for generic ARM boards, +which should work well in most cases. If you would like to use a different Mender client, +place it in `inputs` and adjust the `--mender-client` argument. + +Conversion will take 10-15 minutes, depending on your storage and resources available. +You can watch `output/build.log` for progress and diagnostics information. + +After it finishes, you can find your images in the `output` directory on your host machine! + + +### Known issues +* BeagleBone images might not convert properly using this docker envirnoment due to permission issues: `mount: /mender-convert/output/embedded/rootfs: WARNING: device write-protected, mounted read-only.` + + ## Contributing We welcome and ask for your contribution. If you would like to contribute to Mender, please read our guide on how to best get started [contributing code or documentation](https://github.com/mendersoftware/mender/blob/master/CONTRIBUTING.md). diff --git a/docker/docker-build b/docker-build similarity index 100% rename from docker/docker-build rename to docker-build diff --git a/docker/docker-entrypoint.sh b/docker-entrypoint.sh similarity index 100% rename from docker/docker-entrypoint.sh rename to docker-entrypoint.sh diff --git a/docker/docker-mender-convert b/docker-mender-convert similarity index 100% rename from docker/docker-mender-convert rename to docker-mender-convert diff --git a/docker/README.md b/docker/README.md deleted file mode 100644 index 4002566..0000000 --- a/docker/README.md +++ /dev/null @@ -1,74 +0,0 @@ -Docker environment for mender-convert -===================================== - -In order to correctly set up partitions and bootloaders, mender-convert has many dependencies, -and their version and name vary between Linux distributions. - -To make using mender-convert easier, a reference setup using a Ubuntu 18.04 Docker container -is provided. - -You need to [install Docker Engine](https://docs.docker.com/install) to use this environment. - - -## Build the mender-convert container image - -To build a container based on Ubuntu 18.04 with all required dependencies for mender-convert, -copy this directory to your workstation and change the current directory to it. - -Then run - -```bash -./docker-build -``` - -This will create a container image you can use to run mender-convert. - - -## Use the mender-convert container image - -Create a directory `input` under the directory where you copied these files (`docker-build`, `docker-mender-convert`, etc.): - -```bash -mkdir input -``` - -Then put your raw disk image into `input`, e.g. - -```bash -mv ~/Downloads/2018-11-13-raspbian-stretch.img input/2018-11-13-raspbian-stretch.img -``` - -You can run mender-convert from inside the container with your desired options, e.g. - - -```bash -DEVICE_TYPE="raspberrypi3" -RAW_DISK_IMAGE="input/2018-11-13-raspbian-stretch.img" - -ARTIFACT_NAME="2018-11-13-raspbian-stretch" -MENDER_DISK_IMAGE="2018-11-13-raspbian-stretch.sdimg" -TENANT_TOKEN="" - -./docker-mender-convert from-raw-disk-image \ - --raw-disk-image $RAW_DISK_IMAGE \ - --mender-disk-image $MENDER_DISK_IMAGE \ - --device-type $DEVICE_TYPE \ - --mender-client /mender \ - --artifact-name $ARTIFACT_NAME \ - --bootloader-toolchain arm-linux-gnueabihf \ - --server-url "https://hosted.mender.io" \ - --tenant-token $TENANT_TOKEN -``` - -Note that the default Mender client is the latest stable and cross-compiled for generic ARM boards, -which should work well in most cases. If you would like to use a different Mender client, -place it in `inputs` and adjust the `--mender-client` argument. - -Conversion will take 10-15 minutes, depending on your storage and resources available. -You can watch `output/build.log` for progress and diagnostics information. - -After it finishes, you can find your images in the `output` directory on your host machine! - - -## Known issues -* BeagleBone images might not convert properly using this docker envirnoment due to permission issues: `mount: /mender-convert/output/embedded/rootfs: WARNING: device write-protected, mounted read-only.` From b17b5af608a358f20206ce247676ea1c76ca0800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eystein=20M=C3=A5l=C3=B8y=20Stenberg?= Date: Wed, 28 Nov 2018 13:55:21 -0800 Subject: [PATCH 2/5] Spellfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changelog: None Signed-off-by: Eystein Måløy Stenberg --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 08bf747..6520e7c 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Create a directory `input` under the directory where you copied these files (`do mkdir input ``` -Then put your raw disk image into `input`, e.g. +Then put your raw disk image into `input/`, e.g. ```bash mv ~/Downloads/2018-11-13-raspbian-stretch.img input/2018-11-13-raspbian-stretch.img @@ -77,7 +77,7 @@ TENANT_TOKEN="" Note that the default Mender client is the latest stable and cross-compiled for generic ARM boards, which should work well in most cases. If you would like to use a different Mender client, -place it in `inputs` and adjust the `--mender-client` argument. +place it in `input/` and adjust the `--mender-client` argument. Conversion will take 10-15 minutes, depending on your storage and resources available. You can watch `output/build.log` for progress and diagnostics information. From f570575f41b80738ab24d792bf8eb9b77e202fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eystein=20M=C3=A5l=C3=B8y=20Stenberg?= Date: Wed, 28 Nov 2018 13:57:20 -0800 Subject: [PATCH 3/5] Bind entire mender-convert directory into container. This ensures we use same version of mender-convert inside the container as the one used to launch the container. It makes versioning and local development easier. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changelog: Use local (checked out) version of mender-convert inside container Signed-off-by: Eystein Måløy Stenberg --- Dockerfile | 5 ----- docker-mender-convert | 9 +++------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index b1dcc5f..7e68bfe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,10 +52,5 @@ RUN wget https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz \ && tar -C /usr/local -xzf go$GOLANG_VERSION.linux-amd64.tar.gz \ && echo export PATH=$PATH:/usr/local/go/bin >> /root/.bashrc -# TODO: support selecting tag of mender-convert with MENDER_CONVERT_VERSION -# TODO: consider lighter way to download to avoid git dependency -RUN git clone https://github.com/mendersoftware/mender-convert.git - - COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/docker-mender-convert b/docker-mender-convert index 5691b28..24e3ccb 100755 --- a/docker-mender-convert +++ b/docker-mender-convert @@ -4,13 +4,10 @@ set -e IMAGE_NAME=mender-convert -INPUT_DIR="$(pwd)/input" -OUTPUT_DIR="$(pwd)/output" - -mkdir -p $OUTPUT_DIR +MENDER_CONVERT_DIR="$(pwd)" +mkdir -p output docker run \ - --mount type=bind,source=$INPUT_DIR,target=/mender-convert/input,readonly \ - --mount type=bind,source=$OUTPUT_DIR,target=/mender-convert/output \ + --mount type=bind,source=$MENDER_CONVERT_DIR,target=/mender-convert \ --privileged=true \ $IMAGE_NAME "$@" From ee1a6215b5346c86870cbb23bcd88f7a7fc0a3cb Mon Sep 17 00:00:00 2001 From: Mirza Krak Date: Thu, 29 Nov 2018 15:23:01 +0100 Subject: [PATCH 4/5] compile mender during docker image creation It is a bit exessive to compile the mender client every time the mender-convert tool is launched using docker-mender-convert. Move the build to the Dockerfile so it is done during image creation. Changelog: Title Signed-off-by: Mirza Krak --- Dockerfile | 22 ++++++++++++++++++++++ docker-entrypoint.sh | 22 ---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7e68bfe..1793010 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,5 +52,27 @@ RUN wget https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz \ && tar -C /usr/local -xzf go$GOLANG_VERSION.linux-amd64.tar.gz \ && echo export PATH=$PATH:/usr/local/go/bin >> /root/.bashrc +ENV MENDER_CLIENT_VERSION="1.6.0" + +RUN echo "Cross-compiling Mender client $MENDER_CLIENT_VERSION" + +# NOTE: we are assuming generic ARM board here, needs to be extended later + +ENV PATH "$PATH:/usr/local/go/bin:/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin" +ENV GOPATH "/root/go" + +RUN go get github.com/mendersoftware/mender +WORKDIR $GOPATH/src/github.com/mendersoftware/mender +RUN git checkout $MENDER_CLIENT_VERSION + +RUN env CGO_ENABLED=1 \ + CC=arm-linux-gnueabihf-gcc \ + GOOS=linux \ + GOARCH=arm make build + +RUN cp $GOPATH/src/github.com/mendersoftware/mender/mender / + +WORKDIR / + COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 49bf2cd..b18eb05 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,28 +2,6 @@ set -e -MENDER_CLIENT_VERSION="1.6.0" # TODO: Default, support input as env variable - - -echo "Cross-compiling Mender client $MENDER_CLIENT_VERSION" -# NOTE: we are assuming generic ARM board here, needs to be extended later - -export PATH=$PATH:/usr/local/go/bin -export GOPATH=$HOME/go -export PATH=$PATH:/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin - -go get github.com/mendersoftware/mender -cd $GOPATH/src/github.com/mendersoftware/mender -git checkout $MENDER_CLIENT_VERSION - -env CGO_ENABLED=1 \ - CC=arm-linux-gnueabihf-gcc \ - GOOS=linux \ - GOARCH=arm make build - -cp $GOPATH/src/github.com/mendersoftware/mender/mender / - - # run conversion, args provided to container (end of docker run ...) cd /mender-convert From c569ed430e19f399d91a04a8003a40f528067b58 Mon Sep 17 00:00:00 2001 From: Mirza Krak Date: Thu, 29 Nov 2018 15:56:33 +0100 Subject: [PATCH 5/5] Provide Mender client version as a argument to docker build This way we could extend this argument to the user, but this is not yet done. Changelog: None Signed-off-by: Mirza Krak --- Dockerfile | 4 ++-- docker-build | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1793010..e39b1f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,9 +52,9 @@ RUN wget https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz \ && tar -C /usr/local -xzf go$GOLANG_VERSION.linux-amd64.tar.gz \ && echo export PATH=$PATH:/usr/local/go/bin >> /root/.bashrc -ENV MENDER_CLIENT_VERSION="1.6.0" +ARG mender_client_version -RUN echo "Cross-compiling Mender client $MENDER_CLIENT_VERSION" +ENV MENDER_CLIENT_VERSION=$mender_client_version # NOTE: we are assuming generic ARM board here, needs to be extended later diff --git a/docker-build b/docker-build index e0a0683..7cbb549 100755 --- a/docker-build +++ b/docker-build @@ -4,4 +4,6 @@ set -e IMAGE_NAME=mender-convert -docker build . -t $IMAGE_NAME +MENDER_CLIENT_VERSION="1.6.0" + +docker build . -t ${IMAGE_NAME} --build-arg mender_client_version=${MENDER_CLIENT_VERSION}