[AAI-2177] Run container process as non-root
[aai/gizmo.git] / src / main / docker / Dockerfile
1 FROM @aai.docker.namespace@/aai-common-@aai.base.image@:@aai.base.image.version@
2
3 ARG MICRO_HOME=/opt/app/crud-api
4 ARG BIN_HOME=$MICRO_HOME/bin
5 ARG USERS_HOME=/opt/aaihome
6
7 # AAI-2177: Change aai gizmo container processes to run as non-root on the host
8
9 #Note:The group id and user id used below (492382 & 341790 respectively) are chosen arbitarily based on assumption that
10 # these are not used elsewhere. Please see  https://jira.onap.org/browse/AAI-2172 for more background on this.
11
12 RUN mkdir -p $MICRO_HOME $USERS_HOME /logs \
13     && groupadd -g 492382 aaiadmin \
14     && useradd -r -u 341790  -g 492382 -ms /bin/sh -d $USERS_HOME/aaiadmin aaiadmin
15 ##The following 2 lines are added to add the user to the sudoers group
16 ##The script src\main\bin\start.sh could then optionally run the process as sudo user if an environment variable is set
17 ## By default the sudo mode is disabled.
18 RUN usermod -aG sudo aaiadmin  &&\
19     echo  'aaiadmin  ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
20 WORKDIR $MICRO_HOME
21 COPY /maven/gizmo/ .
22 RUN chmod 755 $BIN_HOME/* \
23     && ln -snf /logs $MICRO_HOME/logs \
24     && chown -R aaiadmin:aaiadmin $MICRO_HOME /logs
25
26 USER aaiadmin
27
28 EXPOSE 9520 9520
29
30 CMD ["/opt/app/crud-api/bin/start.sh"]