bbc_mc @ moddingメモ
Github_&_jenkins_buildsystem
最終更新:
bbc_mc
Github & jenkins buildsystem 勝手な和訳
以下のページの個人的和訳です。
http://www.minecraftforge.net/wiki/Github_%26_jenkins_buildsystem
現在、翻訳中です。(2013/09/13)
そのため、まだ以下の手順を実際に試してません。。。
なるたけ原文(英文)を併記しますので、意味不明・曖昧な場合は参照下さい。
目次
How-To
これは Minecraft Forge(もしくは関連するソフトウェア)の利用方法に関する、ハウツーガイド もしくはチュートリアルです。 このチュートリアルは完全ではありませんので、ご注意下さい!
GitHub と Jenkins
このチュートリアルでは、jenkins と github を使ったビルドシステムをどうやって作るか、を説明していきます。
状況によっていくらか違いがあるのですが、できる限りがんばります。
この方法はあなたのソースコードをインターネットに公開しますので、その結果誰かがあなたのコードをコピーして使っても私に怒らないでください。
この翻訳(和訳者註:英文)はオランダ語で書かれたものを翻訳したものですので、完全な翻訳となっているかは保証しかねる事をご承知ください。
In this tutorial I’m going to (try to) explain how to create a jenkins and github build system, this is different for each scenario, but I’ll do my best. This will put your source code on the internet, don’t be mad at me if someone copies it. Please note that is written on a Dutch system, not all translations might be 100% accurate.
事前準備:
-
root 権限を持っている Linux サーバ(VPS のサーバでもおそらく動きます。ただし、あなたはそのサーバにソフトウェアをインストールできる必要があります。)
- Linux サーバは windows に比べて 200% くらいは速い、という事をあなたは知っておくべきかもしれません
-
mod を作成するコンピュータ(windows ... ?)
- windows、と書きましたが、Linux や Mac でも構いません。但し、ここではそれらの環境特有の問題については述べません。
- ここで windows と書いた理由は、GitHub for Windows(PCアプリ) のほうが、コマンドラインよりも簡単だからです。
-
Linux サーバへのファイルアクセス
- FTP や samba
Needed for this: A linux server with root access (a VPS might work, but you need to be able to install software) As you should know a linux server is like 200% faster than a windows equivalent.... A (windows) computer on which you mod. I say windows, but with some common sense and research you should be able to adapt to linux and mac too, but I don’t provide the instructions for that. The reason for this is primarily “GitHub for windows”. >> Basic command line experience. I’m not going to explain how to use the terminal. Easy file acsess to the servers file system ((s)FTP or samba file server is recommended)
Modding 環境の準備 / Preparing your modding environment
a) 開発環境PCに必要なプログラム / Programs needed on your PC (the modding machine):
- Github for Windows
- プログラムを作成するエディタ (Notepad++とか)
- コピー/ペースト機能付きのターミナルクライアント (PuTTYとか)
Github for windows: [2] A note making program (Notepad++) A terminal client that supports copy/paste (PuTTY)
b) GitHub のセットアップ / Setting up GitHub
1."GitHub for Windows" を開く
あなたのリポジトリをここに作成する事をお勧めしますが、どの位置に保存するかが重要です。
もしデータドライブ(和訳者註:C(システムドライブ)以外、の意味か)にするのであれば、以下のような構成がお勧めです。
D:\modding\github\ModName
2.Mincraft の jar を取得(client / server) し、MCP と Forge をインストールする
3.あなたの mod を作成する
あなたの mod を区分された package にしておく事で、元々の Minecraft や Forge のコードとあなたのコードの見分けが付きやすくなります。
4.Minecraft や Forge のコードは、あなたのリポジトリに入れてはいけません!!!
".gitignore" で指定する事で、リポジトリに登録されなくすることができます。
/bin/* /conf/* /docs/* /eclipse/* /forge/* /jars/* /lib/* /logs/* /modsrc/* /reobf/* /runtime/* /temp/* /src/minecraft/* /src/minecraft_server/* /src/common/* !/src/common/dries007/ !/src/common/mcmod.info !/src/common/SP.png *.bat *.sh
Open github for windows.
I recommend creating your repo here.
The location you pick is important.
If you have a data drive, I recommend this structure: D:\modding\github\ModName
Now you download a fresh copy of Minecraft (both client and server) and install MCP and forge.
Hint for easier modding:
If you use eclipse, make a shortcut to it in your mods folder and open the properties of the shortcut, and
add “-data PathToEclipseFolder” to the target box so you get something like this:
“C:\ProgramEXEs\eclipse\eclipse.exe -data C:\Modding\GitHub\SimpleCore\eclipse”
This will open Eclipse in the right folder and make your life easier if you use more then 1 project.
Now you make your mod (or only a basic mod class so we can go on with the tutuorial ;-) )
Make the mod in a separate package so you can easily filter it out of the original Minecraft and Forge code.
Original code (both MC and Forge) CAN’T be in your repo!
That's where the .gitignore file comes in.
Open it with your notepad.
This is where you specify what doesn’t go in the repo, mine looks like this:
/bin/*
/conf/*
/docs/*
/eclipse/*
/forge/*
/jars/*
/lib/*
/logs/*
/modsrc/*
/reobf/*
/runtime/*
/temp/*
/src/minecraft/*
/src/minecraft_server/*
/src/common/*
!/src/common/dries007/
!/src/common/mcmod.info
!/src/common/SP.png
*.bat
*.sh
追加説明:
- ".gitignore" の記載は、リポジトリ登録時に無視するファイルのリストです。
- "!" から始まる記載の場合、「無視対象から外す」意味となります。
-
基本的に、あなたの mod のファイル以外をすべて無視するように設定する必要があります。
- あなたの mod が package で区分けされているのであれば、上位ディレクトリを無視した上で、mod 用ディレクトリを ! 付きで指定することができます。
- そうでなければ。。。ファイルをひとつづつ指定するしかないかもしれませんね!グッドラック!
Let me explain: All the lines in here make an ignore rule. Except the ones that start with ! You basically need to tell github to ignore all files except your mod. If your mod is in a seperate package, you can do this by ignoring /src/common, except for /src/common/MOD. If you didn’t, well good luck specifying all the files separately.
サーバーの準備 / Preparing your server
a) サーバーに必要なプログラム / Programs needed on your server:
- Jenkins (もし ubuntu を使うのであれば、以下をどうぞ http://pkg.jenkins-ci.org/debian/)
- Java / OpenSDK (http://openjdk.java.net/install/index.html )
- Wine (Ubuntu: http://www.winehq.org/download/ubuntu)
Jenkins (If you use ubuntu: http://pkg.jenkins-ci.org/debian/) Java / OpenSDK (http://openjdk.java.net/install/index.html ) Wine (Ubuntu: http://www.winehq.org/download/ubuntu)
b) Jenkins の設定 / Setting up Jenkins
-
Linuxサーバの 8080 ポートへお好きなブラウザでアクセスしてください(Chrome(ium)お勧め)
Jenkins の管理画面が見れたでしょうか?もし見えなければ、以下のコマンドで jenkins を開始して下さい。
"/etc/init.d/jenkins start"
- (管理画面が開いたら) "Manage Jenkins" を選択し、"Configure Global Security" の画面へ移動
-
以下の設定を確認
- “Enable security”
- “Jenkins's own user database”
- “Allow users to sign up”
- 設定/変更を保存
-
ユーザーを作成してログインし、"Global Security" が下記の通りか確認
- “Project-based Matrix Authorization Strategy”
-
"In the table" あなたの求める通りのユーザーを作成してください(おそらく管理者?)
- ここで、追加するユーザーの名前は、すでに存在しておりアクセス可能であるべきです。
- それ以外の場合、jenkins が影響を及ぼすことがあります
- 設定/変更を保存
-
やっと jenkins の設定を変更できます。
-
"manage" から "Plugin management" へ
- "Available" から "GitHub plugin" を選択
- チェックボックスにチェックをつけ、“Download now and install after restart”ボタンを押下
- ダウンロード画面で、"restart once no jobs are running" にチェック
-
"manage" から "Plugin management" へ
-
Jenkins の設定は完了
- 但し、まだ job は何も走っていない状態です。
Got to SERVERHOST:8080 in your favorite browser (should be chrome(ium))
This will give you the jenkins interface, if not, run “/etc/init.d/jenkins start”
Hit “Manage Jenkins” and “Configure Global Security”
Check the following options:
“Enable security”
“Jenkins's own user database”
“Allow users to sign up”
Save.
Now create a user and log in, then return to the global security section and check:
“Project-based Matrix Authorization Strategy”
In the table: Add a user you want to be (admin perhaps?)
This should be a username that exists and you have access to (like the one you just created).
Otherwise, jenkins will cheerfully and quickly cut off your ability to manage your own server.
For anonymous: "Read" in Overall
For Admin(User you just added): Check it all!
Save.
Now only you can edit Jenkins settings.
Now go to manage and then Plugin management.
In the “Available” tab you look for “GitHub plugin” (Currently right at the bottom of "External Site/Tool Integrations")
Click the check box, and hit “Download now and install after restart”.
In the download screen, check “restart once no jobs are running”
Now your jenkins is done, but no jobs are running just yet.
c) Jenkins Job の設定 / Setting up a Jenkins job.
- Jenkins にログインし、"New Job" を押下
- job に名称を登録し、1つ目のオプション "free-style software project" を選択
- "Enable project-based security" にチェックを入れ、現在のユーザーを追加
- "Anonymous" アカウントについては、Read/Workspace のみにチェック
- テキストボックス "Github Project" にて、Github 用のユーザーでアクセスするための URL を与える
- "buildの実行タイミング" については、"手動で指示がある場合のみ" を設定
- あなたのユーザー名を入力
- "ソースコード" セクションにて、Git を選択
- Github の URL を入力 ( Git:// みたいなやつ)
- "Github (のレポジトリ) に変更があった場合、ビルドする" を設定
-
ビルドステップのセクションで、"シェルスクリプトを実行" を追加
- 入力欄が開くので、以下のコマンドを登録
- ここで入力したスクリプトは、この後 Github に変更を push するたびに実行されます
rm -r builds mkdir builds python runtime/recompile.py python runtime/reobfuscate.py zip -r -9 $WORKSPACE/builds/SimpleCore_src_$BUILD_NUMBER src/common/dries007/* zip -r -9 $WORKSPACE/builds/SimpleCore_src_$BUILD_NUMBER src/common/mcmod.info zip -r -9 $WORKSPACE/builds/SimpleCore_src_$BUILD_NUMBER src/common/SP.png cd reobf/minecraft zip -r -D -9 $WORKSPACE/builds/SimpleCore_$BUILD_NUMBER * cd ../.. cd src/common zip -r -D -9 $WORKSPACE/builds/SimpleCore_$BUILD_NUMBER mcmod.info zip -r -D -9 $WORKSPACE/builds/SimpleCore_$BUILD_NUMBER SP.png cd ../..
In Jenkins, hit “New job”. Give a name and select the 1st option (Build a free-style software project) Now, you check: “Enable project-based security” and add your user, In the table, check everything behind your user. Behind Anonymous you check Read and Workspace. In the textbox “Github Project” you can give a URL to forward the user to Github. Check: “Promote builds when...”, “Only when manually approved”. In the box, put your username. In the source code section, select Git. In the box put the GitHub url (the Git:// one) Check: “Build when a change is pushed to GitHub”. In the building steps section: Add a step: “Execute a shell sript” This gives you a box. Ever time you push a change to GitHub this box will be executed.
ここで、上記のスクリプトの内容を説明していきます。
rm -r builds
古いビルドを削除します。
mkdir builds
新しいビルドのため、ディレクトリを作成し直します。
python runtime/recompile.py python runtime/reobfuscate.py
(わかるよね…?)
(※翻訳者注: mcp に同梱されているスクリプトを実行し、recompile と reobfuscate します)
zip -r -9 $WORKSPACE/builds/SimpleCore_src_$BUILD_NUMBER src/common/dries007/* zip -r -9 $WORKSPACE/builds/SimpleCore_src_$BUILD_NUMBER src/common/mcmod.info zip -r -9 $WORKSPACE/builds/SimpleCore_src_$BUILD_NUMBER src/common/SP.png
ここで行っている事は OPTIONAL(しなくても良い) です。
あなたのコードもまた github にある場合、この工程は不要です。
この工程では mod のファイルをビルドフォルダ内の zip に含めています。
OPTIONAL: (Your code is on github too, you don’t need this, but it copies the mod’s files to a zip in the builds folder)
cd reobf/minecraft zip -r -D -9 $WORKSPACE/builds/SimpleCore_$BUILD_NUMBER * cd ../.. cd src/common zip -r -D -9 $WORKSPACE/builds/SimpleCore_$BUILD_NUMBER mcmod.info zip -r -D -9 $WORKSPACE/builds/SimpleCore_$BUILD_NUMBER SP.png cd ../..
この部分では、mod のコード(.javaではなく .class等)(と、mcmod.info やロゴファイル) を zip へ含めています。
"SimpleCore" と書いている部分は、あなたの mod 名に書き換えて下さい。
This part copies the actual mod code (And the mcmod.info and my logo) to a zip. You should replace the “SimpleCore” with your mods name.
これらの作業結果が正しく動作するかどうかをテストするために、"Archiving the artifacts" という post-build action を追加します。
- 実行内容を記載する欄が表示されたら、以下を記入します。
builds/*.zip
==> builds/*.zip に関するエラーが表示されたとしても気にしないで下さい。
これは .zip フォルダがあなたの builds フォルダ内に無い事による警告表示であり、無視できます。
builds フォルダ内に .zip フォルダを配置することでこのエラーを回避できますが、どちらでもお好きな対策でかまいません。
Now we need to tell jenkins what the result of the hard work is by adding a post-build action: “Archiving the artifacts” (? translation....) In the little box you put this: “builds/*.zip” ==> If you get an error about “builds/*.zip” not meaning anything, it simply detects no .zip in your freshly made builds folder. You can make an empty .zip to evade that, but it doesn't matter. Now you have a configured job. Now you need to:
d) Build 環境の設定 / set up the building environment
- サーバへファイルを送受信する準備をして下さい。
-
/var/lib/jenkins/jobs フォルダへ移動します
- このフォルダにはあなたの mod 名のフォルダがあるはずです。このフォルダを開き、"workspace" という名前の新しいフォルダを作成して下さい。
- このフォルダ内に、あなたの modding フォルダの中身を "完全に全て" コピーして下さい。(例: D:\modding\github\ModName)
- workspace フォルダ内に builds フォルダがある事を必ず確認して下さい。(無い場合、ビルドが失敗します)。さて、お好きな飲み物を飲んできて下さい!コピーには時間がかかりますからね。
- コピーが終わったら、コピーしたファイルへのアクセス権限を jenkins に与えて下さい。 ターミナルからだと、以下の様な感じでしょう。
“chmod 777 /var/lib/jenkins/jobs/ModName -R”
forge や MC をアップデートする度に、上記の工程が必要となります。 jenkinsサーバと開発用PCで、forge や MC のバージョンを合わせておく必要があります。
さて、では build をテストしてみましょう。
- 手動でテストを行い、次に github との連携確認を行います。
- 手動で build を開始するには、jenkins の画面をブラウザで開いて job を選択し、"build now" ボタンを押下します。
- 結果を見るには、スタートさせた build の画面を開き、"コンソール" ボタンを押下します。
ログの末尾が「Finished: SUCCESS」で終わっていれば OK です。
最後に、github へ変更を push して、この結果が幸運によらないものである事を確認したら、パーティへ出かけましょう!
Open the way you send files back and forth with your server. Go (on the server) to /var/lib/jenkins/jobs/ In this folder there will be a folder with the name of your mod, open it and make a new folder here called “workspace”. In here you copy the entire(!) modding folder (D:\modding\github\ModName) Make sure there is a builds folder in the workspace or your build WILL FAIL. Go get a coffie/wathever you like, this might take a while. If its done you need to give jenkins permission to edit these files, do this by executing this command in terminal: “chmod 777 /var/lib/jenkins/jobs/ModName -R” Every time you update forge or MC this needs to happen, you need the same version of Forge and MC on your server and your PC. Now you can test a build (begin manually, after that do a test by pushing something in github) To manually start a build, go to jenkins (in browser) and click on your job, then hit “build now”. To see the result, go to the build you just started and hit “Console”. If your log ends with “Finished: SUCCESS”, try again (with github) to make sure it wasn’t luck and then go and throw a party.