Skip to content

Commit

Permalink
Merge pull request #272
Browse files Browse the repository at this point in the history
1bb60ff docker: adds script to start docker with volume (Stephanie Stroka)
  • Loading branch information
douglasbakkum committed May 9, 2019
2 parents ca4ba7d + 1bb60ff commit 921eb5d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 26 deletions.
35 changes: 20 additions & 15 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
# Copyright 2018 Shift Devices AG
# The MIT License (MIT)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Copyright 2019 Shift Cryptosecurity AG
#
# http://www.apache.org/licenses/LICENSE-2.0
# 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:
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
#
# Run with Docker:
# docker build --tag shift/mcu-base -f Dockerfile.dev .
#

FROM debian:stretch
ENV DEBIAN_FRONTEND noninteractive
WORKDIR /app
COPY . /app

RUN apt update && apt-get install -y cmake git wget locales python python-pip
RUN mkdir ~/Downloads && cd ~/Downloads && wget -O gcc.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2
Expand All @@ -30,5 +35,5 @@ RUN apt install -y libbz2-dev libbz2-dev libbz2-1.0 libncurses5 libz1 valgrind a
RUN pip install --prefix /usr/local cpp-coveralls
RUN locale-gen UTF-8
ENV CC gcc
RUN cd /app/ && mkdir docker-build && cd docker-build && cmake .. -DBUILD_TYPE=firmware -DUSE_SECP256K1_LIB=ON && make TEST=yes
RUN sha256sum docker-build/bin/*

CMD ["bash"]
29 changes: 18 additions & 11 deletions Dockerfile.tests
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Copyright 2018 Shift Devices AG
# The MIT License (MIT)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Copyright 2019 Shift Cryptosecurity AG
#
# http://www.apache.org/licenses/LICENSE-2.0
# 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:
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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.
#
# Run with Docker:
# docker build --tag shift/mcu-base-tests -f Dockerfile.tests .
Expand All @@ -21,7 +29,6 @@ ENV DEBIAN_FRONTEND noninteractive
WORKDIR /app
COPY . /app


RUN gcc -v
RUN clang -v
ENV CC gcc
Expand Down
59 changes: 59 additions & 0 deletions dockerdev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash -e
#
# The MIT License (MIT)
#
# Copyright 2019 Shift Cryptosecurity AG
#
# 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.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

dockerdev () {
local container_image=shift/mcu-base
local container_name=mcu-dev

if ! docker images | grep -q $container_image; then
echo "No $container_image docker image found! Maybe you need to run 'docker build --tag $container_image -f Dockerfile.dev .'?" >&2
exit 1
fi

# If already running, enter the container.
if docker ps | grep -q $container_name; then
docker exec -it $container_name bash
return
fi

if docker ps -a | grep -q $container_name; then
docker rm $container_name
fi

local repo_path="$DIR"
docker run \
--detach \
--privileged -v /dev/bus/usb:/dev/bus/usb \
--interactive --tty \
--name=$container_name \
-v $repo_path:/app \
$container_image bash

# Call a second time to enter the container.
dockerdev
}

dockerdev

0 comments on commit 921eb5d

Please sign in to comment.