From ee293f2718bffa63dbef1e52ab74fcced0a54e94 Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Fri, 15 Mar 2019 14:35:25 -0400
Subject: [PATCH] added deploy stage with weekly push to repo

---
 .gitlab-ci.yml                           | 14 ++++
 cicd_testing/deploy.sh                   | 67 +++++++++++++++++++
 cicd_testing/docker-zipr-bin/Dockerfile  | 27 ++++++++
 cicd_testing/docker-zipr-bin/run_pszr.sh | 84 ++++++++++++++++++++++++
 tools/pszr                               | 20 ++++++
 5 files changed, 212 insertions(+)
 create mode 100755 cicd_testing/deploy.sh
 create mode 100644 cicd_testing/docker-zipr-bin/Dockerfile
 create mode 100755 cicd_testing/docker-zipr-bin/run_pszr.sh
 create mode 100755 tools/pszr

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6e6966a8d..84f838a04 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,6 +9,7 @@ stages:
   - clean
   - build
   - test
+  - deploy
 
 
 #
@@ -156,3 +157,16 @@ elfdep-centos75:
   variables:
     OS: 'centos75'  
 
+
+
+#
+# deploy a docker image
+#
+deploy-u18:
+  stage: deploy
+  script:
+    - ./cicd_testing/elfdep.sh
+  tags:
+    - ubuntu18
+  variables:
+    OS: 'ubuntu18'  
diff --git a/cicd_testing/deploy.sh b/cicd_testing/deploy.sh
new file mode 100755
index 000000000..01088a3bd
--- /dev/null
+++ b/cicd_testing/deploy.sh
@@ -0,0 +1,67 @@
+#/bin/bash
+
+export PS_PATH=git.zephyr-software.com:4567/allnp/irdb-sdk/
+export PS_TAG=zipr-bin:latest
+export DOCKER_PS=${PS_PATH}${PS_TAG}
+
+
+do_docker_clean()
+{
+	if [[ $CICD_WEEKLY == 1 ]]; then
+		docker system prune -a -f
+	fi
+}
+
+
+do_login()
+{
+
+	# login to gitlab's docker registry as gitlab-user
+	docker login $PS_PATH -u gitlab-runner -p 84MyuSuDo4kQat4GZ_Zs  2> /dev/null
+}
+
+do_build_image()
+{
+
+	#
+	# Re-install peasoup without ida.
+	#
+	cd $PEASOUP_HOME
+	rm -rf installed || true
+	$PEDI_HOME/pedi --setup -m manifest.txt -l ps -l zipr -l stars -i $PS_INSTALL
+	$PEDI_HOME/pedi -m manifest.txt
+
+	# build the docker image
+	cd $PEASOUP_HOME/cicd_testing/docker-zipr-bin
+	mv ../../installed .
+
+	# if we fail here, continue on so we put "install" back in the right place.
+	# the test should stop this
+	docker build -t $DOCKER_PS . || true	
+	mv installed ../..
+}
+
+
+do_push()
+{
+	if [[ $CICD_WEEKLY == 1 ]]; then
+		docker push ${DOCKER_PS}
+	fi
+}
+
+do_logout()
+{
+	docker logout $PS_PATH
+}
+
+main()
+{
+	set -e 
+	do_docker_clean
+	do_login
+	do_build_image
+	do_push
+	do_logout
+}
+
+main "$@"
diff --git a/cicd_testing/docker-zipr-bin/Dockerfile b/cicd_testing/docker-zipr-bin/Dockerfile
new file mode 100644
index 000000000..eacbcee70
--- /dev/null
+++ b/cicd_testing/docker-zipr-bin/Dockerfile
@@ -0,0 +1,27 @@
+
+FROM ubuntu:18.04
+RUN DEBIAN_FRONTEND=noninteractive apt-get update &&   \
+    DEBIAN_FRONTEND=noninteractive apt-get install -yq \
+	postgresql  				\
+	postgresql-client  			\
+	libpqxx-dev				\
+	sudo 					\
+	nasm
+
+ENV IRDB_SDK=/opt/ps_zipr/irdb-sdk
+ENV IRDB_LIBS=/opt/ps_zipr/irdb-libs/lib
+COPY ./installed /opt/ps_zipr/
+COPY ./run_pszr.sh /run_pszr.sh
+RUN sudo chmod +x /run_pszr.sh
+RUN cd /opt/ps_zipr && ./get-peasoup-packages.sh all
+RUN useradd -ms /bin/bash zuser && gpasswd -a zuser sudo 
+RUN echo '%sudo   ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers
+RUN echo 'export PATH=$PATH:/opt/ps_zipr/tools/' >> /home/zuser/.bashrc 
+RUN echo 'sudo service postgresql start ' >> /home/zuser/.bashrc
+RUN chown zuser:zuser /home/zuser/.bashrc
+USER zuser
+ENV USER=zuser
+RUN sudo service postgresql start && cd /opt/ps_zipr/ && (env USER=zuser ./postgres_setup.sh || true)
+WORKDIR /home/zuser
+ENTRYPOINT [ "/bin/bash", "-c", "/run_pszr.sh \"$@\"", "--" ]
+CMD [ ] 
diff --git a/cicd_testing/docker-zipr-bin/run_pszr.sh b/cicd_testing/docker-zipr-bin/run_pszr.sh
new file mode 100755
index 000000000..73b09e990
--- /dev/null
+++ b/cicd_testing/docker-zipr-bin/run_pszr.sh
@@ -0,0 +1,84 @@
+#/bin/bash
+
+print_usage()
+{
+	echo ""
+	echo " This docker container is made available to the public by Zephyr Software       "
+	echo " (contact: jwd@zephyr-software.com) under the Creative Commons Attribution-     "
+	echo " NonCommercial license (CC BY-NC).                                              "
+	echo ""
+	echo " Linux, Gcc, and other relevant open source projects are licensed under their   "
+	echo " own license and are exempt from this license statement.                        "
+	echo ""
+	echo "IRDB toolchain subcommands:"
+	echo ""
+	echo "	iagree	        Accept the creative commons non-commercial license and login."
+	echo "	help            Print this menu."
+	echo ""
+}
+
+main()
+{
+	local res=0
+	export USER=root;
+	cd /opt/ps_zipr 
+	source ./set_env_vars 
+	cd /home/zuser
+
+	subcommand=$1
+	shift
+	
+	echo "Arguments are: $@"
+	case "$subcommand" in
+		iagree)
+			echo
+			echo Welcome to the IRDB toolchain docker image!
+			echo
+			echo "Setting up postgres..."
+			echo
+			service postgresql start
+			sleep 2 # let service start up enough to print the message
+			echo
+			echo 'The IRDB toolchain is setup and ready to run.'
+			echo 'You could start your first experiment with:'
+			echo
+			echo 'zuser@a3fc1666aaa4:~$ pszr /bin/ls ./ls.p1 -c p1transform'
+			echo 'Using Zipr backend.'
+			echo 'Detected ELF shared object.'
+			echo 'Performing step rida [dependencies=mandatory] ...Done.  Successful.'
+			echo 'Performing step pdb_register [dependencies=mandatory] ...Done.  Successful.'
+			echo 'Performing step fill_in_cfg [dependencies=unknown] ...Done.  Successful.'
+			echo 'Performing step fill_in_indtargs [dependencies=unknown] ...Done.  Successful.'
+			echo 'Performing step fix_calls [dependencies=unknown] ...Done.  Successful.'
+			echo 'Performing step p1transform [dependencies=unknown] ...Done.  Successful.'
+			echo 'Performing step zipr [dependencies=none] ...Done.  Successful.'
+			echo 'zuser@a3fc1666aaa4:~$ ./ls.p1 -l ' 
+			echo ' < ls output >  '
+			echo 'zuser@a3fc1666aaa4:~$ readelf -l /bin/ls ./ls.p1 ' 
+			echo
+			exec sudo su - zuser
+			res=0
+		;;
+
+		help)
+			print_usage
+			exit 0
+		;;
+		*)
+			print_usage
+			echo 
+			echo "Unknown subcommand: '$subcommand'"
+			echo 
+			exit 1
+		;;
+	esac
+
+	if [[ $res  != 0 ]]; then
+		echo
+		echo Subcommand failed.  Logs were printed.
+		exit 1
+	fi
+	exit 0
+}
+
+main "$@" 
diff --git a/tools/pszr b/tools/pszr
new file mode 100755
index 000000000..c9b542492
--- /dev/null
+++ b/tools/pszr
@@ -0,0 +1,20 @@
+#!/bin/bash 
+
+source $(dirname $0)/ps_wrapper.source $0
+
+meds_static_opt=" -s meds_static=off"
+rida_opt=" -s rida=on"
+
+echo $@ | grep "meds_static=" >/dev/null 2>&1
+if [ $? -eq 0 ]; then
+	meds_static_specified=1
+	meds_static_opt=" "
+fi
+
+echo $@ | grep "rida=" >/dev/null 2>&1
+if [ $? -eq 0 ]; then
+	rida_specified=1
+	rida_opt=" "
+fi
+
+$PEASOUP_HOME/tools/ps_analyze.sh "$@" --backend zipr $meds_static_opt $rida_opt
-- 
GitLab