Skip to content

Instantly share code, notes, and snippets.

@kotauchisunsun
Created August 9, 2017 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotauchisunsun/e19dd56bdc832da380f2516f4eb63bf9 to your computer and use it in GitHub Desktop.
Save kotauchisunsun/e19dd56bdc832da380f2516f4eb63bf9 to your computer and use it in GitHub Desktop.
サーバーレスの入門に!自宅サーバーレス+自宅S3環境で作るサーバーレス・サムネイルサーバー! ref: http://qiita.com/kotauchisunsun/items/856e7ecb65bb06f85ffa
# minioを起動
$ sudo docker run --rm -p 8080:9000 -it \
-e MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE\
-e MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\
minio/minio server /export
# minioへimagesバケットの作成
$ aws --endpoint-url http://192.168.0.6:8080 s3 mb s3://images
# minioへthumbsバケットの作成
$ aws --endpoint-url http://192.168.0.6:8080 s3 mb s3://thumbs
# iron-functionsのサービス
$ sudo docker run --rm -it --name functions -v ${PWD}/data:/app/data \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 8000:8080 iron/functions
# ソースコードをクローン
$ git clone https://github.com/kotauchisunsun/iron_thumbs.git
$ cd iron_thumbs
# パッケージの依存関係を解消
$ glide update
$ sudo fn build
$ fn apps create iron_thumbs \
--config IMAGE_BUCKET=images\
--config THUMB_BUCKET=thumbs\
--config S3_ENDPOINT=http://192.168.0.6:8080\
--config S3_REGION=us-east-1\
--config S3_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE\
--config S3_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
$ fn routes create iron_thumbs /thumbs
# 素材をダウンロード
$ wget "http://4.bp.blogspot.com/-dVbfTZcofUU/VGX8crT5GiI/AAAAAAAApG4/CB7GF5UmMqE/s400/computer_cloud_system.png"
# minioにファイルをアップロード
$ aws --endpoint-url http://192.168.0.6:8080 s3 cp computer_cloud_system.png s3://images/
$ curl "http://localhost:8000/r/iron_thumbs/thumbs?filename=computer_cloud_system.png&size=180" > thumbs.png
$ ab -n 1000 -c 10 "http://localhost:8000/r/iron_thumbs/thumbs?filename=computer_cloud_system.png&size=180"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment