From cb9f6e56c7eda3954e92a0240d34f625100b59eb Mon Sep 17 00:00:00 2001 From: Josix Date: Wed, 8 Sep 2021 23:28:45 +0800 Subject: [PATCH] build: Add Dockerfile and shim (#47) * build: Add Dockerfile and shims * build: Publish dockerfile to docker hub * build: Fix permisson error when writing in docker * fix: Fix wrong ouput if no given model * docs(docker): Add documentation for running with docker --- Dockerfile | 20 ++++++++++++++++++++ README.md | 23 +++++++++++++++++++++++ entrypoint.sh | 15 +++++++++++++++ smore.sh | 8 ++++++++ 4 files changed, 66 insertions(+) create mode 100644 Dockerfile create mode 100755 entrypoint.sh create mode 100755 smore.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..05f715d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM ubuntu:18.04 + +ENV DEBIAN_FRONTEND noninteractive +ENV BASE_DIR /usr/local +ENV APP_DIR $BASE_DIR/smore + +RUN apt-get update \ + && apt-get -y install g++-7 make\ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +COPY cli $APP_DIR/cli +COPY src $APP_DIR/src +COPY ./entrypoint.sh $APP_DIR +COPY Makefile $APP_DIR +WORKDIR $APP_DIR + +RUN make CC=g++-7 +ENTRYPOINT ["./entrypoint.sh"] +VOLUME ["$APP_DIR/data"] \ No newline at end of file diff --git a/README.md b/README.md index 8026492..d9bbb2c 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,29 @@ sh train_youtube.sh ``` Changing the number of threads in *train_youtube.sh* could speedup the process. +# Running with Docker +- Running with locally built image + - Building docker image which is created following the instructions of Dockerfile + ```sh + docker build -t smore:latest . + ``` + - Running container instantiated by image. + ```sh + docker run -it --name smore --rm -v "$PWD":/usr/local/smore/data smore:latest model_name -train training_dataset -save embedding [model_options] + ``` + - Example: + ```sh + docker run -it --name smore --rm -v "$PWD":/usr/local/smore/data smore:latest hpe -train net.txt -save rep.txt + ``` +- Running with published image + - Running `smore.sh` + ```sh + ./smore.sh model_name -train training_dataset -save embedding [model_options] + ``` + - Example: + ``` + ./smore.sh model_name -train training_dataset -save embedding [model_options] + ``` # Related Work You can find related work from [awesome-network-embedding](https://github.com/chihming/awesome-network-embedding). diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..ac5f3f6 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +if [ $# -lt 1 ];then + echo "Usage:\n ./smore.sh model_name -train training_dataset -save embedding [model_options]" + echo "Example:\n ./smore.sh hpe -train net.txt -save rep.txt" + exit 1 +fi +args=( "$@" ) +for ((i=0; i < $#; i++)) ;do + next_arg=$((i+1)) + if [ "${args[$i]}" == "-train" ] || [ "${args[$i]}" == "-save" ]; then + args[${next_arg}]="data/"${args[${next_arg}]} + fi +done +set "${args[@]}" +exec "./cli/$@" \ No newline at end of file diff --git a/smore.sh b/smore.sh new file mode 100755 index 0000000..84206e7 --- /dev/null +++ b/smore.sh @@ -0,0 +1,8 @@ +#!/bin/sh +if [ $# -lt 1 ];then + echo "Usage:\n ./smore.sh model_name -train training_dataset -save embedding [model_options]" + echo "Example:\n ./smore.sh hpe -train net.txt -save rep.txt" + exit 1 +fi +IMAGE=josix/smore:latest +docker run -it --name smore --rm --user="$(id -u):$(id -g)" -v "$PWD":/usr/local/smore/data "$IMAGE" "$@" \ No newline at end of file