コンテンツにスキップ

2016

Android StudioからGAE for Javaアプリケーションをdeployするのに必要なFacet

こちらの記事を参考にGAE for JavaアプリケーションをAndroid Studio + Gradleでセットアップし、サンプルアプリケーションを開発してみました。

早速GAEにdeployしてみようと、メニューバーの Build から Deploy Module to App Engine... を選択してdeployを実行...ところがタスクが走らずうんともすんとも言わないので調べてみました。

結論

以下の設定を app.iml ファイルに追記する

<facet type="android-gradle" name="Android-Gradle">
  <configuration>
    <option name="GRADLE_PROJECT_PATH" value=":app" />
  </configuration>
</facet>
<facet type="java-gradle" name="Java-Gradle">
  <configuration>
     <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
     <option name="BUILDABLE" value="true" />
  </configuration>
</facet>

こちらは少々特殊な方法でmoduleを作成しているのでFacetの設定が不十分となってしまった模様。

Facetとは

FacetはIntelliJ IDEAに用意された機能で、使用するフレームワークや言語に合わせたFacetを設定することでIntelliJ IDEAが必要なコンポーネントのダウンロードや各種補完機能の設定などを行ってくれるもの。

Android StudioはIntelliJ IDEAをベースとして開発されたIDEなのでFacetの機能を継承している。

参照

DockerでRails環境を構築した手順

2016/07/10 修正: docker-compose.ymlnginx.conf の一部を修正しました

とある経緯で Docker を使って Rails の環境をセットアップした手順です。

setting files

まずは用意した file から。

docker-compose.yml

``` yml docker-compose.yml

not use datastore container now

datastore:

build: Dockerfiles/datastore

mysql: image: mysql:5.6.26 environment: MYSQL_ROOT_PASSWORD: 'pass' ports: - '3306:3306'

volumes_from:

- datastore

nginx: build: Dockerfiles/nginx ports: - '80:80'

volumes_from:

- datastore

links: - web

web: build: .

command: bundle exec unicorn -c config/unicorn.rb

volumes_from:

- datastore

volumes: - .:/usr/src/app ports: - '3000:3000' links: - mysql environment: RAILS_ENV: development MYSQL_ROOT_PASSWORD: 'pass' DATABASE_URL: mysql2://root:pass@mysql:3306 SECRET_KEY_BASE: hogehoge


## Dockerfile
``` dockerfile Dockerfile
FROM rails:onbuild

Dockerfiles/nginx/Dockerfile

``` dockerfile Dockerfile FROM nginx:1.7.9

COPY nginx.conf /etc/nginx/nginx.conf


## Dockerfiles/nginx/nginx.conf
``` bash nginx.conf
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # "on" if nginx worker_processes > 1
}

http {
  include mime.types;
  default_type application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

  access_log  /var/log/nginx/access.log  main;

  sendfile on;

  tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
  tcp_nodelay off; # on may be better for some Comet/long-poll stuff

  gzip on;
  gzip_http_version 1.0;
  gzip_proxied any;
  gzip_min_length 500;
  gzip_disable "MSIE [1-6]\.";
  gzip_types text/plain text/html text/xml text/css
             text/comma-separated-values
             text/javascript application/x-javascript
             application/atom+xml;

  upstream app_server {
    # for UNIX domain socket setups:
    # server unix:/path/to/.unicorn.sock fail_timeout=0;

    # for TCP setups, point these to your backend servers
    # server 192.168.0.7:8080 fail_timeout=0;
    server web:3000 fail_timeout=0;
  }

  server {
    listen       80;
    server_name  localhost;
    client_max_body_size 4G;
    keepalive_timeout 5;

    # path for static files
    root /usr/your_app/home/system/public;

    try_files $uri/index.html $uri.html $uri @app;

    location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app_server;
    }

    # Rails error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /usr/your_app/home/system/public;
    }
  }
}

Setup Tutorial

Download Tools

VirtualBox

https://www.virtualbox.org/wiki/Downloads

please install version >= 5.x

Homebrew

http://brew.sh/index_ja.html

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Docker Tools

Docker
$ brew install docker
Docker Machine
$ brew install docker-machine
Docker Compose
$ brew install docker-compose

Download Application

$ cd ~/path/to/workspace
$ git clone git@github.com:your/App.git your_app
$ cd your_app

Setup Docker Machine

$ docker-machine create --driver virtualbox dev
...

$ docker-machine ls
NAME   ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
dev    -        virtualbox   Running   tcp://192.168.99.100:2376           v1.10.0
$ eval "$(docker-machine env dev)"

$ echo 'eval "$(docker-machine env dev)"' >> ~/.bashrc
$ docker-machine start dev
...

$ docker-machine ip dev
192.168.99.100

Setup Application

Build Docker Images and Start Containers

# ~/path/to/workspace/your_app
$ docker-compose build
...

$ docker-compose up
...

please open another tab

Setup DB

$ docker-compose run web rake db:create
$ docker-compose run web rake db:migrate

Access Application

$ docker-machine ip dev
192.168.99.100

access to 192.168.99.100:3000

plenv で perl を管理する

