Skip to content

Commit c6a935f

Browse files
committed
Update Dockerfile to run with non-root user
1 parent aaae96a commit c6a935f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.ci/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
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+
17+
COPY --chown=$BUILDER_USER:$BUILDER_GROUP . .
18+
19+
USER ${BUILDER_USER}:${BUILDER_GROUP}
420
WORKDIR /code/elasticsearch-py
521
COPY dev-requirements.txt .
622
RUN python -m pip install \

.ci/make.sh

Lines changed: 2 additions & 0 deletions
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"

0 commit comments

Comments
 (0)