Docker Image to build InfiniSim
This PR adds a Dockerfile that allows to build InfiniSim in a pre-configured, separate environment. It follows the structure and idea of the InfiniTime Dockerfile. Furthermore instructions are added to the README.md.
I think a devcontainer.json would increase developer benefit even more since it allows you to use the container as an pre-setup development environment (for example in VsCode or IDEs). A minimal initial version would look like this:
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "InfiniSim Dev Container",
"build": {
"dockerfile": "Dockerfile"
},
// Configure tool-specific properties.
"customizations": {
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"marus25.cortex-debug",
"notskm.clang-tidy",
"mjohns.clang-format",
"timonwong.shellcheck"
]
}
},
"mounts": [
// Local volume to store bash history across rebuilds
"source=projectname-bashhistory,target=/commandhistory,type=volume"
// Uncomment and modify path to mount external InfiniTime source into the container
//,"source=/home/example/InfiniTime,target=/workspaces/InfiniTime,type=bind,consistency=cached"
],
// Sudo password "it"
"remoteUser": "infinitime"
}
I took the liberty of adapting the Dockerfile from your PR to be better suited for interactive use. This is mainly adding a non-root user with sudo password (infinitime:it) as well as git. I also added a volume to persist bash history across container rebuilds.
FROM ubuntu:22.04
# Install dependencies
ARG DEBIAN_FRONTEND=noninteractive
ARG NODE_MAJOR=20
RUN apt-get update -qq && \
apt-get install -y \
curl \
cmake \
ccache \
libsdl2-dev \
g++ \
git \
libpng-dev \
ninja-build \
sudo \
python3-pip \
python3-venv \
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/* \
&& curl -sL https://deb.nodesource.com/setup_${NODE_MAJOR}.x -o nodesource_setup.sh \
&& bash nodesource_setup.sh \
&& apt-get install -y nodejs \
&& npm install -g [email protected] \
&& pip install wheel Pillow
# Add the infinitime user with sudo password "it" for developing in devcontainer
RUN adduser infinitime && echo "infinitime:it" | chpasswd && usermod -aG sudo infinitime
# Persist bash history across container rebuilds
# Reference: https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history
ARG USERNAME=infinitime
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
&& mkdir /commandhistory \
&& touch /commandhistory/.bash_history \
&& chown -R $USERNAME /commandhistory \
&& echo "$SNIPPET" >> "/home/$USERNAME/.bashrc"
WORKDIR /sources
# Build configuration environment variables
ENV INFITIME_DIR="/sources/InfiniTime"
ENV BUILD_FLAGS=""
CMD ["bash", "-c", "cmake -S . -B build -DInfiniTime_DIR=${INFITIME_DIR} ${BUILD_FLAGS} && cmake --build build -j4"]
Both files are to be placed in the following layout:
.devcontainer/
|-- Dockerfile
`-- devcontainer.json
I tested this with VsCode and it works very well. You can open the repo in a dev container and build with CMake. With VsCode under Linux I am able to run the infinisim executable directly inside the Docker dev container.
Feel free to add any of this to your PR if you and the maintainers would like to. I like projects providing a dev environment ready with all requirements.
changes included in https://github.com/InfiniTimeOrg/InfiniSim/pull/174
Thanks for the initial push with the Dockerfile!