diff --git a/.github/workflows/student-image-build.yml b/.github/workflows/student-image-build.yml index 975b9a1..6da2cf7 100644 --- a/.github/workflows/student-image-build.yml +++ b/.github/workflows/student-image-build.yml @@ -30,4 +30,4 @@ jobs: file: ./resources/images/student-ubuntu/Dockerfile platforms: linux/amd64 push: true - tags: ryann3/student-ubuntu:6.0 + tags: ryann3/student-ubuntu:7.0 diff --git a/resources/images/control-ubuntu/.env b/resources/images/control-ubuntu/.env index 76d3e15..e385a5b 100644 --- a/resources/images/control-ubuntu/.env +++ b/resources/images/control-ubuntu/.env @@ -13,8 +13,8 @@ KUBE_BASE_URL=http://moaroom-infra.duckdns.org BASE_URL=http://moaroom-back.duckdns.org:8080 STUDENT_BASE_URL=http://${STUDENT_SVC}.${STUDENT_NS}.svc.cluster.local:${STUDENT_SERVER_PORT} -DIR_PATH_STUDENT=/root/assignment -DIR_PATH_PROFESSOR=/root/assignment +DIR_PATH_STUDENT=/root/assignments +DIR_PATH_PROFESSOR=/root/assignments APISERVER=https://kubernetes.default.svc # Point to the internal API server hostname SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount # Path to ServiceAccount token diff --git a/resources/images/control-ubuntu/server/res/remote-deploy-student.yml b/resources/images/control-ubuntu/server/res/remote-deploy-student.yml index 18c4003..231c8f4 100644 --- a/resources/images/control-ubuntu/server/res/remote-deploy-student.yml +++ b/resources/images/control-ubuntu/server/res/remote-deploy-student.yml @@ -8,7 +8,7 @@ metadata: spec: containers: - name: student-{{ ID }} - image: ryann3/student-ubuntu:6.0 + image: ryann3/student-ubuntu:7.0 imagePullPolicy: Always ports: - name: nginx-port diff --git a/resources/images/professor-ubuntu/.env b/resources/images/professor-ubuntu/.env index 18d7e51..121f5a2 100644 --- a/resources/images/professor-ubuntu/.env +++ b/resources/images/professor-ubuntu/.env @@ -13,8 +13,8 @@ KUBE_BASE_URL=http://moaroom-infra.duckdns.org BASE_URL=http://moaroom-back.duckdns.org:8080 STUDENT_BASE_URL=http://${STUDENT_SVC}.${STUDENT_NS}.svc.cluster.local:${STUDENT_SERVER_PORT} -DIR_PATH_STUDENT=/root/assignment -DIR_PATH_PROFESSOR=/root/assignment +DIR_PATH_STUDENT=/root/assignments +DIR_PATH_PROFESSOR=/root/assignments APISERVER=https://kubernetes.default.svc # Point to the internal API server hostname SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount # Path to ServiceAccount token diff --git a/resources/images/student-ubuntu/.env b/resources/images/student-ubuntu/.env index 18d7e51..121f5a2 100644 --- a/resources/images/student-ubuntu/.env +++ b/resources/images/student-ubuntu/.env @@ -13,8 +13,8 @@ KUBE_BASE_URL=http://moaroom-infra.duckdns.org BASE_URL=http://moaroom-back.duckdns.org:8080 STUDENT_BASE_URL=http://${STUDENT_SVC}.${STUDENT_NS}.svc.cluster.local:${STUDENT_SERVER_PORT} -DIR_PATH_STUDENT=/root/assignment -DIR_PATH_PROFESSOR=/root/assignment +DIR_PATH_STUDENT=/root/assignments +DIR_PATH_PROFESSOR=/root/assignments APISERVER=https://kubernetes.default.svc # Point to the internal API server hostname SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount # Path to ServiceAccount token diff --git a/resources/images/student-ubuntu/Dockerfile b/resources/images/student-ubuntu/Dockerfile index 480ff49..5f1c03a 100644 --- a/resources/images/student-ubuntu/Dockerfile +++ b/resources/images/student-ubuntu/Dockerfile @@ -19,7 +19,7 @@ RUN apt-get dist-upgrade RUN echo "deb http://archive.ubuntu.com/ubuntu vivid main restricted universe" >> /etc/apt/sources.list # libffi-dev -RUN apt-get install -y ssh openssh-server sudo curl vim git openssh-client telnet net-tools nginx python3.8 python3-pip libc-dev libffi-dev gcc tzdata +RUN apt-get install -y ssh openssh-server sudo curl vim git openssh-client telnet net-tools nginx python3.8 python3-pip libc-dev libffi-dev gcc tzdata tree shc ## TZ ENV TZ=Asia/Seoul @@ -64,8 +64,9 @@ RUN pip3 install -r ./server/requirements.txt EXPOSE 8001-8886 -## run ssh connection and nginx with startup.sh +## change permissions of executable files RUN chmod +x /root/workdir/startup.sh +RUN chmod +x /root/workdir/moaroom.sh RUN chmod +x /root/workdir/webssh/run.py RUN chmod +x /root/workdir/server/main.py CMD ["./startup.sh"] @@ -81,4 +82,5 @@ CMD ["./startup.sh"] ### 4.1: change rep type from model to dict ### 4.2: added timezone ## 5.0: Deploy version -## 6.0: NodePort version \ No newline at end of file +## 6.0: NodePort version +## 7.0: moaroom cli version \ No newline at end of file diff --git a/resources/images/student-ubuntu/moaroom.sh b/resources/images/student-ubuntu/moaroom.sh new file mode 100644 index 0000000..b92bc91 --- /dev/null +++ b/resources/images/student-ubuntu/moaroom.sh @@ -0,0 +1,82 @@ +#! /bin/bash +ROOT_PATH="$(pwd)" +TARGET_ASSIGNMENT="default" + +sed_inplace() { + # BSD sed and GNU sed implements the "-i" option differently. + case "$OSTYPE" in + darwin*) sed -i '' "$@" ;; + bsd*) sed -i '' "$@" ;; + *) sed -i "$@" ;; + esac +} + +usage() { + echo "How to use MoaRoom CLI: MoaRoom CLI Tool" + echo "" + echo "" + echo "USAGE" + echo " $0 [OPTIONS]" + echo "" + echo "OPTIONS" + echo " -h, --help" + echo " Show this help message and exit" + echo "" + echo " -g, --show-guide" + echo " Show the guide of MoaRoom and exit" + echo "" + echo " -l, --list-assignments" + echo " List assignments of this lecture" + echo "" + echo " -t, --tree-assignments" + echo " List assignments of this lecture with tree-style" + echo "" + echo " -m, --to-assignment" + echo " Move to specific assignment directory" + echo " Can cd to assignment directory by number of listed assignments" + echo "" +} + +show_guide() { + echo "MoaRoom Guide: How to use MoaRoom!" + echo "1. Go to a specific assignment directory by using the cli command" + echo " You can use moaroom -h | --help to see how to use it" + +} +list_assignments(){ + lines=$((`ls -l assignment/ | wc -l`-1)) + for ((l=1 ; l <= $((lines)) ; l++)); + do + directory=`ls -l assignment/ | awk 'NR=='"$((l+1))"' {print $9}'` + echo "$l. $directory" + done + echo "" + echo "Remember the number and get the cmd line with -m | --to-assignment option" +} +tree_assignments(){ + tree "${DIR_PATH_STUDENT}" +} +to_assignment(){ + directory=`ls -l assignment/ | awk 'NR=='"$((TARGET_ASSIGNMENT+1))"' {print $9}'` + echo "Run this on terminal" + echo "cd \"${DIR_PATH_STUDENT}/${directory}\"" + +} + +while [ $# -gt 0 ]; do + case $1 in + -h | --help) usage; exit 1 ;; + -g | --show-guide) show_guide; exit 1 ;; + -l | --list-assignments) list_assignments; exit 1 ;; + -t | --tree-assignments) tree_assignments; exit 1 ;; + -m) TARGET_ASSIGNMENT=$2; to_assignment; shift ;; + -m=*) TARGET_ASSIGNMENT="${1#*=}"; to_assignment ;; + --to-assignment) TARGET_ASSIGNMENT=$2; to_assignment; shift ;; + --to-assignment=*) TARGET_ASSIGNMENT="${1#*=}"; to_assignment ;; + *) + echo "Unknown option: $1" + echo "Run '$0 --help' for usage." + exit 1 + esac + shift +done diff --git a/resources/images/student-ubuntu/startup.sh b/resources/images/student-ubuntu/startup.sh index 4f5d442..a417dd8 100644 --- a/resources/images/student-ubuntu/startup.sh +++ b/resources/images/student-ubuntu/startup.sh @@ -5,10 +5,13 @@ while read line || [ -n "$line" ] ; do echo "export $line > /dev/null 2>&1" >> /etc/profile ((i+=1)) done < ./.env -source /etc/profile > /dev/null 2>&1 -# no welcome message -chmod -x /etc/update-motd.d/* +# MoaRoom CLI +alias moaroom="/root/workdir/moaroom.sh" +echo "alias moaroom=\"/root/workdir/moaroom.sh\"" >> /etc/profile + +# source env variables +source /etc/profile > /dev/null 2>&1 # # ssl configuration # mkdir -p /etc/nginx/ssl @@ -26,6 +29,9 @@ echo "root:${SSH_PASSWORD}" | chpasswd mkdir -p /run/nginx echo "

THIS NGINX INDEX.HTML

" >> /var/www/html/index.html +# no welcome message +chmod -x /etc/update-motd.d/* + # Banner cp /root/workdir/motd /etc/issue.net # 원격 접속 시도 시 cp /root/workdir/motd /etc/issue # 콘솔 접속 시도 시 diff --git a/resources/res/.env b/resources/res/.env index 53bc912..852d936 100644 --- a/resources/res/.env +++ b/resources/res/.env @@ -13,8 +13,8 @@ KUBE_BASE_URL=http://af3a1a2d769ff4be9991c752a7a41937-923523649.ap-northeast-2.e BASE_URL=http://moaroom-back.duckdns.org:8080 STUDENT_BASE_URL=http://${STUDENT_SVC}.${STUDENT_NS}.svc.cluster.local:${STUDENT_SERVER_PORT} -DIR_PATH_STUDENT=/root/assignment -DIR_PATH_PROFESSOR=/root/assignment +DIR_PATH_STUDENT=/root/assignments +DIR_PATH_PROFESSOR=/root/assignments APISERVER=https://kubernetes.default.svc # Point to the internal API server hostname SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount # Path to ServiceAccount token