Skip to content

Commit

Permalink
Docker: Create MacOS script
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Jan 8, 2025
1 parent 4a1adfa commit fd9386b
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 11 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Ignore Git repository files
.git
.gitignore

# Ignore node_modules or other build artifacts
node_modules
build

# Ignore Docker-related files
Dockerfile*
docker-compose.yml

# Ignore OS-specific files
.DS_Store
*.swp
36 changes: 36 additions & 0 deletions deploy/docker/Dockerfile-build-macos
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use a lightweight base image; Docker-OSX handles the macOS environment
FROM sickcodes/docker-osx:latest

# Set environment variables
ENV QT_VERSION=6.8.1
ENV QT_PATH=/opt/Qt
ENV QT_DESKTOP=$QT_PATH/${QT_VERSION}/clang_64

ENV PATH=$QT_DESKTOP/bin:/usr/local/bin:$PATH

# Install Homebrew (if not already installed)
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" \
&& eval "$(/usr/local/bin/brew shellenv)" \
&& brew update

# Install necessary dependencies via Homebrew
RUN brew install cmake ninja git

# Install Qt using Homebrew
RUN brew install qt@${QT_VERSION} \
&& brew link --force qt@${QT_VERSION}

# Set up Qt environment
RUN mkdir -p $QT_PATH \
&& ln -s /usr/local/opt/qt@${QT_VERSION} $QT_PATH/Qt

# Configure Git to trust the project directory
RUN git config --global --add safe.directory /project/source

# Set the working directory
WORKDIR /project/build

# Define the build command
CMD cmake -S /project/source -B . -G Ninja -DCMAKE_BUILD_TYPE=Release && \
cmake --build . --target all --config Release && \
cmake --install . --config Release
62 changes: 51 additions & 11 deletions deploy/docker/Dockerfile-build-ubuntu
Original file line number Diff line number Diff line change
@@ -1,28 +1,68 @@
# Use the official Ubuntu 22.04 LTS as the base image
FROM ubuntu:22.04

# ------------------------------------------------------------------------------
# Argument Definitions
# ------------------------------------------------------------------------------

ARG QT_VERSION=6.8.1
ARG QT_MODULES="qtcharts qtlocation qtpositioning qtspeech qt5compat qtmultimedia qtserialport qtimageformats qtshadertools qtconnectivity qtquick3d qtsensors"

ENV DEBIAN_FRONTEND noninteractive

ENV DISPLAY :99
# ------------------------------------------------------------------------------
# Environment Variables
# ------------------------------------------------------------------------------

ENV QT_PATH /opt/Qt
ENV QT_DESKTOP $QT_PATH/${QT_VERSION}/gcc_64
ENV DEBIAN_FRONTEND=noninteractive \
DISPLAY=:99 \
QT_PATH=/opt/Qt \
QT_DESKTOP=${QT_PATH}/${QT_VERSION}/gcc_64 \
PATH=/usr/lib/ccache:${QT_DESKTOP}/bin:${PATH} \
LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8

ENV PATH /usr/lib/ccache:$QT_DESKTOP/bin:$PATH
# ------------------------------------------------------------------------------
# Install Dependencies and Qt
# ------------------------------------------------------------------------------

# Update and install essential packages
COPY tools/setup/install-dependencies-debian.sh /tmp/qt/
RUN /tmp/qt/install-dependencies-debian.sh
RUN chmod +x /tmp/qt/install-dependencies-debian.sh && \
/tmp/qt/install-dependencies-debian.sh && \
rm /tmp/qt/install-dependencies-debian.sh

# Install Qt
COPY tools/setup/install-qt-debian.sh /tmp/qt/
RUN /tmp/qt/install-qt-debian.sh
RUN chmod +x /tmp/qt/install-qt-debian.sh && \
/tmp/qt/install-qt-debian.sh && \
rm /tmp/qt/install-qt-debian.sh

# Generate and set locale
RUN locale-gen en_US.UTF-8 && dpkg-reconfigure locales

# Configure Git to recognize the project directory as safe
RUN git config --global --add safe.directory /project/source

# ------------------------------------------------------------------------------
# Add Non-Root User (Optional but Recommended)
# ------------------------------------------------------------------------------

# Uncomment the following lines to add a non-root user
# RUN useradd -m builder
# USER builder
# WORKDIR /home/builder/project/build

# ------------------------------------------------------------------------------
# Set Working Directory
# ------------------------------------------------------------------------------

WORKDIR /project/build
CMD cmake -S /project/source -B . -G Ninja -DCMAKE_BUILD_TYPE=Release ; \
cmake --build . --target all --config Release ; \
cmake --install . --config Release

# ------------------------------------------------------------------------------
# Build Commands
# ------------------------------------------------------------------------------

CMD set -ex && \
cmake -S /project/source -B . -G Ninja -DCMAKE_BUILD_TYPE=Release && \
cmake --build . --target all --config Release && \
cmake --install . --config Release
16 changes: 16 additions & 0 deletions deploy/docker/run-docker-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Exit immediately if a command exits with a non-zero status
set -e

# Build the macOS Docker-OSX image
docker build --file ./deploy/docker/Dockerfile-build-macos -t qgc-macos-docker .

# Run the Docker-OSX container with necessary volume mounts
docker run --rm \
--cap-add SYS_ADMIN \
--device /dev/fuse \
--security-opt apparmor:unconfined \
-v "${PWD}:/project/source" \
-v "${PWD}/build:/project/build" \
qgc-macos-docker
2 changes: 2 additions & 0 deletions tools/setup/install-dependencies-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,5 @@ fi
# Ubuntu 22.04
# wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc
# wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list http://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list

DEBIAN_FRONTEND=noninteractive apt-get clean && rm -rf /var/lib/apt/lists/*

0 comments on commit fd9386b

Please sign in to comment.