Skip to content

Commit d411230

Browse files
authored
non-root user to build artifacts inside the container
1 parent 576fae9 commit d411230

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

Diff for: .ci/Dockerfile

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
ARG PYTHON_VERSION=3.8
22
FROM python:${PYTHON_VERSION}
33

4+
# Default UID/GID to 1000
5+
# it can be overridden at build time
6+
ARG BUILDER_UID=1000
7+
ARG BUILDER_GID=1000
8+
ENV BUILDER_USER elastic
9+
ENV BUILDER_GROUP elastic
10+
11+
# Create user
12+
RUN groupadd --system -g ${BUILDER_GID} ${BUILDER_GROUP} \
13+
&& useradd --system --shell /bin/bash -u ${BUILDER_UID} -g ${BUILDER_GROUP} -d /var/lib/elastic -m elastic 1>/dev/null 2>/dev/null \
14+
&& mkdir -p /code/elasticsearch-py && mkdir /code/elasticsearch-py/build \
15+
&& chown -R ${BUILDER_USER}:${BUILDER_GROUP} /code/elasticsearch-py
16+
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .
417
WORKDIR /code/elasticsearch-py
18+
USER ${BUILDER_USER}:${BUILDER_GROUP}
519
COPY dev-requirements.txt .
620
RUN python -m pip install \
721
-U --no-cache-dir \
822
--disable-pip-version-check \
9-
pip \
10-
&& python -m pip install \
11-
--no-cache-dir \
12-
--disable-pip-version-check \
13-
-r dev-requirements.txt
14-
15-
COPY . .
16-
RUN python -m pip install -e .
23+
nox -rdev-requirements.txt
24+
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .
25+
RUN python -m pip install -U -e .

Diff for: .ci/make.sh

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ esac
115115
echo -e "\033[34;1mINFO: building $product container\033[0m"
116116

117117
docker build \
118+
--build-arg BUILDER_UID="$(id -u)" \
118119
--file $repo/.ci/Dockerfile \
119120
--tag ${product} \
120121
.
@@ -129,6 +130,7 @@ if [[ "$CMD" == "assemble" ]]; then
129130

130131
# Build dists into .ci/output
131132
docker run \
133+
-u "$(id -u)" \
132134
--rm -v $repo/.ci/output:/code/elasticsearch-py/dist \
133135
$product \
134136
/bin/bash -c "python /code/elasticsearch-py/utils/build-dists.py $VERSION"

Diff for: .ci/run-elasticsearch.sh

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ END
116116
echo -e "\033[34;1mINFO:\033[0m Starting container $node_name \033[0m"
117117
set -x
118118
docker run \
119+
-u "$(id -u)" \
119120
--name "$node_name" \
120121
--network "$network_name" \
121122
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g -da:org.elasticsearch.xpack.ccr.index.engine.FollowingEngineAssertions" \

Diff for: .ci/run-repository.sh

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fi
3737

3838
mkdir -p junit
3939
docker run \
40+
-u "$(id -u)" \
4041
--network=${network_name} \
4142
--env "STACK_VERSION=${STACK_VERSION}" \
4243
--env "ELASTICSEARCH_URL=${elasticsearch_url}" \

0 commit comments

Comments
 (0)