Skip to content
Permalink
Browse files

Merge pull request #71 from rose-a/docker-compatibility

make init-common.sh compatible with docker build
  • Loading branch information...
synapticvoid committed Jul 14, 2019
2 parents 416ac61 + 258c463 commit 112e6560eadf3bc7bbb0ac337edc8a555bd257e8
@@ -3,22 +3,19 @@
## Purpose
Offer an easy-to-use environment to cross-compile Qt application on a Raspberry Pi. This repo contains all the scripts needed to prepare a sysroot, cross-compile Qt and deploy Qt libraries to your Raspberry.

For more information, go to http://www.qtrpi.com/faq.

## How to contact us?
You can fill a contact form from our [official website](https://www.neuronalmotion.com/contact/) or send us an email at *contact [at] neuronalmotion [dot] com*.
For more information, go to [the wiki](https://github.com/neuronalmotion/qtrpi/wiki)

## Difference between init-qtrpi-minimal and init-qtrpi-full
* **init-qtrpi-minimal**, the typical way: downloads ready-to-use Qt binaries for the Raspberry Pi and a minimal sysroot that we released on the [official website](http://www.qtrpi.com/download)
* **init-qtrpi-minimal**, the typical way: downloads ready-to-use Qt binaries for the Raspberry Pi and a minimal sysroot that we released on the [download page](https://github.com/neuronalmotion/qtrpi/wiki/Download)
* **init-qtrpi-full**, the custom way: compiles on your computer the Qt binaries for the Raspberry Pi to let you tweak the configuration, enhance the compilation by adding some missing Qt modules to QtRpi or add some specific third-party dependencies

### Summary
| | init-qtrpi-minimal | init-qtrpi-full |
| ------------------- | ----------------------------- | ------------------------------------ |
| Raspbian image | | *from [raspberrypi.org](https://www.raspberrypi.org/downloads/raspbian/)* |
| Toochain | *from [the github project](https://github.com/raspberrypi/tools)* | *from [the github project](https://github.com/raspberrypi/tools)* |
| Sysroot | *from [qtrpi.com](http://www.qtrpi.com/download)* | generated from raspbian image |
| Qt binaries | *from [qtrpi.com](http://www.qtrpi.com/download)* | compiled |
| Sysroot | *from qtrpi team* | generated from raspbian image |
| Qt binaries | *from qtrpi team* | compiled |

## Tutorial of init-qtrpi-minimal.sh

@@ -29,7 +26,7 @@ This tutorial will help you to:

### Requirements
* A 64-bit Linux host computer
* A Raspberry Pi 3
* A Raspberry Pi 3 **with Raspbian Jessie** (Raspbian Stretch is currently not supported!)

In this example, you already have an SSH access to your Raspberry Pi 3 at `192.168.1.12` with the user `pi`. The script will use sudo several times to install the packages on the board. You should add your SSH key in your Raspberry Pi. For example with **`ssh-copy-id`**:
```bash
@@ -80,3 +77,25 @@ How to build a Raspberry Pi 3 application from your desktop Qt Creator (step by
* If you want to add a module, just add the repository name in the file [qt-modules.txt](https://github.com/neuronalmotion/qtrpi/blob/develop/qt-modules.txt)
* You might have to add some packages in the sysroot, this can be done in [utils/prepare-sysroot-full.sh](https://github.com/neuronalmotion/qtrpi/blob/develop/utils/prepare-sysroot-full.sh)
* Once you have modified these scripts, you should be able to re-execute [init-qtrpi-full.sh](https://github.com/neuronalmotion/qtrpi/blob/develop/init-qtrpi-full.sh) and see the magic happen.

## Docker images

The images are tagged according to their target configuration.

Currently the following tags are available:

* `rpi3-qt5.6.2`: Crosscompile Qt 5.6.2 for the Raspbarry Pi 3

Choose the image which fits your needs.

### Building a Qt project

To build a Qt project, mount the directory containing the sources and the project file to the `/sources` path inside the container and run it.
By default the image automatically executes `qmake` and `make` in the current working directory, which is set to `/sources` by default.

#### Example

``` shell
docker pull arose/qtrpi:rpi3-qt5.6.2
docker run -v /someqtprojectfolder/:/source arose/qtrpi:rpi3-qt5.6.2
```
@@ -0,0 +1,40 @@
FROM debian:stable-slim
LABEL maintainer="Alexander Rose <alex@rose-a.de>"

# install necessary packages
RUN apt-get update -q && apt-get install -yq --no-install-recommends \
build-essential \
ca-certificates \
curl \
git \
unzip \
&& rm -rf /var/lib/apt/lists/*

# Clone Qtrpi and additional scripts
RUN git clone https://github.com/rose-a/qtrpi.git -b docker-compatibility

# Setup Qtrpi environment
ENV QTRPI_QT_VERSION='5.6.2' \
QTRPI_TARGET_DEVICE='linux-rpi3-g++' \
QTRPI_TARGET_HOST='pi@localhost' \
QTRPI_DOCKER='True'

# Change workdir
WORKDIR /qtrpi

# Execute init script and clean up after it
RUN ./init-qtrpi-minimal.sh && \
rm /opt/qtrpi/*.zip && \
rm -rf /opt/qtrpi/raspi/tools/.git && \
rm -rf /opt/qtrpi/raspi/tools/arm-bcm2708/arm-* && \
rm -rf /opt/qtrpi/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian

# Extend path
ENV PATH=/opt/qtrpi/bin:$PATH

# Create path for source files
RUN mkdir /source
WORKDIR /source

# Execute build commands on run
CMD /qtrpi/docker/scripts/build.sh
@@ -0,0 +1,11 @@
#!/bin/bash

source ${0%/*}/utils/common.sh

# Run qmake
message 'running qmake...'
qmake_cmd

# Run make
message 'running make...'
make_cmd
@@ -6,3 +6,4 @@ qtquickcontrols
qtquickcontrols2
qtserialport
qtsvg
qtgraphicaleffects
@@ -82,6 +82,10 @@ QTRPI_SYSROOT_URL="$QTRPI_BASE_URL/sysroot/qtrpi-sysroot-minimal-latest.zip"
QTRPI_MINIMAL_URL="$QTRPI_BASE_URL/qtrpi/$DEVICE_NAME/$QTRPI_ZIP"
QTRPI_CURL_OPT=''

# evaluate docker usage
if [[ $QTRPI_DOCKER ]]; then
DOCKER_BUILD=$QTRPI_DOCKER
fi

# Get absolute path of script dir for later execution
# /!\ has to be executed *before* any "cd" command
@@ -53,7 +53,8 @@ function download_raspbian() {
message 'Downloading Raspbian latest image'
wget --output-document=${RASPBIAN_BASENAME}.zip \
--content-disposition \
https://downloads.raspberrypi.org/raspbian_latest
https://downloads.raspberrypi.org/raspbian/images/raspbian-2017-03-03/2017-03-02-raspbian-jessie.zip


unzip -p ${RASPBIAN_BASENAME}.zip > ${RASPBIAN_BASENAME}.img
}
@@ -4,15 +4,23 @@ source ${0%/*}/common.sh

message 'Creating qtrpi directory structure'

# sanity check for mounted image
sudo umount /mnt/raspbian
sudo umount $ROOT/raspbian/sysroot-full/sys
sudo umount $ROOT/raspbian/sysroot-full/dev
sudo umount $ROOT/raspbian/sysroot-full/proc
if [[ ! $DOCKER_BUILD ]]; then
# sanity check for mounted image
sudo umount /mnt/raspbian
sudo umount $ROOT/raspbian/sysroot-full/sys
sudo umount $ROOT/raspbian/sysroot-full/dev
sudo umount $ROOT/raspbian/sysroot-full/proc

sudo mkdir -p $ROOT
sudo chown -R $USER:$USER $ROOT
else
# === Docker-Mode ===
# umount is not allowed in a docker image, besides we use a fresh linux image => skipping sanity checks
# sudo is also not needed/installed by default => creating directory structure without use of sudo
mkdir -p $ROOT
chown -R $USER:$USER $ROOT
fi

sudo mkdir -p $ROOT
sudo chown -R $USER:$USER $ROOT
cd_root

mkdir raspi raspbian bin logs

@@ -7,6 +7,7 @@ mkdir -p raspbian ; cd raspbian

# Mount and extract the raspbian sysroot
message 'Creating sysroot'
sudo umount /dev/loop0
sudo losetup -P /dev/loop0 ${RASPBIAN_BASENAME}.img
sudo mkdir /mnt/raspbian
sudo mount /dev/loop0p2 /mnt/raspbian
@@ -43,10 +43,15 @@ cd raspi

message 'Downloading Raspberry Pi toolchain'

if [[ ! -d 'tools' ]]; then
git clone https://github.com/raspberrypi/tools
if [[ ! $DOCKER_BUILD ]]; then
if [[ ! -d 'tools' ]]; then
git clone https://github.com/raspberrypi/tools
fi

pushd tools
git pull origin master
popd
else
# create shallow copy, which is a lot faster
git clone --depth=1 -b master https://github.com/raspberrypi/tools
fi

pushd tools
git pull origin master
popd

0 comments on commit 112e656

Please sign in to comment.
You can’t perform that action at this time.