From f2801c46c57333c31d1a474e7ac264e06eafb52b Mon Sep 17 00:00:00 2001 From: Nayeon Keum Date: Tue, 26 Sep 2023 21:16:51 +0900 Subject: [PATCH 1/4] [feat/#91] Refactor: assignment dir name to assignments --- resources/images/control-ubuntu/.env | 4 ++-- resources/images/professor-ubuntu/.env | 4 ++-- resources/images/student-ubuntu/.env | 4 ++-- resources/res/.env | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) 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/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/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 From 45eb25fbb4d17a072584bd280c31788b17133fa8 Mon Sep 17 00:00:00 2001 From: Nayeon Keum Date: Tue, 26 Sep 2023 22:23:04 +0900 Subject: [PATCH 2/4] [feat/#91] Add: cli command of moaroom --- resources/images/student-ubuntu/Dockerfile | 2 +- resources/images/student-ubuntu/moaroom.sh | 82 ++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 resources/images/student-ubuntu/moaroom.sh diff --git a/resources/images/student-ubuntu/Dockerfile b/resources/images/student-ubuntu/Dockerfile index 480ff49..226e316 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 ## TZ ENV TZ=Asia/Seoul 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 From efbd0b4200b46c0db1f1ca9a46089332df145d70 Mon Sep 17 00:00:00 2001 From: Nayeon Keum Date: Tue, 26 Sep 2023 23:08:41 +0900 Subject: [PATCH 3/4] [feat/#91] Add: moaroom.sh execution file to docker image --- resources/images/student-ubuntu/Dockerfile | 8 +++++--- resources/images/student-ubuntu/startup.sh | 12 +++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/resources/images/student-ubuntu/Dockerfile b/resources/images/student-ubuntu/Dockerfile index 226e316..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 tree +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/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 # 콘솔 접속 시도 시 From 1f8930f6c2e50e5dc814c9d02c8bcd48fd4693be Mon Sep 17 00:00:00 2001 From: Nayeon Keum Date: Tue, 26 Sep 2023 23:09:17 +0900 Subject: [PATCH 4/4] [feat/#91] Fix: image tags of student-ubuntu --- .github/workflows/student-image-build.yml | 2 +- .../images/control-ubuntu/server/res/remote-deploy-student.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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