Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI "moaroom [Options]" #93

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/student-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions resources/images/control-ubuntu/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/images/professor-ubuntu/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/images/student-ubuntu/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions resources/images/student-ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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
## 6.0: NodePort version
## 7.0: moaroom cli version
82 changes: 82 additions & 0 deletions resources/images/student-ubuntu/moaroom.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions resources/images/student-ubuntu/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +29,9 @@ echo "root:${SSH_PASSWORD}" | chpasswd
mkdir -p /run/nginx
echo "<h1>THIS NGINX INDEX.HTML</h1>" >> /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 # 콘솔 접속 시도 시
Expand Down
4 changes: 2 additions & 2 deletions resources/res/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading