Windows上にDigdagサーバ構成を作る その3 Digdagクライアント


http://qiita.com/pilot/items/e763a67675e264ed0347 および http://qiita.com/pilot/items/a49e6985f1c18aa37b5c の続き

Digdagクライアント作成用Vagrantfile

Vagrant.configure("2") do |config|
  # Vagrant公式Box https://atlas.hashicorp.com/bento
  config.vm.box = "bento/centos-6.7"
  # ネットワーク設定
  config.vm.define :digcl do |digcl|
    digcl.vm.hostname = "digcl"
    digcl.vm.network :private_network, ip: "192.168.1.41", virtualbox__intnet: "dignet"
    digcl.vm.network :forwarded_port, guest: 22, guest_ip: "0.0.0.0", host: 2222, host_ip: "127.0.0.1", id: "ssh"
  end
  # VirtualBox独自設定
  config.vm.provider "virtualbox" do |vb|
    # メモリ
    vb.memory = "768"
    # CPU
    vb.cpus = 1
    # サスペンド復帰時に時刻をホストと同期
    vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
  end
  config.vm.provision "shell", inline: <<-EOT
    # タイムゾーン設定
    rm /etc/localtime
    ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
    # ロケール変更
#    echo LANG="ja_JP.utf8"           >  /etc/sysconfig/i18n
#    echo SYSFONT="latarcyrheb-sun16" >> /etc/sysconfig/i18n
    # manインストール
    yum -y install man man-pages
#    yum -y install man man-pages-ja
    # ツール群インストール
    yum -y install telnet nkf ftp unzip
    # カーネルアップデート (Vagrantで共有フォルダマウントのため)
    yum -y update kernel
    # NTPサーバ設定
    yum -y install ntp
    cd /etc
    mv ntp.conf ntp.conf.org
    sed 's|\\(^server .*$\\)|#\\1|' ntp.conf.org >  ntp.conf
    echo                                         >> ntp.conf
    echo 'server ntp.nict.jp'                    >> ntp.conf
    echo 'server ntp1.jst.mfeed.ad.jp'           >> ntp.conf
    echo 'server ntp2.jst.mfeed.ad.jp'           >> ntp.conf
    echo 'server ntp3.jst.mfeed.ad.jp'           >> ntp.conf
    service ntpd start
    chkconfig ntpd on
    # OracleJDKインストール
    wget -nv --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u152-b16/aa0333dd3019491ca4f6ddbe78cdb6d0/jdk-8u152-linux-x64.rpm
    rpm -ivh jdk-8u152-linux-x64.rpm
    echo 'export JAVA_HOME=/usr/java/default' >> /etc/profile.d/jdk.sh
    rm -f jdk-8u152-linux-x64.rpm
    # Digdagインストール
    wget -nv https://dl.digdag.io/digdag-latest
    mv digdag-latest /usr/local/bin/digdag
    chmod +x /usr/local/bin/digdag
    # td-agentインストール
    curl --tlsv1.2 -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh
    # Embulkインストール
    wget -nv http://dl.embulk.org/embulk-latest.jar
    mv -f embulk-latest.jar /usr/local/bin/embulk
    chmod +x /usr/local/bin/embulk
    # Gitインストール
    yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker
    cd /usr/local/src
    GIT_VERSION=2.14.1
    wget -nv https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.gz
    tar xzf git-${GIT_VERSION}.tar.gz
    rm -f   git-${GIT_VERSION}.tar.gz
    cd      git-${GIT_VERSION}
    make prefix=/usr/local install
    # Gitのmanインストール
#    yum -y install asciidoc xmlto epel-release
#    yum -y install docbook2X docbook-utils
#    ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
#    make prefix=/usr/local install-doc install-html install-info
    mkdir man
    cd man
    wget https://www.kernel.org/pub/software/scm/git/git-manpages-${GIT_VERSION}.tar.gz
    tar xzf git-manpages-${GIT_VERSION}.tar.gz
    rm -f   git-manpages-${GIT_VERSION}.tar.gz
    cp -r * /usr/local/share/man
    # sudoersのsecure_pathに/usr/local/binが含まれていないので一時的にPATHに追加(gitを使用するため)
    export PATH=/usr/local/bin:${PATH}
    # Rubyインストール
    RUBY_VERSION=2.3.4
    yum -y install readline-devel
    git clone git://github.com/rbenv/rbenv.git /usr/local/rbenv
    echo 'export RBENV_ROOT="/usr/local/rbenv"'     >  /etc/profile.d/rbenv.sh
    echo 'export PATH="${RBENV_ROOT}/bin:${PATH}"'  >> /etc/profile.d/rbenv.sh
    echo 'eval "$(rbenv init -)"'                   >> /etc/profile.d/rbenv.sh
    source                                             /etc/profile.d/rbenv.sh 
    git clone git://github.com/rbenv/ruby-build.git ${RBENV_ROOT}/plugins/ruby-build
    rbenv install ${RUBY_VERSION}
    rbenv global  ${RUBY_VERSION}
    cp -r ${RBENV_ROOT}/versions/${RUBY_VERSION}/share/man/* /usr/local/share/man
    # Rubyライブラリインストール
    gem install td
    # Gradleインストール
    GRADLE_VERSION=3.5
    wget -nv https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
    unzip -o gradle-${GRADLE_VERSION}-all.zip -d /opt/gradle
    rm -f gradle-${GRADLE_VERSION}-all.zip
    rm -f /opt/gradle/latest
    ln -s /opt/gradle/gradle-${GRADLE_VERSION} /opt/gradle/latest
    echo 'export GRADLE_HOME=/opt/gradle/latest' >  /etc/profile.d/gradle.sh
    echo 'export PATH=$PATH:$GRADLE_HOME/bin'    >> /etc/profile.d/gradle.sh
    # digsvにあるNFS共有ディレクトリと同じディレクトリを作成
    mkdir -p                 /export/home
    chown -R vagrant.vagrant /export/home
  EOT
  config.vm.provision "shell", privileged: false, inline: <<-EOT
    # Gitユーザ設定
    git config --global user.name  '<Gitユーザ>'
    git config --global user.email '<Gitメールアドレス>'
    # GitBucket認証設定
    echo 'machine  <GitBucketマシン>' >  ~/.netrc
    echo 'login    <Gitユーザ>'       >> ~/.netrc
    echo 'password <Gitパスワード>'   >> ~/.netrc
    chmod 600                             ~/.netrc
    # 本案件のリポジトリをクローン
    git clone https://<GitBucketマシン>/gitbucket/git/<Gitユーザ>/xxx1.git
    git clone https://<GitBucketマシン>/gitbucket/git/<Gitユーザ>/xxx2.git
    # Digdagサーバ接続設定
    mkdir -p ~/.config/digdag
    echo ' client.http.endpoint = http://192.168.1.21:65432/' >  ~/.config/digdag/config
    echo '#client.http.endpoint = http://192.168.1.22:65432/' >> ~/.config/digdag/config
    # TreasureData接続設定
    mkdir                                         ~/.td
    echo '[account]'                           >  ~/.td/td.conf
    echo 'user     = <TDユーザ>'              >> ~/.td/td.conf
    echo 'apikey   = <APIキー>'               >> ~/.td/td.conf
    echo 'endpoint = https://<エンドポイント>' >> ~/.td/td.conf
    # Embulkプラグインインストール
    embulk gem install embulk-input-td embulk-output-td embulk-input-sftp embulk-output-sftp embulk-filter-timestamp_format embulk-filter-column embulk-filter-stdout
    # vi全角文字編集設定
    echo 'set ambiwidth=double' > ~/.vimrc
  EOT
end

ユーザ名とかメアドとかパスワードとかAPIキーとか書いてるので人に渡すときにはその辺をマスキングしてから渡すこと

GradleのインストールはJava開発あり時のみ必要