Skip to content

Commit

Permalink
Merge pull request #44 from tritonuas/chore/devcontainer-non-root
Browse files Browse the repository at this point in the history
enter dev container as non-root user
  • Loading branch information
Tyler-Lentz authored Oct 29, 2023
2 parents 4dfd1c4 + fffacc7 commit 42bef54
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
33 changes: 12 additions & 21 deletions Dockerfile → .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
FROM amd64/ubuntu:22.04

# Create a non-root user
ARG USERNAME=tuas
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME


# https://gist.github.com/SSARCandy/fc960d8905330ac695e71e3f3807ce3d
# OpenCV dependencies from above
RUN apt-get update \
Expand All @@ -20,6 +29,7 @@ RUN apt-get update \

# TODO: is it possible to save the built opencv in the docker build? Need to see what cmake keeps checking and wasting time on.

# Download latest CMake from their repositories
RUN apt-get update \
&& rm -rf /var/lib/apt/lists/* \
&& wget https://github.com/Kitware/CMake/releases/download/v3.27.7/cmake-3.27.7-linux-x86_64.sh \
Expand All @@ -30,24 +40,5 @@ RUN apt-get update \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin

WORKDIR /obcpp

COPY . /obcpp

WORKDIR /obcpp/build

# RUN cmake ..

# RUN make obcpp # parallelize this

CMD ["/bin/bash"]
# CMD ["/obcpp/build/bin/obcpp"]

# docker build - < Dockerfile
# docker build -t "test" .
# docker run -it --rm test

# https://www.jmoisio.eu/en/blog/2020/06/01/building-cpp-containers-using-docker-and-cmake/
# find -name "*Cache.txt" -delete

# TODO: this container is way too big for some reason. Refer to above blog post for staged build (may not want to do that for development tho. I am unable to get devcontainers running)
# login as non-root user
USER $USERNAME
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// See this page for reference of options: https://containers.dev/implementors/json_reference
{
"name": "Existing Dockerfile",
"build": {
"context": "..",
"dockerfile": "Dockerfile"
},

"customizations": {
"vscode": {
"settings": {
// Use bash instead of sh
"terminal.integrated.defaultProfile.linux": "bash"
},
"extensions": [
"shd101wyy.markdown-preview-enhanced",
"ms-vscode.cpptools",
"nick-dimeglio.family-guy-funny-moments", // ඞ
"twxs.cmake"
]
}
}

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": ""
}
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ _deps/
Testing/

.vscode
.devcontainer

libcore_library.dylib
.DS_Store

0 comments on commit 42bef54

Please sign in to comment.