Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Gradle SSH Plugin
Search
Hidetake Iwata
June 20, 2014
Technology
0
260
Gradle SSH Plugin
わいわいGroovy ~ 教えてG*小ネタ大会!
https://jggug.doorkeeper.jp/events/11365
Hidetake Iwata
June 20, 2014
Tweet
Share
More Decks by Hidetake Iwata
See All by Hidetake Iwata
Rewrite Go error handling using AST transformation
int128
1
1.3k
Cluster AutoscalerをTerraformとHelmfileでデプロイしてPrometheusでモニタリングする / Deploy the Cluster Autoscaler with Terraform and Helmfile, Monitor with Prometheus
int128
3
1.7k
認証の仕組みとclient-go credential plugin / authentication and client-go credential plugin
int128
7
7.3k
CLIでOAuth/OIDCを快適に利用する
int128
0
810
AppEngine × Spring Boot × Kotlin
int128
0
96
いつものJIRA設定
int128
1
170
Swaggerのテンプレートを魔改造した話 / Customize Swagger Templates
int128
1
4.7k
本番環境のリリースを自動化した話
int128
0
730
Swagger × Spring Cloud
int128
0
86
Other Decks in Technology
See All in Technology
Share my, our lessons from the road to re:Invent
naospon
0
150
DevinでAI AWSエンジニア製造計画 序章 〜CDKを添えて〜/devin-load-to-aws-engineer
tomoki10
0
170
Pwned Labsのすゝめ
ken5scal
2
460
日経のデータベース事業とElasticsearch
hinatades
PRO
0
250
Change Managerを活用して本番環境へのセキュアなGUIアクセスを統制する / Control Secure GUI Access to the Production Environment with Change Manager
yuj1osm
0
100
Two Blades, One Journey: Engineering While Managing
ohbarye
4
2.2k
AWS Well-Architected Frameworkで学ぶAmazon ECSのセキュリティ対策
umekou
2
150
大規模アジャイルフレームワークから学ぶエンジニアマネジメントの本質
staka121
PRO
3
1.3k
エンジニア主導の企画立案を可能にする組織とは?
recruitengineers
PRO
1
150
【詳説】コンテンツ配信 システムの複数機能 基盤への拡張
hatena
0
270
30→150人のエンジニア組織拡大に伴うアジャイル文化を醸成する役割と取り組みの変化
nagata03
0
190
システム・ML活用を広げるdbtのデータモデリング / Expanding System & ML Use with dbt Modeling
i125
1
330
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
35
1.6k
Testing 201, or: Great Expectations
jmmastey
42
7.2k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
4 Signs Your Business is Dying
shpigford
182
22k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Git: the NoSQL Database
bkeepers
PRO
427
65k
How STYLIGHT went responsive
nonsquared
98
5.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Transcript
Gradle SSH Plugin @int128 #jggug
はじめに 5分ぐらいで Gradle SSH Pluginを紹介します。 http://gradle-ssh-plugin.github.io @int128 Groovy and Scala
Programmer Certified ScrumMaster
どうやって デプロイしてますか?
どうやってデプロイしてますか? アプリをサーバにデプロイする方法 ➔ 手順書 ➔ シェルスクリプト ➔ Capistrano ➔ Maven
➔ Ant ➔ Gradle
Gradleからデプロイできると 便利ですよね
Gradleからデプロイするメリット 使い慣れたツールでビルドからデプロイまでをシー ムレスに記述できます ビルドやデプロイの設定を一元管理することでメン テナンスの無駄がなくなります JavaVMさえ入っていればすぐにデプロイできます (Gradle Wrapperのおかげ)
Gradle SSH Pluginとは GradleでSSHを使うためのプラグイン ➔ Gradleとの統合 ➔ コマンド実行やファイル転送 ➔ 標準入出力とのインタラクション
➔ パスワード、公開鍵、ssh-agentによる認証 ➔ 踏み台サーバやプロキシを経由した接続
使用例1: アプリのデプロイ Gradleでビルドした成果物 (JARやWAR) をサー バに配置する例 1. ビルドしてWARファイルを生成 2. WebサーバにWARファイルを配置
3. プロセスを再起動
apply plugin: 'war' apply plugin: 'ssh' remotes { webServer {
host = '192.168.1.101' user = 'jenkins' } } task deploy(type: SshTask, dependsOn: war) { session(remotes.webServer) { put war.archivePath, '/webapps' execute 'sudo service tomcat restart' } } Webサーバを定義 WebサーバにWARをデプロイ WARファイルを配置し、Tomcatサービスを再起動 プラグインを適用 warタスクの後にdeployタスクを実行
例2: SSHオペレーションの自動化 ネットワーク機器 (Cisco Catalyst) から設定を取 得してファイルに保存する例 1. ネットワーク機器にSSHで接続 2.
特権モードに移行 3. パスワードを入力 4. 現在の設定を取得 5. 終了
task backupConfig(type: SshTask) { session(remotes.switch01) { file('config.txt').withWriter { writer ->
shell { interaction { when(partial: ~/.*>/) { standardInput << 'terminal length 0\n' standardInput << 'enable\n' when(partial: /Password: /) { standardInput << enablePassword << '\n' when(partial: ~/.*#/) { standardInput << 'show run\n' when(partial: ~/.*[#>]/) { standardInput << 'exit\n' } when(line: _) { line -> writer << line << '\n' } } } パスワードを入力 プロンプトが出現したらコマンドを入力 show runコマンドを入力 プロンプトが出現したらexitコマンドを入力 プロンプト以外の標準出力をファイルに保存 ネットワーク機器の設定を取得
まとめ Gradle SSH Pluginを使用することで、 使い慣れたGradleでビルドからデプロイまでを シームレスに実現できます デプロイだけでなく、SSHオペレーションの 自動化全般に使用できます
おまけ:アーキテクチャ プロダクト ➔ Groovy 1.8(Gradle 1.xに同梱) ➔ JSch テスト ➔
Spock ➔ Apache MINA SSHD server 受け入れテスト ➔ Travis CI ◆ localhostにSSH接続してテストを実行