Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docker working dir #107

Merged
merged 13 commits into from
Apr 22, 2020
Merged

Fix docker working dir #107

merged 13 commits into from
Apr 22, 2020

Conversation

tamakiii
Copy link
Collaborator

@tamakiii tamakiii self-assigned this Apr 18, 2020
@tamakiii
Copy link
Collaborator Author

make publish して http://localhost:8080/

🧸 sarabi-mastiff.lan:covid19-surveyor
$ docker-compose exec crawler make publish
./crawler/publish.sh > ./www-data/index.html

Copy link
Collaborator

@515hikaru 515hikaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

気づいたことをコメントしました。動作は問題なかったです。

README.md Show resolved Hide resolved
docker-entrypoint.sh Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
WORKDIR /app
COPY . /app
WORKDIR /home/ubuntu/vscovid-crawler
COPY . /home/ubuntu/vscovid-crawler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ディスクデバイスの様子を見ると現実的じゃない。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すみません。
wget しなければへいきですね。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いや。

make wget した後でも使えるようになっていないと困ります。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そもそもentrypointを指定していたのはこれが原因なんだけど、そもそもdocker buildしたタイミングでcurrent directoryを全部参照するっぽいので今の構造自体をdockerのためにリファクタリングしないといけないのでは....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

僕のPRでentrypointをわざとDockerfileに書かなかった理由ですね。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

わかりにくい文になってしまいましたが、「 .dockerignore で /tmp を指定しているので、build 時に /tmp は COPY されない」はずです

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make wget したときに www-data/ に数十GB のファイルができるので、そちらを懸念しているのだと思います。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そもそもですが、 docker-compose.yml でマウントしているように見えるんですがプロジェクト全ファイルの COPY は必要なんでしょうか?

少なくともビルド時に必要なファイルは、明示的に COPY しているように見えるのですが。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make wget の成果物 /result.txt/www-data/ 以下のサイトを認識したので .dockerignore に追加しました。
www-data 以下の成果物は出力先の構造的に適切にignoreできなそうだったので www-data そのものを ignore してしまっています。
他にもあれば追加します

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そもそもですが、 docker-compose.yml でマウントしているように見えるんですがプロジェクト全ファイルの COPY は必要なんでしょうか?

Docker Image 単体で動くのが好ましいという観点からアプリケーションに当たるこのリポジトリ全体を COPY しています。
「docker-compose で volume マウントする開発環境」と割り切るなら、混乱されてそうですし COPY しない方に倒すでもいいかなーと思ってます

@takano32 takano32 self-requested a review April 18, 2020 14:27
Copy link
Member

@takano32 takano32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いつ make wget するのか、を明確にしないとですね。

docker-compose up のたびに走るのは現実的に使い物にならない。

make wget した後のディレクトリをコピーするのはディスク容量に問題がある。

@tamakiii
Copy link
Collaborator Author

tamakiii commented Apr 19, 2020

docker-compose exec crawler make wget 実行後に docker-compose build
Layer は現状こんな感じ COPY ... in /home/ubuntu/vscovid-crawler が 410KB

🧸 sarabi-mastiff.lan:covid19-surveyor
$ docker history --no-trunc covid19-surveyor_crawler:latest
IMAGE                                                                     CREATED              CREATED BY                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 SIZE                COMMENT
sha256:5fa53fc8e2588d088f62e4dee8c0a77a8302e075e03a071be88b69d09a073ac5   About a minute ago   /bin/sh -c #(nop)  EXPOSE 80                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               0B
sha256:3e56d66520139c4545cc8beacf02a3c76baf3b908cd7f4df32bdc533ce599aff   About a minute ago   /bin/sh -c #(nop) COPY file:cce6012199ce0d694045839f3ed131dbfeda32990f8f2b3f0bd5396decf9244c in /usr/local/sbin/redis-cli                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  52B
sha256:04531ee1cea65163a7af4b34d6f3e075e00ab5f734db7ecccd60329f7e74173f   About a minute ago   /bin/sh -c #(nop)  ENTRYPOINT ["docker-entrypoint.sh"]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     0B
sha256:f9d8e89a3f0b4c3748cb707a07c0fb7cc69d3ddf63334992829df6967ba3916f   About a minute ago   /bin/sh -c #(nop) COPY file:11b7ed291b297f01f85bc325136f35230e3476f7eee398b295f7396778a0639a in /usr/local/sbin/docker-entrypoint.sh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       309B
sha256:fb31848a1d352a785cd4521d2309d9e4f3b26f5c05e588e2ed85935067dfb4ad   About a minute ago   /bin/sh -c #(nop) COPY dir:004a36f2786ec1d6fddfc9a5f120f138957d5ee49d0ef7275925ac8b07851076 in /home/ubuntu/vscovid-crawler                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                410kB
sha256:677004730a146b0098f42d9d85fdc6331d12298f4be54b620d88e2380e730cb8   19 hours ago         /bin/sh -c #(nop) WORKDIR /home/ubuntu/vscovid-crawler                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     0B
sha256:1798afbf84a7a3adba65127837f80cbf89e37f4be8a66ad4ae00f95afe83158c   19 hours ago         /bin/sh -c #(nop) COPY file:da09fe60620f1012a4ffbc803ea83161433b023b7921ec971a6118c87843fa70 in /etc/squid/squid.conf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      291kB
sha256:6377a2947a873098ee7b89a4ce974d0147ed71fd753bc86e9fdee40358d5a3cb   19 hours ago         /bin/sh -c ln -s /etc/nginx/sites-available/vscovid-crawler.conf /etc/nginx/sites-enabled/vscovid-crawler.conf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             47B
sha256:73d759875903e3f543af027a15acc94bdb18b0dfd90b76804a4b0ce576dba959   19 hours ago         /bin/sh -c #(nop) COPY file:9e31cabc65c3fa05a0238b4967b7f4d9ba068f28484bac923db638021c0bf582 in /etc/nginx/sites-available/vscovid-crawler.conf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            714B
sha256:a6f3d072d94e0b5a9ac9f2fd669fa4442fd710df13ce5880c012b52b9aa14109   19 hours ago         /bin/sh -c apt-get update &&     apt-get install -y       make       wget       jq       nginx       fcgiwrap       squid       redis-tools       poppler-utils       &&     apt-get clean &&     rm -rf /var/lib/apt/lists/*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              147MB
sha256:17d9de846f007b658f5ebcadbc8c77ea441624d1db42f77844989f329b53dece   27 hours ago         /bin/sh -c #(nop)  MAINTAINER TAKANO Mitsuhiro                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             0B
sha256:4e5021d210f65ebe915670c7089120120bc0a303b90208592851708c1b8c04bd   4 weeks ago          /bin/sh -c #(nop)  CMD ["/bin/bash"]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       0B
<missing>                                                                 4 weeks ago          /bin/sh -c mkdir -p /run/systemd && echo 'docker' > /run/systemd/container                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 7B
<missing>                                                                 4 weeks ago          /bin/sh -c set -xe   && echo '#!/bin/sh' > /usr/sbin/policy-rc.d  && echo 'exit 101' >> /usr/sbin/policy-rc.d  && chmod +x /usr/sbin/policy-rc.d   && dpkg-divert --local --rename --add /sbin/initctl  && cp -a /usr/sbin/policy-rc.d /sbin/initctl  && sed -i 's/^exit.*/exit 0/' /sbin/initctl   && echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup   && echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean  && echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean  && echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean   && echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages   && echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes   && echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests   745B
<missing>                                                                 4 weeks ago          /bin/sh -c [ -z "$(apt-get indextargets)" ]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                987kB
<missing>                                                                 4 weeks ago          /bin/sh -c #(nop) ADD file:594fa35cf803361e69d817fc867b6a4069c064ffd20ed50caf42ad9bb11ca999 in /                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           63.2MB

@tamakiii
Copy link
Collaborator Author

tamakiii commented Apr 19, 2020

