How to set up a mobile build server: step 1

  1. Introduction
  2. Server-side and client-side: (Optional) Create and configure an user on the build server
  3. Server-side: Install and configure the Android SDK
  4. Server-side: Install and configure cordova/ionic
  5. Client-side: Automate the build process

Server-side and client-side: (Optional) Create and configure an user on the build server

In this part, we will create a new user and configure ssh access. It’s an optional part because you can use an existing user.
I chose to separate the user because I think an user on a server must create for only one thing.
On top of that, as I said in the introduction, this method can be used for a C, LaTeX (or anything else) build server. An user for each build method is better in this case.

The user will be called android-sdk.

It’s the only part of this tutorial you need root access to create the user

Server-side: Create the user

Connect to the server and create a new user:

adduser android-sdk

You’ll be prompted for some informations such as a name, full name, and a password.

Client-side: create a ssh key and add it to the server

To avoid having to type the password each time we push, we create a ssh key and add it to the android-sdk’s authorized keys.

ssh-keygen -t rsa -f ~/.ssh/android-sdk
ssh-copy-id -i ~/.ssh/android-sdk android-sdk@[your-server]
Replace [your-server] by your server ip/alias/domain name. If you’re on Mac OS X, install ssh-copy-id with brew (brew install ssh-copy-id).
It’s recommended to have different ssh keys for each ssh user that is for github.com, bitbucket.com or other users on your server.

Client-side: add a rule in the ssh config

If you followed the previous command, you must add a rule in the ~/.ssh/config file to match the appropriate ssh key file.
Open with your favorite text editor (vim of course :D) and add these lines

Host build-server
Hostname [your-server-adress/ip/alias]
IdentityFile ~/.ssh/android-sdk
User android-sdk
See this excellent tutorial for more informations about the ssh config file. Don’t forget to change the user if you’re using another user. Same for the ssh key file.

The host will be used when you’ll clone the repository. You will use somethink like

git clone android-sdk@build-server:~/my_amazing_project.git

Scripts

As promised, I give you scripts to automate the configuration. There’re two scripts: one for the server and one on the client machine.

Server

We only need to create the user. I only add a variable to let you choose your user name.

## Change it if you want another username.
## Don't forget to change in the client script too.
USERNAME = android-sdk

## DON'T EDIT THESE FOLLOWING LINES
adduser $USERNAME
##

Client

We need to create a ssh key, add the ssh key to the server and modify the ssh config file. If you changed the username in the script server.

##### Change it if you want another username.
## Don't forget to change in the server script too.
## [default = android-sdk]
USERNAME = android-sdk

## Your server IP adress or alias
HOSTNAME = danny-willems.be

## The host name you want to use when you'll clone
## [default = build-server]
HOST = build-server

## SSH key name
## [default = android-sdk]
SSH_KEY_NAME = android-sdk

## DON'T EDIT THESE FOLLOWING LINES
## Create SSH keys
ssh-keygen -t rsa -f ~/.ssh/$SSH_KEY_NAME

## Copy to the server
ssh-copy-id -i ~/.ssh/$SSH_KEY_NAME $USERNAME@$HOSTNAME

## Modify the ssh config file
echo 'Host $HOSTn Hostname $HOSTNAMEn IdentityFile ~/.ssh/$SSH_KEY_NAMEn User $USERNAME' >> ~/.ssh/config

And now ?

OK, user configured. Now, let’s download and install the Android SDK in our new user environment.

Go to the second part

Leave a Reply

Your email address will not be published. Required fields are marked *