diff --git a/Dockerfile b/Dockerfile index 7f49f12..c997d53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,19 @@ -FROM openjdk:8-jre-alpine -#ENV AOZORA_EPUB3 AozoraEpub3-1.1.0b46.zip -ENV KINDLEGEN kindlegen_linux_2.6_i386_v2_9.tar.gz -ENV NAROU_VERSION 3.5.1 -WORKDIR /opt/narou - -RUN apk --update add ruby ruby-io-console ruby-json ruby-etc wget unzip && rm -rf /var/cache/apk/* +FROM adoptopenjdk/openjdk8:alpine-slim +LABEL maintainer "Kazushi (Jam) Marukawa " -RUN wget https://github.com/kyukyunyorituryo/AozoraEpub3/releases/download/1.1.1b3Q/AozoraEpub3-1.1.1b3Q.zip -O /opt/AozoraEpub3.zip -#RUN wget https://github.com/jam7/AozoraEpub3/releases/download/1.1.0b46/${AOZORA_EPUB3} -O /opt/AozoraEpub3.zip -#RUN wget https://github.com/jam7/AozoraEpub3/releases/download/openjdk-support/AozoraEpub3.jar -O /opt/AozoraEpub3.jar +ENV NAROU_VERSION 3.8.0 +WORKDIR /opt/narou -RUN wget http://kindlegen.s3.amazonaws.com/${KINDLEGEN} && \ - mkdir -p /opt/kindlegen && \ - tar zxf ${KINDLEGEN} -C /opt/kindlegen && \ - rm ${KINDLEGEN} +RUN apk --update add --no-cache ruby ruby-io-console ruby-json ruby-etc ca-certificates curl unzip docker-cli su-exec #COPY narou-${NAROU_VERSION}.gem . RUN apk add --no-cache --virtual .ruby-builddeps build-base libffi-dev ruby-dev && \ gem install narou -v ${NAROU_VERSION} --no-document && \ apk del .ruby-builddeps -COPY init.sh /usr/local/bin - -WORKDIR /opt/narou/work +COPY entrypoint.sh /narou/ +COPY init.sh /narou/ +COPY kindlegen.sh /narou/ +COPY narou.sh /narou/ -ENTRYPOINT ["init.sh"] -CMD ["narou"] +ENTRYPOINT ["/narou/entrypoint.sh"] diff --git a/Makefile b/Makefile index dddc1d2..e6eb816 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -RELEASE_VERSION = v1.14 +RELEASE_VERSION = v1.15 VERSION = latest OPTIONS = \ @@ -9,9 +9,9 @@ OPTIONS = \ --build-arg no_proxy=${no_proxy} build: FORCE - docker build -t jam7/narou-alpine:${VERSION} ${OPTIONS} . + docker build -t jam7/narou:${VERSION} ${OPTIONS} . release: FORCE - docker build -t jam7/narou-alpine:${RELEASE_VERSION} ${OPTIONS} . + docker build -t jam7/narou:${RELEASE_VERSION} ${OPTIONS} . FORCE: diff --git a/README.md b/README.md index ce3360a..9e0d42f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # narou-docker-alpine -A narou.rb in docker using alpine / narou.rbをalpine linuxで実行するためのdocker環境 +A docker container to run narou as a host user. ## Prerequisite @@ -7,41 +7,80 @@ Need to install docker. ## Install -In order to use this, installation is not really needed. There is docker image in public. +Download container and run it to generate kindlegen script. ``` -$ docker pull jam7/narou-alpine +$ docker pull jam7/narou +$ docker run --rm jam7/narou > narou +$ chmod a+x narou ``` -## Build +Don't add `-ti` to `docker run`. Otherwise, you may create a narou +script with crlf. -In order to build image by yourself, perform `make` +## How to use it + +Use a generated narou script. All downloaded data is stored at +$HOME/.narou. ``` -$ make +$ ./narou list + % Total % Received % Xferd Average Speed Time Time Time Current + Dload Upload Total Spent Left Speed +100 632 100 632 0 0 2202 0 --:--:-- --:--:-- --:--:-- 2209 +100 4765k 100 4765k 0 0 5719k 0 --:--:-- --:--:-- --:--:-- 9845k +.narou/ を作成しました +小説データ/ を作成しました +------------------------------ +AozoraEpub3の設定を行います + !!!WARNING!!! +AozoraEpub3の構成ファイルを書き換えます。narouコマンド用に別途新規インストールしておくことをオススメします + +(次のファイルを書き換えました) +/opt/narou/AozoraEpub3-1.1.1b9Q/chuki_tag.txt + +(次のファイルをコピーor上書きしました) +/opt/narou/AozoraEpub3-1.1.1b9Q/AozoraEpub3.ini +/opt/narou/AozoraEpub3-1.1.1b9Q/template/OPS/css_custom/vertical_font.css +AozoraEpub3の設定を終了しました +初期化が完了しました! +現在のフォルダ下で各種コマンドが使用出来るようになりました。 +まずは narou help で簡単な説明を御覧ください。 +device を kindle に設定しました +端末をKindleに指定したことで、以下の関連設定が変更されました + → default.enable_half_indent_bracket が true に変更されました + +$ ``` -## Usage +### Run as web service (not tested recently) -It is easy to use through [narou-docker-script](https://github.com/jam7/narou-docker-script). +Use `docker run -p IP-ADDRESS:8000-8001:8000-8001 narou web -p 8000 -n`. Narou.rb uses sepecified port 8000 for web server and +1 port 8001 for push_server. -## Where is data directory +## How to convert old data -All data are stored in `/opt/narou`. So, use docker something like `docker run -v $HOME/.narou:/opt/narou ...` to use your `$HOME/.narou` as the data directory. +From v1.14, narou-docker changes to run as a host user. So, it is required +to chown $HOME/.narou to a host user is required. Old narou-docker runs as +a root user. -## Run as web service +``` +$ sudo chown -R `id -u`:`id -g` $HOME/.narou +``` -Use `docker run -p IP-ADDRESS:8000-8001:8000-8001 narou web -p 8000 -n`. Narou.rb uses sepecified port 8000 for web server and +1 port 8001 for push_server. +## Build + +In order to build image by yourself, perform `make` + +``` +$ make +``` ## License -@ 2017 Kazushi (Jam) Marukawa, All rights reserved. +@ 2017-2021 Kazushi (Jam) Marukawa, All rights reserved. This project including all of its source files is released under the terms of [GNU General Public License (version 3 or later)](http://www.gnu.org/licenses/gpl.txt) ## Related projects -narou.rb is in https://github.com/whiteleaf7/narou. -narou-docker is in https://github.com/migimigi/narou-docker. - - +narou.rb is in https://github.com/whiteleaf7/narou. diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..21bd069 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +# This is the entrypoint script for the dockerfile. Executed in the +# container at runtime. Based on dockcross. + +if [[ $# == 0 ]]; then + # Presumably the image has been run directly, so help the user get + # started by outputting the dockcross script + cat /narou/narou.sh + exit 0 +fi + +# If we are running docker natively, we want to create a user in the container +# with the same UID and GID as the user on the host machine, so that any files +# created are owned by that user. Without this they are all owned by root. +# The dockcross script sets the NAROU_UID and NAROU_GID vars. +if [[ -n "$NAROU_UID" ]] && [[ -n "$NAROU_GID" ]] && [[ -n "$NAROU_GROUP" ]]; then + + addgroup -g $NAROU_GID $NAROU_GROUP + adduser -g "" -D -G $NAROU_GROUP -u $NAROU_UID $NAROU_USER + export HOME=/home/${NAROU_USER} + chown -R $NAROU_UID:$NAROU_GID $HOME + + addgroup docker + addgroup $NAROU_USER docker + # Cannot find a way to specify multiple groups in su-exec. + # So, adding g+s to kindlegen + chgrp docker /narou/kindlegen.sh + chmod g+s /narou/kindlegen.sh + + # Enable passwordless sudo capabilities for the user + chown root:$NAROU_GID $(which su-exec) + chmod +s $(which su-exec); sync + + # Run the command as the specified user/group. + exec su-exec $NAROU_USER /narou/init.sh "$@" +else + # Just run the command as root. + exec "$@" +fi diff --git a/init.sh b/init.sh index f94c162..0978e40 100755 --- a/init.sh +++ b/init.sh @@ -1,10 +1,24 @@ #!/bin/sh -if [ ! -d "/opt/narou/.narou" ]; then - unzip -q /opt/AozoraEpub3.zip -d /opt/narou/AozoraEpub3 -# cp /opt/AozoraEpub3.jar /opt/narou/AozoraEpub3 - ln -s /opt/kindlegen/kindlegen /opt/narou/AozoraEpub3 - narou init -p /opt/narou/AozoraEpub3 -l 1.6 +AOZORA_VERSION=1.1.1b9Q +AOZORA_ZIP=AozoraEpub3-${AOZORA_VERSION}.zip +AOZORA_DIR=/opt/narou/AozoraEpub3-${AOZORA_VERSION} + +# Extract the latest AozoraEpub3 to /opt/narou (host's $HOME/.narou). +if [ ! -d ${AOZORA_DIR} ]; then + + curl -L https://github.com/kyukyunyorituryo/AozoraEpub3/releases/download/${AOZORA_VERSION}/${AOZORA_ZIP} -o /tmp/${AOZORA_ZIP} + unzip -q /tmp/${AOZORA_ZIP} -d /opt/narou + ln -s /narou/kindlegen.sh ${AOZORA_DIR}/kindlegen + + # Create dummy directories + mkdir -p /opt/narou/AozoraEpub3-1.1.1b9Q/template/OPS/css_custom/ + + # Initialize by narou + narou init -p ${AOZORA_DIR} -l 1.6 +fi + +if [ ! -d "/opt/narou/.narousetting" ]; then narou setting device=kindle # Do not make .narousetting nor .narou directory at the beginning # since narou changes it's behavior of existance of them. diff --git a/kindlegen.sh b/kindlegen.sh new file mode 100755 index 0000000..64ff00e --- /dev/null +++ b/kindlegen.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +CMD="/opt/kindlegen/kindlegen" +TTY="" + +case .$1 in +.*sh|.*bash) CMD=""; TTY="-ti";; +esac + +# Need to specify host's mount point, so we use $HOME/.narou identical to +# narou.sh. +exec docker run $TTY --rm \ + -v "$HOME/.narou":/opt/narou \ + -e KINDLEGEN_UID="$( id -u )" \ + -e KINDLEGEN_GID="$( id -g )" \ + -e KINDLEGEN_USER="$( id -un )" \ + -e KINDLEGEN_GROUP="$( id -gn )" \ + jam7/kindlegen "$CMD" "$@" diff --git a/narou.sh b/narou.sh new file mode 100755 index 0000000..fbe27a6 --- /dev/null +++ b/narou.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# +# Usage: +# narou +# +# Example: +# narou -h to see on-line help +# narou ls to see the list of contents +# narou download n4830bu to download n4830bu narou-shousetsu +# narou web to start web UI +# +# Notice: +# "narou web" ignore all options and starts web UI at localip:8000 + +envs="http_proxy https_proxy ftp_proxy no_proxy" +data=$HOME/.narou + +# check environment variables of particular names in $envs and pass them to container +for i in $envs; do + v=`eval echo $"$i"` + case x$v in + x) ;; # nothing to do + *) opt="-e $i=$v $opt" + esac +done + +# initialize narou configuration directory +if [ ! -d $data ]; then + mkdir $data +fi + +CMD="narou" +TTY="-ti" + +case x$1 in +xw|xweb) + # retrieve external IP address of local machine to allow access from other machiens + IP=`ip route get 1|grep src|sed -e 's:^.*src \([1-9][0-9.]*\).*$:\1:'` + echo "connect $IP:8000 from web browser" + opt="-p $IP:8000-8001:8000-8001 $opt" + set -- web -p 8000 -n + narou s server-ws-add-accepted-domains=$IP + ;; +xsh|xbash) + CMD="" + TTY="-ti" + ;; +xinit) + case x$# in + x1) + set -- init -p /opt/narou/AozoraEpub3 --line-height 1.6 + ;; + esac + ;; +esac + +# Need to mount docker.sock in order to use jam7/kindlegen docker image. +docker run $TTY --rm $opt \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v $data:/opt/narou \ + -v /mnt/Kindle:/mnt/Kindle \ + -e NAROU_UID="$( id -u )" \ + -e NAROU_GID="$( id -g )" \ + -e NAROU_USER="$( id -un )" \ + -e NAROU_GROUP="$( id -gn )" \ + jam7/narou $CMD "$@"