From 7a406c1f135bd1020528cf46870b70360342d244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=B2=E3=82=8F=E3=81=974=EF=BC=88=E3=83=90?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B31=EF=BC=89?= Date: Tue, 9 Oct 2018 15:09:50 +0900 Subject: [PATCH] Docker (#2867) * Dockerize Misskey * Add a new line at EOF * Add support Elasticsearch * / * Add setup document for docker * Add english document * Edit docs * docker -> Docker * Arrange format * Update docker.en.md * Modify title --- .config/mongo_initdb_example.js | 13 +++++++++ .dockerignore | 12 ++++++++ .gitignore | 4 +++ Dockerfile | 28 ++++++++++++++++++ docker-compose.yml | 52 +++++++++++++++++++++++++++++++++ docs/docker.en.md | 47 +++++++++++++++++++++++++++++ docs/docker.ja.md | 48 ++++++++++++++++++++++++++++++ 7 files changed, 204 insertions(+) create mode 100644 .config/mongo_initdb_example.js create mode 100755 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 docs/docker.en.md create mode 100644 docs/docker.ja.md diff --git a/.config/mongo_initdb_example.js b/.config/mongo_initdb_example.js new file mode 100644 index 0000000000..b7e7321f35 --- /dev/null +++ b/.config/mongo_initdb_example.js @@ -0,0 +1,13 @@ +var user = { + user: 'example-misskey-user', + pwd: 'example-misskey-pass', + roles: [ + { + role: 'readWrite', + db: 'misskey' + } + ] +}; + +db.createUser(user); + diff --git a/.dockerignore b/.dockerignore new file mode 100755 index 0000000000..a25d4e5718 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.autogen +.git +.github +.travis +.vscode +Dockerfile +build/ +docker-compose.yml +node_modules/ +mongo/ +redis/ +elasticsearch/ diff --git a/.gitignore b/.gitignore index 2cea822c18..1e12e20de2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.config/* !/.config/example.yml +!/.config/mongo_initdb_example.js /.vscode /node_modules /build @@ -12,3 +13,6 @@ npm-debug.log run.bat api-docs.json *.log +/redis +/mongo +/elasticsearch diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..64c0b8b589 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM alpine:latest AS base + +ENV NODE_ENV=production + +RUN apk add --no-cache nodejs nodejs-npm +RUN apk add vips fftw --update-cache --repository https://dl-3.alpinelinux.org/alpine/edge/testing/ +WORKDIR /misskey +COPY . ./ + +FROM base AS builder + +RUN apk add --no-cache gcc g++ python autoconf automake file make nasm +RUN apk add vips-dev fftw-dev --update-cache --repository https://dl-3.alpinelinux.org/alpine/edge/testing/ +RUN npm install \ + && npm install -g node-gyp \ + && node-gyp configure \ + && node-gyp build \ + && npm run build + +FROM base AS runner + +COPY --from=builder /misskey/built ./built +COPY --from=builder /misskey/node_modules ./node_modules + +RUN apk add --no-cache tini +ENTRYPOINT ["/sbin/tini", "--"] + +CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..1b2e6c9fc3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,52 @@ +version: "3" + +services: + web: + build: . + restart: always + links: + - mongo + - redis +# - es + ports: + - "127.0.0.1:3000:3000" + networks: + - internal_network + - external_network + + redis: + restart: always + image: redis:4.0-alpine + networks: + - internal_network +### Uncomment to enable Redis persistance +# volumes: +# - ./redis:/data + + mongo: + restart: always + image: mongo:4.1-bionic + networks: + - internal_network + environment: + MONGO_INITDB_DATABASE: "misskey" + volumes: + - ./.config/mongo_initdb.js:/docker-entrypoint-initdb.d/mongo_initdb.js:ro +### Uncomment to enable MongoDB persistance +# - ./mongo:/data + +# es: +# restart: always +# image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.2 +# environment: +# - "ES_JAVA_OPTS=-Xms512m -Xmx512m" +# networks: +# - internal_network +#### Uncomment to enable ES persistence +## volumes: +## - ./elasticsearch:/usr/share/elasticsearch/data + +networks: + internal_network: + internal: true + external_network: diff --git a/docs/docker.en.md b/docs/docker.en.md new file mode 100644 index 0000000000..d0546c0a2a --- /dev/null +++ b/docs/docker.en.md @@ -0,0 +1,47 @@ +Docker Guide +================================================================ + +This guide describes how to install and setup Misskey with Docker. + +[Japanese version also available - 日本語版もあります](./docker.ja.md) + +---------------------------------------------------------------- + +*1.* Make configuration files +---------------------------------------------------------------- +1. `cp .config/example.yml .config/default.yml` Copy the `.config/example.yml` and rename it to `default.yml`. +2. `cp .config/mongo_initdb_example.js .config/mongo_initdb.js` Copy the `.config/mongo_initdb_example.js` and rename it to `mongo_initdb.js`. +2. Edit `default.yml` and `mongo_initdb.js`. + +*2.* Configure Docker +---------------------------------------------------------------- +Edit `docker-compose.yml`. + +*3.* Build Misskey +---------------------------------------------------------------- +Build misskey with the following: + +`docker-compose build` + +*4.* That is it. +---------------------------------------------------------------- +Well done! Now, you have an environment that run to Misskey. + +### Launch normally +Just `docker-compose up -d`. GLHF! + +### Way to Update to latest version of your Misskey +1. `git fetch` +2. `git stash` +3. `git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)` +4. `git stash pop` +5. `docker-compose build` +6. Check [ChangeLog](../CHANGELOG.md) for migration information +7. `docker-compose stop && docker-compose up -d` + +### Way to execute cli command: +`docker-compose run --rm web node cli/mark-admin @example` + +---------------------------------------------------------------- + +If you have any questions or troubles, feel free to contact us! diff --git a/docs/docker.ja.md b/docs/docker.ja.md new file mode 100644 index 0000000000..e38f3e91a6 --- /dev/null +++ b/docs/docker.ja.md @@ -0,0 +1,48 @@ +Dockerを使ったMisskey構築方法 +================================================================ + +このガイドはDockerを使ったMisskeyセットアップ方法について解説します。 + +[英語版もあります - English version also available](./docker.en.md) + +---------------------------------------------------------------- + +*1.* 設定ファイルを作成する +---------------------------------------------------------------- +1. `cp .config/example.yml .config/default.yml` `.config/example.yml`をコピーし名前を`default.yml`にする +2. `cp .config/mongo_initdb_example.js .config/mongo_initdb.js` `.config/mongo_initdb_example.js`をコピーし名前を`mongo_initdb.js`にする +3. `default.yml`と`mongo_initdb.js`を編集する + +*2.* Dockerの設定 +---------------------------------------------------------------- +`docker-compose.yml`を編集してください。 + +*3.* Misskeyのビルド +---------------------------------------------------------------- +次のコマンドでMisskeyをビルドしてください: + +`docker-compose build` + +*4.* 以上です! +---------------------------------------------------------------- +お疲れ様でした。これでMisskeyを動かす準備は整いました。 + +### 通常起動 +`docker-compose up -d`するだけです。GLHF! + +### Misskeyを最新バージョンにアップデートする方法: +1. `git fetch` +2. `git stash` +3. `git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)` +4. `git stash pop` +5. `docker-compose build` +6. [ChangeLog](../CHANGELOG.md)でマイグレーション情報を確認する +7. `docker-compose stop && docker-compose up -d` + +### cliコマンドを実行する方法: + +`docker-compose run --rm web node cli/mark-admin @example` + +---------------------------------------------------------------- + +なにかお困りのことがありましたらお気軽にご連絡ください。 \ No newline at end of file