2 # Copyright 2020 Huawei Technologies Co., Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 # Prepare stage for multistage image build
19 # FROM python:3.6-slim-stretch
21 # FROM python:3.9-slim-buster
22 # # CREATE APP USER ##
27 RUN sed -i "s|umask 022|umask 027|g" /etc/profile
29 # Create the home directory for the new app user.
31 RUN mkdir -p /usr/app/bin
32 RUN mkdir -p /usr/app/inventry
33 RUN mkdir -p /usr/app/test/resources
34 RUN mkdir -p /usr/app/images_result
36 # Set the home directory to our app user's home.
41 ENV GROUP_NAME=eggroup
42 ENV ENV="/etc/profile"
43 ENV PYTHONUNBUFFERED=0
45 # Create an app user so our program doesn't run as root.
46 RUN apt-get -y update &&\
47 groupadd -r -g $GID $GROUP_NAME &&\
48 useradd -r -u $UID -g $GID -d $APP_HOME -s /sbin/nologin -c "Docker image user" $USER_NAME
50 RUN apt-get install -y --fix-missing \
58 libgraphicsmagick1-dev \
66 software-properties-common \
69 && apt-get clean && rm -rf /tmp/* /var/tmp/*
71 # Set the working directory.
74 # Copy the application & scripts
75 COPY config.py requirements.txt run.py $APP_HOME/
76 COPY inventry $APP_HOME/inventry/
78 COPY test $APP_HOME/test/
79 COPY test/resources $APP_HOME/test/resources/
80 COPY configs/start.sh $APP_HOME/bin
82 RUN chmod 750 $APP_HOME &&\
83 chmod -R 550 $APP_HOME/bin &&\
84 mkdir -p -m 750 $APP_HOME/log &&\
85 mkdir -p -m 700 $APP_HOME/ssl &&\
86 chown -R $USER_NAME:$GROUP_NAME $APP_HOME
91 # Change to the app user.
94 # Install requirements
95 RUN pip install -r requirements.txt
97 # Execute script & application
98 ENTRYPOINT ["sh", "./bin/start.sh"]