Skip to content

Commit 7111183

Browse files
committed
build: add Dockerfile and scripts for compiling COMTool
1 parent cb519fc commit 7111183

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

Dockerfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM ubuntu:focal
4+
5+
ARG DEBIAN_FRONTEND=noninteractive
6+
7+
RUN <<EOF
8+
apt-get update
9+
apt-get install -y ca-certificates
10+
rm -rf /var/lib/apt/lists/*
11+
EOF
12+
13+
COPY <<EOF /etc/apt/sources.list
14+
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
15+
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
16+
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
17+
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
18+
EOF
19+
20+
ENV TZ=Asia/Shanghai
21+
22+
RUN <<EOF
23+
apt-get update
24+
apt-get install -y tzdata
25+
apt-get install -y locales && locale-gen en_US.UTF-8
26+
apt-get install -y gosu
27+
rm -rf /var/lib/apt/lists/*
28+
EOF
29+
30+
ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8
31+
32+
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
33+
RUN <<EOF
34+
apt-get update
35+
apt-get install -y git
36+
apt-get install -y build-essential libssl-dev zlib1g-dev \
37+
libbz2-dev libreadline-dev libsqlite3-dev curl \
38+
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
39+
rm -rf /var/lib/apt/lists/*
40+
EOF
41+
42+
ENV PYENV_ROOT="/usr/local/pyenv"
43+
ENV PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
44+
ARG PYTHON_VERSION="3.10"
45+
# https://github.com/pyenv/pyenv/pull/2592
46+
# https://github.com/pyenv/pyenv/wiki#how-to-build-cpython-for-maximum-performance
47+
ARG PYTHON_CONFIGURE_OPTS="--disable-shared --enable-optimizations --with-lto"
48+
ARG PYTHON_CFLAGS="-march=native -mtune=native"
49+
50+
RUN <<EOF
51+
curl https://pyenv.run | bash
52+
pyenv install $PYTHON_VERSION
53+
pyenv global $PYTHON_VERSION
54+
EOF
55+
56+
RUN <<EOF
57+
python -m pip install --no-cache-dir --upgrade pip
58+
pip install --no-cache-dir nuitka
59+
EOF
60+
61+
RUN <<EOF
62+
apt-get update
63+
apt-get install -y ccache patchelf
64+
rm -rf /var/lib/apt/lists/*
65+
EOF
66+
67+
WORKDIR /code
68+
69+
COPY docker-entrypoint.sh /usr/local/bin/
70+
ENTRYPOINT ["docker-entrypoint.sh"]
71+
COPY docker-cmd.sh /usr/local/bin/
72+
CMD ["docker-cmd.sh"]

build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
docker build -t comtool-complier .
4+
5+
docker run --rm \
6+
-e USER_ID=$UID \
7+
-e GROUP_ID=$GID \
8+
--mount type=bind,src=$PWD,dst=/code \
9+
comtool-complier

docker-cmd.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
pip install .
4+
5+
NUITKA_CACHE_DIR=".nuitka_cache" python -m nuitka --onefile --output-filename=COMTool src/comtool/__main__.py

docker-entrypoint.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Exit immediately if a command exits with a non-zero status
4+
set -e
5+
6+
# Set the user ID to 1000 or the value of USER_ID environment variable if it's set
7+
ID_USER=${USER_ID:-1000}
8+
9+
# Set the group ID to 1000 or the value of GROUP_ID environment variable if it's set
10+
ID_GROUP=${GROUP_ID:-1000}
11+
12+
# Set the username and groupname to 'static'
13+
NAME=static
14+
15+
# If the current user is root
16+
if [ "$(id -u)" = "0" ]; then
17+
# Check if the group exists and if not add it
18+
if ! getent group $NAME > /dev/null; then
19+
groupadd --gid "$ID_GROUP" "$NAME"
20+
fi
21+
22+
# Check if the user exists and if not add it
23+
if ! getent passwd $NAME > /dev/null; then
24+
useradd --uid "$ID_USER" --gid "$ID_GROUP" --create-home --shell /bin/bash "$NAME"
25+
fi
26+
27+
# Run the current script as the new user
28+
exec gosu "$NAME" "$0" "$@"
29+
fi
30+
31+
# Execute the command specified by the arguments
32+
exec "$@"

0 commit comments

Comments
 (0)