Perl をバージョンごと、あるいはプロジェクトごとに管理するためのツールである plenv の導入手順メモ

plenv をインストールする

homebrew の update

$ brew update
Updated Homebrew from c0fae05 to bfe20af.
No changes to formulae.

先ほど rbenv をインストールする手順 で同じことをやったばかりなので更新なし

plenv と perl-build のインストール

これも どこか で見たような手順

perl-buildplenv のプラグイン

$ brew install plenv perl-build
==> Downloading https://github.com/tokuhirom/plenv/archive/2.2.0.tar.gz
==> Downloading from https://codeload.github.com/tokuhirom/plenv/tar.gz/2.2.0
...

plenv init

$ echo 'eval "$(plenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

plenv init - でやっていることは以下の通り

$ plenv init -
export PATH="/Your/Home/Directory/.plenv/shims:${PATH}"
export PLENV_SHELL=bash
source '/usr/local/Cellar/plenv/2.2.0/libexec/../completions/plenv.bash'

plenv() {
  local command

  command="$1"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "`plenv "sh-$command" "$@"`";;
  *)
    command plenv "$command" "$@";;
  esac
}

perl のインストール

インストールできる perl のバージョンを確認

$ plenv install -l
Available versions:
 5.6.0
 5.6.1-TRIAL1
 5.6.1-TRIAL2
...

最新の安定版であるバージョン 5.22.1 をインストールする

$ plenv install 5.22.1
Installing 5.22.1 as 5.22.1
...

インストールされたバージョンを確認

$ plenv versions
* system (set by /My/Home/Directory/.plenv/version)
  5.22.1

使用する perl を設定

$ plenv global 5.22.1
$ plenv versions
  system
* 5.22.1 (set by /My/Home/Directory/.plenv/version)

perl に cpanm をインストールする

現在使用している perl に cpanm をインストールする

$ plenv install-cpanm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   314    0   314    0     0   2078      0 --:--:-- --:--:-- --:--:--  2079
100  296k  100  296k    0     0   367k      0 --:--:-- --:--:-- --:--:-- 2135k
...

cpanm のパスが変わっていることを確認

$ which cpanm
/My/Home/Directory/.plenv/shims/cpanm

参照

rbenv で ruby を管理する

Ruby をバージョンごと、あるいはプロジェクトごとに管理するためのツールである rbenv の導入手順メモ

rbenv をインストールする

homebrew の update

$ brew update
Updated Homebrew from b369c25 to c0fae05.
...

rbenv と ruby-build のインストール

rbenv と同時に ruby-build もインストールする

ruby-buildrbenv のプラグインで rbenv install コマンドを提供する

$ brew install rbenv ruby-build
==> Installing dependencies for rbenv: autoconf, pkg-config, openssl, ruby-build
...

rbenv init

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

rbenv init - でやっていることは以下の通り

$ rbenv init -
export PATH="/Your/Home/Directory/.rbenv/shims:${PATH}"
export RBENV_SHELL=bash
source '/usr/local/Cellar/rbenv/1.0.0/libexec/../completions/rbenv.bash'
command rbenv rehash 2>/dev/null
rbenv() {
  local command
  command="$1"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "$(rbenv "sh-$command" "$@")";;
  *)
    command rbenv "$command" "$@";;
  esac
}

ruby のインストール

インストールできる ruby のバージョンを確認

$ rbenv install -l
Available versions:
  1.8.6-p383
  1.8.6-p420
  1.8.7-p249
...

バージョン 2.2.0 をインストールする

$ rbenv install 2.2.0
Downloading ruby-2.2.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.0.tar.bz2
Installing ruby-2.2.0...
...

インストールされたバージョンを確認

$ rbenv versions
* system (set by /My/Home/Directory/.rbenv/version)
  2.2.0

使用する ruby を設定

$ rbenv global 2.2.0
$ rbenv versions
  system
* 2.2.0 (set by /My/Home/Directory/.rbenv/version)

ブログを管理しているディレクトリは system ruby にしておく

$ cd git/blog/
$ rbenv local system
$ rbenv versions
* system (set by /My/Home/Directory/git/blog/.ruby-version)
  2.2.0
$ cd
$ rbenv versions
  system
* 2.2.0 (set by /My/Home/Directory/.rbenv/version)

参照

minil を使った Changes ファイルの更新

CPAN モジュールの bug fix を行ったので修正版をリリース。

minil 様様と思いながら minil release コマンドを打つのだが、 いつも Changes ファイルの更新のところで、どこに何を書けば良いのだっけ?となってしまうのでここにメモしておくことにした。

{{$NEXT}} の下に書く

今回のリリースだとこうなった

Revision history for Perl extension JSON-MergePatch

{\{$NEXT}}

    - (bug fix) diff() :when the same hash-refs are present in the hash values of source and target (thanks bessarabov)
    - refactoring

0.02 2015-09-13T09:08:20Z

    - use JSON::MaybeXS and fix keys arg

0.01 2015-07-02T18:29:20Z

    - original version

{{$NEXT}} となっているところにバージョンやら日付やらが入る。

参照

Minilla チュートリアルドキュメント