server_name ~^(?<domain>.+)\.help\.stopcovid19\.jp$; がこうできれば

-         root /home/ubuntu/vscovid-crawler/www-data/$domain;
+         root /home/ubuntu/vscovid-crawler/www-data/generated-sites/$domain;

.dockerignore をこうできて ignore の範囲が適切にできそう

- /www-data/
+ /www-data/generated-sites/

@tamakiii
Copy link
Collaborator Author

--no-install-recommends がついてなかったので追加
apt-get update && apt-get install が 147MB -> 126MB に

@tamakiii
Copy link
Collaborator Author

いつ make wget するのか、を明確にしないとですね。

docker-compose up 後に docker-compose exec crawler make wget する」でいいと思います
「crawler はいろいろな make コマンドが動く」「成果物を nginx で配信する」のうちのひとつに make wget もあるという感じでよいと思います
クラウドストレージに最新の成果物を置いておいて起動時に取ってくる、とかするといいんだろうとは思うんですが、まずは各自の環境で make wget できるようにするのが優先かなと思います

docker-compose up のたびに走るのは現実的に使い物にならない。

そうですねー

make wget した後のディレクトリをコピーするのはディスク容量に問題がある。

.dockerignore に設定していれば問題にはなりませんが、このへん混乱を生みそうであれば COPY しないのも手かなーと思います

@tamakiii tamakiii requested a review from takano32 April 19, 2020 06:31
@yuiseki
Copy link
Member

yuiseki commented Apr 19, 2020

make wgetは非現実的なくらい容量消費するうえに全自治体のサイトに負荷がかかるから各自のDocker環境でやってほしくないです。
あるいは、environment環境変数をチェックして、以下のように分岐してほしいです

.PHONY: wget
wget:
ifeq ($(ENV),production)
	./crawler/wget.sh data/gov.csv data/pref.csv data/city.csv
else
	./crawler/wget.sh data/test.csv
endif
	./crawler/remove-large-files.sh

@tamakiii
Copy link
Collaborator Author

make wgetは非現実的なくらい容量消費するうえに全自治体のサイトに負荷がかかるから各自のDocker環境でやってほしくないです。

ですよねー。わかります。
とはいえ一部でもデータがないとこの後に続く処理が本番でしか動かせなくなっちゃうのはいい感じにしたいですね、

readme に make wget は悪手なので消すとして(どなたか既に対応してくださってましたが)、nginx が正常に動かないのを直すところまでは進めたいんですが、どうしましょうか…

@kobake
Copy link
Collaborator

kobake commented Apr 20, 2020

とはいえ一部でもデータがないとこの後に続く処理が本番でしか動かせなくなっちゃうのはいい感じにしたいですね

@yuiseki さんの提示したサンプルコードを踏襲すれば else のところの ./crawler/wget.sh data/test.csv これが少量のデータは取ってきてくれると思います。

@tamakiii
Copy link
Collaborator Author

SQS障害にやられておりました…。

あるいは、environment環境変数をチェックして、以下のように分岐してほしいです

すでに 464c06d でしてくださっているのを確認しました。ありがとうございます。

data/test.csv これが少量のデータは取ってきてくれると思います。

よさそうでした〜

@tamakiii
Copy link
Collaborator Author

現状あまり使っている人がいなそうで優先度は低そうな気がしているんですが、中途半端な状態で残すのは後に混乱を生みそうなので、nginxが動く所までマージしたいと思っています〜

Copy link
Collaborator

@515hikaru 515hikaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 本番環境では Docker は使わない
  • make wget は本番環境以外では法外な容量にはならない
    という前提ができたのでいいと思います。既に reduce.csv がリポジトリにあるので、 make publish でローカルNGINXの動作確認はできました。

@515hikaru 515hikaru merged commit 6dc164a into master Apr 22, 2020
@515hikaru 515hikaru deleted the fix-docker-working-dir branch April 22, 2020 11:53
@takano32
Copy link
Member

takano32 commented May 9, 2020

see also. #26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants