#!/bin/sh # define color variable RED='\E[1;31m' # red GREEN='\E[1;32m' # green RES='\E[0m' # clear color # you can modify below settings for your new project #subsitute space, slash, dot and dash by underscores # PROJECT_NAME=$(nerbasename $PWD) PROJECT_NAME=$(echo "$PWD" | sed -e 's/[ -./]/_/g') PROJECT_PORT=10086 PROJECT_PASSWORD="123456" PROJECT_SOURCE_PATH=$PWD PROJECT_CONFIG_PATH=/home/$(whoami)/.vscode/default PROJECT_HOME_PATH=$HOME PROJECT_REPO_PATH=/repo/$(whoami) PROJECT_REPO2_PATH=/repo2/jiangusu # please keep your name in the container name # CONTAINER_NAME="$(whoami)_vscode_$PROJECT_NAME CONTAINER_NAME=vscode_$PROJECT_NAME CONTAINER_NAME=$(whoami)_code_server # local vscode server image VSCODE_IMAGE="jgsun/code-server" # VSCODE_IMAGE="codercom/code-server" parse_para() { if [ $(echo $1 | cut -d'=' -f1) = "c" ]; then PROJECT_CONFIG_PATH=$(echo $1 | cut -d'=' -f2) fi if [ $(echo $1 | cut -d'=' -f1) = "p" ]; then PROJECT_PORT=$(echo $1 | cut -d'=' -f2) fi } start_container() { if [ "$#" -eq 1 ]; then parse_para $1 fi if [ "$#" -eq 2 ]; then parse_para $1 parse_para $2 fi echo -e " ${RED}Source: $PROJECT_SOURCE_PATH${RES}" echo -e " ${RED}Config: $PROJECT_CONFIG_PATH${RES}" echo -e " ${GREEN}Port: $PROJECT_PORT${RES}" echo -e " ${GREEN}container: $CONTAINER_NAME${RES}" #exit docker run -ti -d --rm \ --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \ -e PASSWORD=$PROJECT_PASSWORD \ -u ""$(id -u):$(id -g)"" \ -e "DOCKER_USER=$USER" \ -p $PROJECT_PORT:8080 \ --name $CONTAINER_NAME \ -v $PROJECT_SOURCE_PATH:/home/coder/project \ -v $PROJECT_HOME_PATH:$HOME \ -v $PROJECT_CONFIG_PATH:/home/coder/project/.vscode \ -v $PROJECT_REPO_PATH:/repo/$(whoami) \ -v $PROJECT_REPO2_PATH:/repo2/$(whoami) \ $VSCODE_IMAGE } #-v /usr/include:/usr/include \ stop_container() { docker container stop $CONTAINER_NAME } login_container() { docker exec -it $CONTAINER_NAME bash } case "$1" in start) echo cmd: $(basename $0) $1 $2 $3 start_container $2 $3 ;; stop) stop_container ;; set) echo -e "${GREEN}setting container, please wait...${RES}" ;; echo) echo -e "${GREEN}success, enjoy!${RES}" ;; login) login_container ;; restart) $0 stop sleep 1 $0 start ;; *) echo "Usage: $0 {start|stop|login|restart} [c=config file] [p=port]" echo "please run it in path of source code." exit 1 esac