Change pod startup to non root 20/102920/2
authoryangyan <yangyanyj@chinamobile.com>
Wed, 4 Mar 2020 02:21:41 +0000 (10:21 +0800)
committerYan Yang <yangyanyj@chinamobile.com>
Wed, 4 Mar 2020 02:23:14 +0000 (02:23 +0000)
Change-Id: Ib15cdbd1d41f58f725ffffef51ec47dd536040a8
Issue-ID: VFC-1637
Signed-off-by: yangyan <yangyanyj@chinamobile.com>
docker/Dockerfile
docker/docker-env-config.sh [new file with mode: 0644]

index bbf9e32..25391f1 100644 (file)
@@ -6,33 +6,15 @@ ARG HTTPS_PROXY=${HTTPS_PROXY}
 ENV http_proxy $HTTP_PROXY
 ENV https_proxy $HTTPS_PROXY
 
-RUN sed -i "s|set compatible|set nocompatible|" /etc/vim/vimrc.tiny
-RUN echo "set backspace=2" >> /etc/vim/vimrc.tiny
-
-RUN echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
-RUN echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections
-
-RUN apt-get update && \
-    apt-get install -y gcc && \
-    apt-get install -y libmysqlclient-dev && \
-    apt-get install -y redis-server && \
-    apt-get install -y mysql-server-5.6 && \
-    apt-get install -y mysql-client-5.6 && \
-    apt-get install -y wget && \
-    apt-get install -y unzip && \
-    apt-get install -y build-essential && \
-    apt-get install -y libssl-dev && \
-    apt-get install -y libffi-dev
-
-RUN sed -i "s|bind-address.*|# bind-address = 127.0.0.1|" /etc/mysql/my.cnf
-
-VOLUME /var/lib/mysql
-
 ADD . /service
 WORKDIR /service
 
+RUN bash docker-env-config.sh
+VOLUME /var/lib/mysql
+
 EXPOSE 3306
 EXPOSE 6379
 
+USER onap
 WORKDIR /service
 ENTRYPOINT ./docker-entrypoint.sh
diff --git a/docker/docker-env-config.sh b/docker/docker-env-config.sh
new file mode 100644 (file)
index 0000000..e059ce6
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+install_sf(){
+
+       sed -i "s|set compatible|set nocompatible|" /etc/vim/vimrc.tiny
+       echo "set backspace=2" >> /etc/vim/vimrc.tiny
+
+       echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
+       echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections
+       
+       apt-get update
+        apt-get install -y gcc libmysqlclient-dev redis-server mysql-server-5.6 mysql-client-5.6 wget unzip build-essential libssl-dev libffi-dev
+       sed -i "s|bind-address.*|# bind-address = 127.0.0.1|" /etc/mysql/my.cnf
+}
+
+add_user(){
+
+        useradd onap
+       chmod u+w /etc/sudoers
+       sed -i '/User privilege specification/a\onap    ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers
+       chmod u-w /etc/sudoers
+       chown onap:onap -R /service
+
+}
+
+clean_sf_cache(){
+
+        apt-get clean
+        apt-get autoclean
+        apt-get autoremove
+}
+
+install_sf
+wait
+add_user
+clean_sf_cache