Preparing Docker image with Qt installed

I’ve recently came up with a need to use a Docker container as a build machine, where Qt Framework was involved. Here is how I solved the way to automatically build the Docker image with a crafted Dockerfile.

I was using Qt version 5.9.4, and the image was based on Ubuntu 18.04.

The dockerfile ended up having such entries:

FROM ubuntu:18.04

RUN apt-get update 
RUN apt-get install unzip wget

ENV QT_VERSION_A=5.9
ENV QT_VERSION_B=5.9.4
ENV QT_VERSION_SCRIPT=594
RUN wget https://download.qt.io/archive/qt/${QT_VERSION_A}/${QT_VERSION_B}/qt-opensource-linux-x64-${QT_VERSION_B}.run
RUN chmod +x qt-opensource-linux-x64-${QT_VERSION_B}.run 
COPY qt-noninteractive.qs /qt-noninteractive.qs
RUN ./qt-opensource-linux-x64-${QT_VERSION_B}.run --script qt-noninteractive.qs  -platform minimal

Additionally, it requires a installer automation script named qt-noninteractive.qs that should co-resite with Dockerfile (in the same directory), having the following content:

function Controller() {
    installer.autoRejectMessageBoxes();
    installer.installationFinished.connect(function() {
        gui.clickButton(buttons.NextButton);
    })
}

Controller.prototype.WelcomePageCallback = function() {
    gui.clickButton(buttons.NextButton, 3000);
}

Controller.prototype.CredentialsPageCallback = function() {
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.IntroductionPageCallback = function() {
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.TargetDirectoryPageCallback = function()
{
    gui.currentPageWidget().TargetDirectoryLineEdit.setText("/qt");
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.ComponentSelectionPageCallback = function() {
    var widget = gui.currentPageWidget();

    widget.selectAll();
    widget.deselectComponent('qt.594.src');

    // widget.deselectAll();
    // widget.selectComponent("qt.594.gcc_64")
    // // widget.selectComponent("qt.594.doc")
    // // widget.selectComponent("qt.594.examples")
    // widget.selectComponent("qt.594.qtcharts")
    // widget.selectComponent("qt.594.qtcharts.gcc_64")
    // widget.selectComponent("qt.594.qtdatavis3d")
    // widget.selectComponent("qt.594.qtdatavis3d.gcc_64")
    // widget.selectComponent("qt.594.qtnetworkauth")
    // widget.selectComponent("qt.594.qtnetworkauth.gcc_64")
    // widget.selectComponent("qt.594.qtpurchasing")
    // widget.selectComponent("qt.594.qtpurchasing.gcc_64")
    // widget.selectComponent("qt.594.qtremoteobjects")
    // widget.selectComponent("qt.594.qtremoteobjects.gcc_64")
    // widget.selectComponent("qt.594.qtscript")
    // widget.selectComponent("qt.594.qtspeech")
    // widget.selectComponent("qt.594.qtspeech.gcc_64")
    // widget.selectComponent("qt.594.qtvirtualkeyboard")
    // widget.selectComponent("qt.594.qtvirtualkeyboard.gcc_64")
    // widget.selectComponent("qt.594.qtwebengine")
    // widget.selectComponent("qt.594.qtwebengine.gcc_64")
    // // widget.selectComponent("qt.594.src")
    // widget.selectComponent("qt.tools.qtcreator")

    gui.clickButton(buttons.NextButton);
}

Controller.prototype.LicenseAgreementPageCallback = function() {
    gui.currentPageWidget().AcceptLicenseRadioButton.setChecked(true);
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.StartMenuDirectoryPageCallback = function() {
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.ReadyForInstallationPageCallback = function()
{
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.FinishedPageCallback = function() {
var checkBoxForm = gui.currentPageWidget().LaunchQtCreatorCheckBoxForm
if (checkBoxForm && checkBoxForm.launchQtCreatorCheckBox) {
    checkBoxForm.launchQtCreatorCheckBox.checked = false;
}
    gui.clickButton(buttons.FinishButton);
}

The bits on how to use this file to automate Qt installation process is taken from: https://stackoverflow.com/a/34032216/78204

You can uncomment specific items and have additinal fine grain control over which Qt components are being installed (I took all).

That’s about it. The receipe gives you a Docker image with Qt framework installed in /qt directory, and available for usage in builds and compilations.

comments powered by Disqus