Canvas Sandbox(WSL) - eiichiromomma/CVMLAB GitHub Wiki
(Canvas) WSL2でSandbox
LMSのCanvasのSandbox作成のWSL2編。WSL2ならではの問題でハマった。
- WSL2 + Ubuntu 18.04 は自力で入れましょう
- 18.04必須です(20.04は×) ※2022/4時点
- doryが必要(Webサービスをlocal動作させる際,偽のFQDNをいい感じにmapしてくれるらしい)
- WSL2上でのdocker諸々必要
- mutagenが必要(dockerのバインドマウントを高速化)
sudo ntpdate time.google.com
sudo apt update; sudo apt upgrade -y
sudo apt install ruby build-essential git doryは普通にgemで入る
sudo gem install dorygit clone https://github.com/instructure/canvas-lms.git
cd canvas-lms要mutagenなのだがhomebrewしか楽に入れる方法がない。
Homebrewのコマンド
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"を実行するのだが,その後に設定が必要。admin不要としたいがために/home/linuxbrewへインストールされるらしい。
test -d ~/.linuxbrew && eval "$(~/.linuxbrew/bin/brew shellenv)"
test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
test -r ~/.bash_profile && echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bash_profile
echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.profileとかやって
source ~/.profileの後に
brew install helloで確認できる。
で
brew install mutagen-io/mutagen/mutagen
brew install mutagen-io/mutagen/mutagen-composeでmutagenとmutagen-composeを入れる。
ここからはWSL2固有の問題で,IPv6優先の設定が災いしてgemsとyarnの導入で必ずコケる。後に載せたdiff通りDockerfileに記載するだけでは解決しない。( /etc/gai.confに echo precedence ::ffff:0:0/96 100とか書いてるのがそれ)
./script/docker_dev_setup.sh --mutagenを実行するとまず
> Bundle install...のところでGem::RemoteFetcher::UnknownHostError timed outでコケる。これはhostsに rubygems.org に対応するIPを書いて解決する。また,その後で
> Yarn install....のところで必ず getaddrinfo EAI_AGAIN registry.yarnpkg.comでコケるので 8.8.8.8 を /etc/resolv.conf に書き込んだりする。
実際の対処方法は,この時点でコンテナは出来上がっているので,canvas-lms-web-1 に入り込んで上記を書き込む。
まず,hostコマンドでrubygems.orgのIPを確認する
host rubygems.orgで
rubygems.org has address 151.101.65.227
rubygems.org has address 151.101.193.227
rubygems.org has address 151.101.129.227
rubygems.org has address 151.101.1.227
と出た例を以下に示す。
docker exec -it --user=root canvas-lms-web-1 /bin/bashで canvas-lms-web-1 のコンテナにrootで入り
echo "151.101.65.227 rubygems.org" >> /etc/hosts
echo "151.101.193.227 rubygems.org" >> /etc/hosts
echo "151.101.129.227 rubygems.org" >> /etc/hosts
echo "151.101.1.227 rubygems.org" >> /etc/hosts
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
exitで書き換え完了。このままscript/docker_dev_setup.shを再度実行するとまたbuildされてしまうので,同ファイルをコピーして
cp script/docker_dev_setup.sh script/docker_dev_build_assets.shとしたうえで,その中を
create_log_file
init_log_file "Docker Dev Setup"
os_setup
message 'Now we can set up Canvas!'
# copy_docker_config
# setup_docker_compose_override
# build_images
# docker_compose_up
# check_gemfile
build_assets
create_db
display_next_stepsのように コケたところから再開するようにコメントアウトして,そのスクリプトを実行する
./script/docker_dev_build_assets.shで Success !と出たら成功。
mutagen-composeでupする(ちなみにupで開始だからdownとやるとcontainersが全部消える)。
mutagen-compose upで,暫く待ってるとwebpack_1からのログが終わってjobs_1からのログが流れるので,ブラウザで http://localhostを開くとCanvasのログイン画面になれば順調。
この状態だとアカウントが無い状態なのでcontainerの中のrailsでアカウントを作成する。
docker psで確認してIMAGEがcanvas-lms_webのNAMESを見る(たぶんcanvas-lms_web_1)。
docker exec -u 0 -it canvas-lms_web_1 /bin/bashでコンテナに入ると
root@xxxxxxxxxxx:/usr/src/app#のようなプロンプトになるので
rails db:initial_setupを実行すると色々聞かれる。
※アカウント名(the account name)なのだが,特殊な用語で大学-学部-学科のようなツリーを考えたときの大学に相当する
1: development:public
What email address will the site administrator account use? > [ログインIDになるメールアドレスを入力]
Please confirm > [ログインIDになるメールアドレスを入力]
What password will the site administrator use? > [パスワードを入力]
Please confirm > [パスワードを入力]
What do you want users to see as the account name? This should probably be the name of your organization. > [他のユーザーから見たアカウント名]
To help our developers better serve you, Instructure would like to collect some usage data about your Canvas installation. You can change this setting at any time.:
1. Opt in
2. Only send anonymized data
3. Opt out completely
> [開発元に情報を送るかどうかなので2の匿名化か3の拒否が無難]
Thank you for participating in anonymous usage collection.
You can change this feature at any time by running the rake task 'rake db:configure_statistics_collection'
........................................................................................
Notifications Loaded
No notification files found for Assignment Publishing Reminder
No notification files found for Assignment Grading Reminder
No notification files found for Assignment Due Date Reminder
No notification files found for Rubric Assessment Invitation
No notification files found for Migration Export Ready
No notification files found for Migration Import Finished
No notification files found for Migration Import Failed
Initial data loadedで完了。が,doryのproxyはあくまでもWSL2上で機能していて,Windowsでは使えないので http://localhost/ を開くとCanvasのログイン画面が出てくる。
たぶん不要な情報もあるが動いてるからそのまま
diff --git a/Dockerfile b/Dockerfile
index f973e5f232..f4c0d79620 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -33,9 +33,11 @@ ARG USER_ID
# Without it, some linux distributions are unable to write at all to the host mounted volume.
RUN if [ -n "$USER_ID" ]; then usermod -u "${USER_ID}" docker \
&& chown --from=9999 docker /usr/src/nginx /usr/src/app -R; fi
-
+RUN echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf
+RUN apt-get update; apt-get install wget -y
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \
- && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
+ && wget --quiet -O - /tmp/pubkey.gpg https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
+ # && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& printf 'path-exclude /usr/share/doc/*\npath-exclude /usr/share/man/*' > /etc/dpkg/dpkg.cfg.d/01_nodoc \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
@@ -64,7 +66,12 @@ RUN if [ -e /var/lib/gems/$RUBY_MAJOR.0/gems/bundler-* ]; then BUNDLER_INSTALL="
&& gem uninstall --all --ignore-dependencies --force $BUNDLER_INSTALL bundler \
&& gem install bundler --no-document -v $BUNDLER_VERSION \
&& find $GEM_HOME ! -user docker | xargs chown docker:docker
+# RUN gem update --system
RUN npm install -g npm@latest && npm cache clean --force
+RUN echo "151.101.193.227 rubygems.org" >> /etc/hosts
+RUN echo "151.101.1.227 rubygems.org" >> /etc/hosts
+RUN echo "151.101.129.227 rubygems.org" >> /etc/hosts
+RUN echo "151.101.65.227 rubygems.org" >> /etc/hosts
USER docker
diff --git a/Dockerfile.jenkins b/Dockerfile.jenkins
index 9f5a765399..a4f2ca3520 100644
--- a/Dockerfile.jenkins
+++ b/Dockerfile.jenkins
@@ -28,8 +28,10 @@ ENV BUNDLE_APP_CONFIG /home/docker/.bundle
WORKDIR $APP_HOME
USER root
+RUN apt-get update; apt-get install wget -y
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \
- && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
+ && wget --quiet -O - /tmp/pubkey.gpg https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
+ # && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& printf 'path-exclude /usr/share/doc/*\npath-exclude /usr/share/man/*' > /etc/dpkg/dpkg.cfg.d/01_nodoc \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
diff --git a/build/Dockerfile.template b/build/Dockerfile.template
index 61e680d71b..ec0cde9222 100644
--- a/build/Dockerfile.template
+++ b/build/Dockerfile.template
@@ -42,8 +42,10 @@ RUN if [ -n "$USER_ID" ]; then usermod -u "${USER_ID}" docker \
&& chown --from=9999 docker /usr/src/nginx /usr/src/app -R; fi
<% end -%>
+RUN apt-get update; apt-get install wget -y
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \
- && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
+ && wget --quiet -O - /tmp/pubkey.gpg https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
+ # && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& printf 'path-exclude /usr/share/doc/*\npath-exclude /usr/share/man/*' > /etc/dpkg/dpkg.cfg.d/01_nodoc \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
diff --git a/script/common/utils/dory_setup.sh b/script/common/utils/dory_setup.sh
index e04d4165cf..10a6d1b3d9 100755
--- a/script/common/utils/dory_setup.sh
+++ b/script/common/utils/dory_setup.sh
@@ -16,9 +16,9 @@ function check_for_dory {
function start_dory {
message 'Starting dory...'
- if dory status | grep -q 'not running'; then
- confirm_command 'dory up'
- elif ! dory status; then
+ if sudo dory status | grep -q 'not running'; then
+ confirm_command 'sudo dory up'
+ elif ! sudo dory status; then
message "Something went wrong with dory! Exiting script."
exit 1
else