Skip to content

Commit 97d3edb

Browse files
authored
docker improvements (#2455)
1 parent 4c18b80 commit 97d3edb

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
build
1+
*
2+
!firmware/tools/docker-entrypoint.sh

dockerize.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
#################################################
4+
# This script aids building mayhem inside docker
5+
#
6+
# Basic usage:
7+
# - Build dev container: ./dockerize.sh build
8+
# - Build mayhem: ./dockerize.sh
9+
#
10+
# The image will be automatically build if it
11+
# does not exist, but if the dockerfile changes
12+
# it need to be rebuilt manually.
13+
#
14+
# Advanced parameters:
15+
# - Get a shell inside the build image to
16+
# inspect problems: ./dockerize.sh shell
17+
# - Give additional parameters to the container:
18+
# ./dockerize.sh -j10
19+
# ./dockerize.sh ninja -j10
20+
# - Use a different dockerfile:
21+
# ./dockerize.sh build dockerfile-other
22+
# - Use a different cpu architecture:
23+
# ./dockerize.sh build dockerfile-nogit-arm arm64
24+
#
25+
# Environment variables:
26+
# - It is possible to override the default image
27+
# name that is being used to build and run the
28+
# build container using an environment variable.
29+
# The default is 'portapack-dev'
30+
# Override by setting the following environment
31+
# variable: MAYHEM_DEV_DOCKER_IMAGE
32+
#
33+
34+
#
35+
# Copyright (C) 2024 u-foka
36+
#
37+
# This file is part of PortaPack.
38+
#
39+
# This program is free software; you can redistribute it and/or modify
40+
# it under the terms of the GNU General Public License as published by
41+
# the Free Software Foundation; either version 2, or (at your option)
42+
# any later version.
43+
#
44+
# This program is distributed in the hope that it will be useful,
45+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
46+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47+
# GNU General Public License for more details.
48+
#
49+
# You should have received a copy of the GNU General Public License
50+
# along with this program; see the file COPYING. If not, write to
51+
# the Free Software Foundation, Inc., 51 Franklin Street,
52+
# Boston, MA 02110-1301, USA.
53+
#
54+
55+
set -e # exit immediatelly on any failure
56+
57+
DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
58+
59+
IMAGE="${MAYHEM_DEV_DOCKER_IMAGE:-portapack-dev}"
60+
61+
build_image() {
62+
DOCKERFILE=${1:-dockerfile-nogit}
63+
PLATFORM=${2:-amd64}
64+
docker build --platform "linux/${PLATFORM}" -t "${IMAGE}" -f "${DOCKERFILE}" .
65+
}
66+
67+
start_docker() {
68+
if [ -z "$(docker images -q ${IMAGE} 2> /dev/null)" ]; then
69+
build_image
70+
fi
71+
72+
exec docker run -v "${DIR}:/havoc" -u "$(id -u):$(id -g)" -ti --rm "${IMAGE}" "$@"
73+
}
74+
75+
if [ "$1" = 'shell' ]; then # open a shell into the container
76+
start_docker "bash -li"
77+
elif [ "$1" = 'build' ]; then # build the default (or specified) target with ninja
78+
shift # remove the first item from $@ as we consumed it, we can then pass the rest on to make
79+
build_image "$@"
80+
exit $?
81+
fi
82+
83+
start_docker "$@"

firmware/tools/docker-entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
#!/bin/bash
22

3+
#
4+
# Copyright (C) 2024 u-foka
5+
#
6+
# This file is part of PortaPack.
7+
#
8+
# This program is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2, or (at your option)
11+
# any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; see the file COPYING. If not, write to
20+
# the Free Software Foundation, Inc., 51 Franklin Street,
21+
# Boston, MA 02110-1301, USA.
22+
#
23+
324
set -e # exit immediatelly on any failure
425

526
build_make() {

0 commit comments

Comments
 (0)