LoginSignup
0
0

MDwiki+CloudRunで、簡単に認証つきドキュメントサイトをホスティング

Last updated at Posted at 2023-08-12

やること

  • ドキュメントをWebで見れるようにする(こんな見た目)
  • ページにはBasic認証をつける
  • ドキュメントはMarkdownで管理する
  • CloudRunでデプロイする(無料枠でそこそこ使えます)
  • ほんとは個別にIAMを管理したいけど、手っ取り早くやりたい

ファルダ構成

用意するのはDockerfile・index.html・navigation.mdだけです

docs/
 ├ markdown/ (ドキュメントはここに入れる)
 │ ├ category_a/ (markdownはカテゴリに分けられる)
 │ │ └ a.md (カテゴリに分けたmdファイル)
 │ └ index.md (トップページのドキュメント)
 ├ Dockerfile (cloudrunに上げるため)
 ├ index.html (MDwiki本体)
 └ navigation.md (ページの構造)

3つのファイルを用意

Dockerfileは以下をコピペし、ユーザ名・パスワードを設定してください

Dockerfile
FROM nginx

# Basic auth
ARG USERNAME=🔒ユーザ名🔒
ARG PASSWORD=🔒パスワード🔒

# Copy the docs to the nginx root
COPY index.html /usr/share/nginx/html
COPY navigation.md /usr/share/nginx/html
COPY markdown /usr/share/nginx/html

# apply basic auth
RUN apt-get update && apt-get install apache2-utils -y
RUN htpasswd -c -b /etc/nginx/.htpasswd ${USERNAME} ${PASSWORD} && cat /etc/nginx/.htpasswd

# edit nginx config
# add basic auth under http block
RUN sed -i "s|http {|http {\n\tauth_basic \"Restricted Content\";\n\tauth_basic_user_file /etc/nginx/.htpasswd;\n|g" /etc/nginx/nginx.conf

MDwikiのindex.htmlここからダウンロードします
https://github.com/Dynalon/mdwiki/releases

navigation.md(サイトマップ)は以下を参考に設定してください

navigation.md
# サイトのタイトル
[カテゴリ名]()
- [項目名](category_a/a.md)

デプロイ

Dockerfileのあるディレクトリ下でcloudrunに上げるコマンドを叩けば完了です
※gcloudCLIを入れていない場合はこちらを参考にいれてください

cd docs
gcloud run deploy docs --source . --project 🔒プロジェクト名🔒 --region asia-northeast1 --allow-unauthenticated --port 80 --memory 128Mi --max-instances=50 --cpu 1

以上です

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0