Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile and VSCode launch scripts to run logcabin build in docker container. #239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Docker",
"type": "cppdbg",
"request": "launch",
"program": "build/test/test",
"args": [],
"stopAtEntry": false,
"cwd": "/logcabin",
"environment": [],
"externalConsole": true,
"preLaunchTask": "scons-build",
"MIMode": "gdb",
"targetArchitecture": "x64",
"sourceFileMap": { "/logcabin": "${workspaceFolder}" },
"pipeTransport": {
"debuggerPath": "/usr/bin/gdb",
"pipeProgram": "docker",
"pipeArgs": ["run", "--rm", "--interactive","--volume","${workspaceFolder}:/logcabin","--workdir","/logcabin","--privileged","logcabin-dev:latest","/bin/bash","-c"],
"pipeCwd": ""
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
63 changes: 63 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp"
}
}
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "scons-build",
"type": "shell",
"command": "docker run --rm -i -v $(pwd):/logcabin logcabin-dev:latest scons"
}
]
}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ubuntu:18.04

RUN apt-get update && \
apt-get install -y \
gcc=4:7.4.0-1ubuntu2.3 g++=4:7.4.0-1ubuntu2.3 gdb=8.1-0ubuntu3.2 \
scons=3.0.1-1 \
libcrypto++-dev=5.6.4-8 \
libprotobuf-dev=3.0.0-9.1ubuntu1 protobuf-compiler=3.0.0-9.1ubuntu1 \
doxygen=1.8.13-10 \
net-tools

VOLUME /logcabin

WORKDIR /logcabin
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ To install a bunch of things on your filesystem, run:

Along with the binaries, this installs a RHEL 6-compatible init script.

If you don't want these files to pollute your filesystem, you can install the files
to any given directory as follows (replace `pathtoinstallprefix` in both places
with wherever you'd like the files to go):
If you don't want these files to pollute your filesystem,
you can install the files to any given directory as follows
(replace `pathtoinstallprefix` in both places with wherever you'd like the files to go):

scons --install-sandbox=pathtoinstallprefix pathtoinstallprefix

Expand All @@ -300,3 +300,42 @@ All commits should pass the pre-commit hooks. Enable them to run before each
commit:

ln -s ../../hooks/pre-commit .git/hooks/pre-commit

Running with Docker
======================

Getting all the dependencies right to build and run logcabin can be an issue.
Its easier to run it with a docker container where dependency versions
are managed properly. There is a dockerfile which can be used as following
1. Install docker (https://www.docker.com/)
2. Make sure to add your user to docker group
so that you do not need to use sudo to run docker

sudo usermod -aG docker $USER

3. Enable IP6 support on docker
as explained here https://docs.docker.com/config/daemon/ipv6/.

4. Build docker image by running command:

docker build . -t logcabin-dev

5. Run the container and map current working directory to /logcabin volume

docker run -it -v $(pwd):/logcabin logcabin-dev:latest /bin/bash

6. In the container, you can run steps documented in the above sections.
e.g. To build the code within container. run scons after running step 2.

Debugging with VSCode
======================

It is possible to run and debug C++ code in the docker container with VSCode.
The .vscode folder contains task to build the logcabin code in docker container
and launch configurations to be able to run and debug logcabin code from within VSCode.

1. Install VSCode https://code.visualstudio.com/
2. Install remote development extension for VSCode from
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
3. Open logcabin folder.
4. Run/Debug by executing Run menu.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only scratched the surface using vscode and the remote development plugin. Run/Debug in the Run menu gave me a permission denied error. Related, I had to run all the docker commands with sudo. Is there a configuration step that I'm missing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added an instruction in README to add user to docker group after docker installation, so that you do not need to run sudo. That should remove the permission denied errors.