From 2ddd255ef89aef49f27094964d6d35fadf802c32 Mon Sep 17 00:00:00 2001 From: Roland Singer Date: Thu, 31 Jan 2019 15:40:04 +0100 Subject: [PATCH] further progress on docker containers --- docker/Makefile | 9 +- docker/README.md | 4 - docker/android/Dockerfile | 15 +++ docker/common/base | 22 ++-- docker/common/windows | 12 +++ docker/generate.go | 136 +++++++++++++++++++++++++ docker/linux/Dockerfile | 26 ++--- docker/linux/Dockerfile.in | 13 ++- docker/windows/Dockerfile | 83 +++++++++++++++ docker/windows/Dockerfile.in | 51 ++++++++++ docker/windows_32_static/Dockerfile | 15 +++ docker/windows_32_static/Dockerfile.in | 8 ++ docker/windows_64_static/Dockerfile | 60 ++--------- docker/windows_64_static/Dockerfile.in | 15 +-- internal/build/context.go | 2 +- internal/build/qtproject.go | 6 +- 16 files changed, 365 insertions(+), 112 deletions(-) delete mode 100644 docker/README.md create mode 100644 docker/android/Dockerfile create mode 100644 docker/common/windows create mode 100644 docker/generate.go create mode 100644 docker/windows/Dockerfile create mode 100644 docker/windows/Dockerfile.in create mode 100644 docker/windows_32_static/Dockerfile create mode 100644 docker/windows_32_static/Dockerfile.in diff --git a/docker/Makefile b/docker/Makefile index fac3dbd..5f220a4 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,8 +1,9 @@ -CROSSBUILD_IMAGES = linux windows_64_static +CROSSBUILD_IMAGES = linux android windows windows_64_static windows_32_static -$(CROSSBUILD_IMAGES): %: - echo "# This file is auto-generated." > $@/Dockerfile - awk '/import common.base/{system("cat common/base");next}1' $@/Dockerfile.in >> $@/Dockerfile +$(CROSSBUILD_IMAGES): %: generate docker build ./ -f $@/Dockerfile -t desertbit/gml:$@ +generate: + go run generate.go + .PHONY: $(CROSSBUILD_IMAGES) \ No newline at end of file diff --git a/docker/README.md b/docker/README.md deleted file mode 100644 index e8aff11..0000000 --- a/docker/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Docker containers - -## Credits -- https://github.com/therecipe/qt/tree/master/internal/docker \ No newline at end of file diff --git a/docker/android/Dockerfile b/docker/android/Dockerfile new file mode 100644 index 0000000..a0494e8 --- /dev/null +++ b/docker/android/Dockerfile @@ -0,0 +1,15 @@ +FROM desertbit/gml:linux +MAINTAINER team@desertbit.com + +# Install dependencies. +# http://doc.qt.io/qt-5/android-getting-started.html +RUN apt-get -y update && \ + apt-get -y install android-sdk && \ + apt-get -y clean + +# TODO: finish this +# Install android NDK +# https://developer.android.com/ndk/downloads/ +RUN mkdir /tmp/ndk && cd /tmp/ndk && \ + wget https://dl.google.com/android/repository/android-ndk-r19-linux-x86_64.zip && \ + rm -rf /tmp/ndk diff --git a/docker/common/base b/docker/common/base index e05c3af..d024365 100644 --- a/docker/common/base +++ b/docker/common/base @@ -1,17 +1,6 @@ -# Install dependencies. -RUN apt-get -y update && \ - apt-get -y install sudo git wget nano make pkg-config && \ - apt-get -y clean - -ENV PATH="/$QT_ROOT/bin:$PATH" \ - PKG_CONFIG_PATH="$QT_ROOT/lib/pkgconfig:$PKG_CONFIG_PATH" \ - LD_LIBRARY_PATH="$QT_ROOT/lib:$LD_LIBRARY_PATH" - -# Install the Go compiler. We can't assure, that the go compiler is up-to-date from the base package. -RUN export GO_VERSION="1.11.4" && \ - export GO_CHECKSUM="fb26c30e6a04ad937bbc657a1b5bba92f80096af1e8ee6da6430c045a8db3a5b" && \ - rm -rf "$(go env GOROOT)" && \ - rm -rf /usr/local/go && \ +# Install the Go compiler. +RUN export GO_VERSION="1.11.5" && \ + export GO_CHECKSUM="ff54aafedff961eb94792487e827515da683d61a5f9482f668008832631e5d25" && \ mkdir -p /tmp/go && \ cd /tmp/go && \ wget -O go.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \ @@ -19,7 +8,8 @@ RUN export GO_VERSION="1.11.4" && \ tar -xvf go.tar.gz && \ mv go /usr/local && \ rm -rf /tmp/go -ENV GOROOT=/usr/local/go \ +ENV PATH="$PATH:/usr/local/go/bin" \ + GOROOT=/usr/local/go \ GOPATH=/work \ CGO_ENABLED=1 @@ -39,4 +29,4 @@ WORKDIR /work ADD common/entrypoint.sh /entrypoint RUN chmod +x /entrypoint ENTRYPOINT ["/entrypoint"] -CMD ["gml"] +CMD ["gml"] \ No newline at end of file diff --git a/docker/common/windows b/docker/common/windows new file mode 100644 index 0000000..460cbca --- /dev/null +++ b/docker/common/windows @@ -0,0 +1,12 @@ +RUN cd /mxe && \ + export NUM_CORES="$(grep -c processor /proc/cpuinfo)" && \ + make -j${NUM_CORES} MXE_TARGETS="${CROSS_TRIPLE}" qtbase qtquickcontrols2 + +ENV PATH="/mxe/usr/bin:/mxe/usr/${CROSS_TRIPLE}/qt5/bin:$PATH" \ + PKG_CONFIG="/mxe/usr/bin/${CROSS_TRIPLE}-pkg-config" \ + PKG_CONFIG_PATH="/mxe/usr/${CROSS_TRIPLE}/qt5/lib/pkgconfig:$PKG_CONFIG_PATH" \ + CC="${CROSS_TRIPLE}-gcc" \ + CXX="${CROSS_TRIPLE}-g++" + +# Patch to include some missing libraries for cgo. Otherwise the linker fails. +RUN sed -i "s|Libs.private:|Libs.private: -lstdc++ |g" "/mxe/usr/${CROSS_TRIPLE}/qt5/lib/pkgconfig/Qt5Core.pc" \ No newline at end of file diff --git a/docker/generate.go b/docker/generate.go new file mode 100644 index 0000000..60be85c --- /dev/null +++ b/docker/generate.go @@ -0,0 +1,136 @@ +/* + * GML - Go QML + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Roland Singer + * Copyright (c) 2019 Sebastian Borchers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" + "strings" + + "github.com/desertbit/gml/internal/utils" +) + +const ( + ImportPrefix = "#import" +) + +func main() { + // Prepare the base dir. + baseDir, err := os.Getwd() + if err != nil { + log.Fatalln("failed to get current working dir:", err) + } + + // Generate all Dockerfiles from Dockerfile.in files. + err = generate(baseDir) + if err != nil { + log.Fatalln("failed to generate Dockerfiles:", err) + } +} + +func generate(baseDir string) (err error) { + var ( + e bool + data []byte + ) + + entries, err := ioutil.ReadDir(baseDir) + if err != nil { + return + } + + for _, fi := range entries { + if !fi.IsDir() { + continue + } + t := filepath.Base(fi.Name()) + + dockerFile := filepath.Join(baseDir, t, "Dockerfile") + dockerFileIn := dockerFile + ".in" + + e, err = utils.Exists(dockerFileIn) + if err != nil { + return + } else if !e { + continue + } + + fmt.Println("> generating:", t) + + data, err = ioutil.ReadFile(dockerFileIn) + if err != nil { + return + } + + var out *os.File + out, err = os.Create(dockerFile) + if err != nil { + return + } + defer out.Close() + + lines := strings.Split(string(data), "\n") + for _, line := range lines { + if !strings.HasPrefix(strings.TrimSpace(line), ImportPrefix) { + _, err = out.WriteString(line + "\n") + if err != nil { + return + } + continue + } + + line = strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(line), ImportPrefix)) + if len(line) == 0 { + return fmt.Errorf("invalid import command: %s", line) + } + + importFile := filepath.Join(baseDir, line) + e, err = utils.Exists(importFile) + if err != nil { + return + } else if !e { + return fmt.Errorf("invalid import command: %s", line) + } + + data, err = ioutil.ReadFile(importFile) + if err != nil { + return + } + + _, err = out.WriteString(string(data) + "\n") + if err != nil { + return + } + } + + } + return +} diff --git a/docker/linux/Dockerfile b/docker/linux/Dockerfile index 030e0a0..43ee6fa 100644 --- a/docker/linux/Dockerfile +++ b/docker/linux/Dockerfile @@ -1,24 +1,15 @@ -# This file is auto-generated. -FROM therecipe/qt:linux - -ENV QT_ROOT="/opt/Qt/5.12.0/gcc_64" \ - GOOS=linux \ - GOARCH=amd64 +FROM ubuntu:18.04 +MAINTAINER team@desertbit.com # Install dependencies. RUN apt-get -y update && \ - apt-get -y install sudo git wget nano make pkg-config && \ + apt-get -y install build-essential sudo git wget nano make pkg-config \ + qt5-default qttools5-dev-tools qtdeclarative5-dev && \ apt-get -y clean -ENV PATH="/$QT_ROOT/bin:$PATH" \ - PKG_CONFIG_PATH="$QT_ROOT/lib/pkgconfig:$PKG_CONFIG_PATH" \ - LD_LIBRARY_PATH="$QT_ROOT/lib:$LD_LIBRARY_PATH" - -# Install the Go compiler. We can't assure, that the go compiler is up-to-date from the base package. -RUN export GO_VERSION="1.11.4" && \ - export GO_CHECKSUM="fb26c30e6a04ad937bbc657a1b5bba92f80096af1e8ee6da6430c045a8db3a5b" && \ - rm -rf "$(go env GOROOT)" && \ - rm -rf /usr/local/go && \ +# Install the Go compiler. +RUN export GO_VERSION="1.11.5" && \ + export GO_CHECKSUM="ff54aafedff961eb94792487e827515da683d61a5f9482f668008832631e5d25" && \ mkdir -p /tmp/go && \ cd /tmp/go && \ wget -O go.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \ @@ -26,7 +17,8 @@ RUN export GO_VERSION="1.11.4" && \ tar -xvf go.tar.gz && \ mv go /usr/local && \ rm -rf /tmp/go -ENV GOROOT=/usr/local/go \ +ENV PATH="$PATH:/usr/local/go/bin" \ + GOROOT=/usr/local/go \ GOPATH=/work \ CGO_ENABLED=1 diff --git a/docker/linux/Dockerfile.in b/docker/linux/Dockerfile.in index ec850f4..25c8a1a 100644 --- a/docker/linux/Dockerfile.in +++ b/docker/linux/Dockerfile.in @@ -1,7 +1,10 @@ -FROM therecipe/qt:linux +FROM ubuntu:18.04 +MAINTAINER team@desertbit.com -ENV QT_ROOT="/opt/Qt/5.12.0/gcc_64" \ - GOOS=linux \ - GOARCH=amd64 +# Install dependencies. +RUN apt-get -y update && \ + apt-get -y install build-essential sudo git wget nano make pkg-config \ + qt5-default qttools5-dev-tools qtdeclarative5-dev && \ + apt-get -y clean -#import common.base \ No newline at end of file +#import common/base \ No newline at end of file diff --git a/docker/windows/Dockerfile b/docker/windows/Dockerfile new file mode 100644 index 0000000..270ec91 --- /dev/null +++ b/docker/windows/Dockerfile @@ -0,0 +1,83 @@ +FROM debian:8 +MAINTAINER team@desertbit.com + +# Install dependencies. +# https://mxe.cc/#requirements +RUN apt-get -y update && \ + apt-get -y install \ + sudo \ + nano \ + autoconf \ + automake \ + autopoint \ + bash \ + bison \ + bzip2 \ + flex \ + g++ \ + g++-multilib \ + gettext \ + git \ + gperf \ + intltool \ + libc6-dev-i386 \ + libgdk-pixbuf2.0-dev \ + libltdl-dev \ + libssl-dev \ + libtool-bin \ + libxml-parser-perl \ + lzip \ + make \ + openssl \ + p7zip-full \ + patch \ + perl \ + pkg-config \ + python \ + ruby \ + sed \ + unzip \ + wget \ + xz-utils && \ + apt-get -y clean + +# Install the Go compiler. +RUN export GO_VERSION="1.11.5" && \ + export GO_CHECKSUM="ff54aafedff961eb94792487e827515da683d61a5f9482f668008832631e5d25" && \ + mkdir -p /tmp/go && \ + cd /tmp/go && \ + wget -O go.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \ + echo "${GO_CHECKSUM} go.tar.gz" | sha256sum -c && \ + tar -xvf go.tar.gz && \ + mv go /usr/local && \ + rm -rf /tmp/go +ENV PATH="$PATH:/usr/local/go/bin" \ + GOROOT=/usr/local/go \ + GOPATH=/work \ + CGO_ENABLED=1 + +# Install the gml tool. +RUN mkdir -p /tmp/go && cd /tmp/go && \ + export GOPATH="/tmp/go" && \ + export GOOS=linux && \ + export GOARCH=amd64 && \ + go get github.com/desertbit/gml/cmd/gml && \ + mv -f /tmp/go/bin/gml /bin/gml && \ + rm -rf /tmp/go + +RUN mkdir /work +VOLUME /work +WORKDIR /work + +ADD common/entrypoint.sh /entrypoint +RUN chmod +x /entrypoint +ENTRYPOINT ["/entrypoint"] +CMD ["gml"] + +# https://mxe.cc +# https://stackoverflow.com/questions/14170590/building-qt-5-on-linux-for-windows/14170591#14170591 +RUN export MXE_COMMIT="744f553022aabe5c9946828235b6a5dd9416a6d0" && \ + git clone https://github.com/mxe/mxe.git /mxe && \ + cd /mxe && \ + git checkout "${MXE_COMMIT}" + diff --git a/docker/windows/Dockerfile.in b/docker/windows/Dockerfile.in new file mode 100644 index 0000000..5d6e0d3 --- /dev/null +++ b/docker/windows/Dockerfile.in @@ -0,0 +1,51 @@ +FROM debian:8 +MAINTAINER team@desertbit.com + +# Install dependencies. +# https://mxe.cc/#requirements +RUN apt-get -y update && \ + apt-get -y install \ + sudo \ + nano \ + autoconf \ + automake \ + autopoint \ + bash \ + bison \ + bzip2 \ + flex \ + g++ \ + g++-multilib \ + gettext \ + git \ + gperf \ + intltool \ + libc6-dev-i386 \ + libgdk-pixbuf2.0-dev \ + libltdl-dev \ + libssl-dev \ + libtool-bin \ + libxml-parser-perl \ + lzip \ + make \ + openssl \ + p7zip-full \ + patch \ + perl \ + pkg-config \ + python \ + ruby \ + sed \ + unzip \ + wget \ + xz-utils && \ + apt-get -y clean + +#import common/base + +# https://mxe.cc +# https://stackoverflow.com/questions/14170590/building-qt-5-on-linux-for-windows/14170591#14170591 +RUN export MXE_COMMIT="744f553022aabe5c9946828235b6a5dd9416a6d0" && \ + git clone https://github.com/mxe/mxe.git /mxe && \ + cd /mxe && \ + git checkout "${MXE_COMMIT}" diff --git a/docker/windows_32_static/Dockerfile b/docker/windows_32_static/Dockerfile new file mode 100644 index 0000000..fe0f0cb --- /dev/null +++ b/docker/windows_32_static/Dockerfile @@ -0,0 +1,15 @@ +FROM desertbit/gml:windows +MAINTAINER team@desertbit.com + +ENV CROSS_TRIPLE="x86_64-w64-mingw32.static" \ + GOOS=windows \ + GOARCH=amd64 + +RUN cd /mxe && \ + export NUM_CORES="$(grep -c processor /proc/cpuinfo)" && \ + make -j${NUM_CORES} MXE_TARGETS="${CROSS_TRIPLE}" qtbase qtquickcontrols2 + +ENV PATH="/mxe/usr/bin:/mxe/usr/${CROSS_TRIPLE}/qt5/bin:$PATH" \ + PKG_CONFIG="/mxe/usr/bin/${CROSS_TRIPLE}-pkg-config" \ + PKG_CONFIG_PATH="/mxe/usr/${CROSS_TRIPLE}/qt5/lib/pkgconfig:$PKG_CONFIG_PATH" + diff --git a/docker/windows_32_static/Dockerfile.in b/docker/windows_32_static/Dockerfile.in new file mode 100644 index 0000000..f0fdd99 --- /dev/null +++ b/docker/windows_32_static/Dockerfile.in @@ -0,0 +1,8 @@ +FROM desertbit/gml:windows +MAINTAINER team@desertbit.com + +ENV CROSS_TRIPLE="i686-w64-mingw32.static" \ + GOOS=windows \ + GOARCH=386 + +#import common/windows diff --git a/docker/windows_64_static/Dockerfile b/docker/windows_64_static/Dockerfile index 6e183e3..fe0f0cb 100644 --- a/docker/windows_64_static/Dockerfile +++ b/docker/windows_64_static/Dockerfile @@ -1,57 +1,15 @@ -# This file is auto-generated. -FROM therecipe/qt:windows_64_static +FROM desertbit/gml:windows +MAINTAINER team@desertbit.com -ENV CROSS_TRIPLE="x86_64-w64-mingw32.static" -ENV QT_ROOT="/usr/lib/mxe/usr/$CROSS_TRIPLE/qt5" \ +ENV CROSS_TRIPLE="x86_64-w64-mingw32.static" \ GOOS=windows \ GOARCH=amd64 -# Install dependencies. -RUN apt-get -y update && \ - apt-get -y install sudo git wget nano make pkg-config && \ - apt-get -y clean +RUN cd /mxe && \ + export NUM_CORES="$(grep -c processor /proc/cpuinfo)" && \ + make -j${NUM_CORES} MXE_TARGETS="${CROSS_TRIPLE}" qtbase qtquickcontrols2 -ENV PATH="/$QT_ROOT/bin:$PATH" \ - PKG_CONFIG_PATH="$QT_ROOT/lib/pkgconfig:$PKG_CONFIG_PATH" \ - LD_LIBRARY_PATH="$QT_ROOT/lib:$LD_LIBRARY_PATH" +ENV PATH="/mxe/usr/bin:/mxe/usr/${CROSS_TRIPLE}/qt5/bin:$PATH" \ + PKG_CONFIG="/mxe/usr/bin/${CROSS_TRIPLE}-pkg-config" \ + PKG_CONFIG_PATH="/mxe/usr/${CROSS_TRIPLE}/qt5/lib/pkgconfig:$PKG_CONFIG_PATH" -# Install the Go compiler. We can't assure, that the go compiler is up-to-date from the base package. -RUN export GO_VERSION="1.11.4" && \ - export GO_CHECKSUM="fb26c30e6a04ad937bbc657a1b5bba92f80096af1e8ee6da6430c045a8db3a5b" && \ - rm -rf "$(go env GOROOT)" && \ - rm -rf /usr/local/go && \ - mkdir -p /tmp/go && \ - cd /tmp/go && \ - wget -O go.tar.gz https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \ - echo "${GO_CHECKSUM} go.tar.gz" | sha256sum -c && \ - tar -xvf go.tar.gz && \ - mv go /usr/local && \ - rm -rf /tmp/go -ENV GOROOT=/usr/local/go \ - GOPATH=/work \ - CGO_ENABLED=1 - -# Install the gml tool. -RUN mkdir -p /tmp/go && cd /tmp/go && \ - export GOPATH="/tmp/go" && \ - export GOOS=linux && \ - export GOARCH=amd64 && \ - go get github.com/desertbit/gml/cmd/gml && \ - mv -f /tmp/go/bin/gml /bin/gml && \ - rm -rf /tmp/go - -RUN mkdir /work -VOLUME /work -WORKDIR /work - -ADD common/entrypoint.sh /entrypoint -RUN chmod +x /entrypoint -ENTRYPOINT ["/entrypoint"] -CMD ["gml"] - -RUN mkdir -p /cross-bin && \ - for f in /usr/lib/mxe/usr/bin/${CROSS_TRIPLE}-*; do \ - name="$(echo "$f" | sed -e "s|^/usr/lib/mxe/usr/bin/${CROSS_TRIPLE}-||")" ;\ - ln -s "$f" "/cross-bin/${name}" ;\ - done -ENV PATH="/cross-bin:$PATH" diff --git a/docker/windows_64_static/Dockerfile.in b/docker/windows_64_static/Dockerfile.in index 5ebe16d..196909d 100644 --- a/docker/windows_64_static/Dockerfile.in +++ b/docker/windows_64_static/Dockerfile.in @@ -1,15 +1,8 @@ -FROM therecipe/qt:windows_64_static +FROM desertbit/gml:windows +MAINTAINER team@desertbit.com -ENV CROSS_TRIPLE="x86_64-w64-mingw32.static" -ENV QT_ROOT="/usr/lib/mxe/usr/$CROSS_TRIPLE/qt5" \ +ENV CROSS_TRIPLE="x86_64-w64-mingw32.static" \ GOOS=windows \ GOARCH=amd64 -#import common.base - -RUN mkdir -p /cross-bin && \ - for f in /usr/lib/mxe/usr/bin/${CROSS_TRIPLE}-*; do \ - name="$(echo "$f" | sed -e "s|^/usr/lib/mxe/usr/bin/${CROSS_TRIPLE}-||")" ;\ - ln -s "$f" "/cross-bin/${name}" ;\ - done -ENV PATH="/cross-bin:$PATH" +#import common/windows diff --git a/internal/build/context.go b/internal/build/context.go index e762fa7..ae3b672 100644 --- a/internal/build/context.go +++ b/internal/build/context.go @@ -40,7 +40,7 @@ import ( ) const ( - staticLibName = "libgml.a" // TODO: + staticLibName = "libgml.a" proFileName = "gml.pro" qmlDir = "qml" qmlResDir = "resources" diff --git a/internal/build/qtproject.go b/internal/build/qtproject.go index 175eb3a..ddaa769 100644 --- a/internal/build/qtproject.go +++ b/internal/build/qtproject.go @@ -58,7 +58,7 @@ CONFIG += staticlib win32|win64 { CONFIG += release - Release:DESTDIR = + Release:DESTDIR = {{.BuildDir}} } INCLUDEPATH += {{.GmlBindingDir}}/headers @@ -70,6 +70,6 @@ RESOURCES += {{.QMLResFile}} OBJECTS_DIR = {{.BuildDir}} MOC_DIR = {{.BuildDir}} UI_DIR = {{.BuildDir}} -TARGET = {{.BuildDir}}/gml -DESTDIR = +DESTDIR = {{.BuildDir}} +TARGET = gml `