├── README.md └── gitlab-runner ├── .gitignore ├── .env.example ├── add-windows-startup.sh ├── bootstrap.sh ├── Vagrantfile └── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Vagrant 2 | 3 | -------------------------------------------------------------------------------- /gitlab-runner/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | .vagrant 3 | 4 | -------------------------------------------------------------------------------- /gitlab-runner/.env.example: -------------------------------------------------------------------------------- 1 | URL="YOUR_GITLAB_URL" 2 | TOKEN="YOUR_TOKEN" 3 | #PROXY_HOST="YOUR_PROXY_HOST" 4 | #PROXY_PORT="YOUR_PROXY_PORT" 5 | #NO_PROXY_HOST="*.google.com|localhost" 6 | -------------------------------------------------------------------------------- /gitlab-runner/add-windows-startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | 5 | DIR=$(pwd -W) 6 | 7 | echo """ 8 | @echo off 9 | 10 | echo "Starting GitLab Runner ..." 11 | 12 | cd /D "$DIR" 13 | 14 | vagrant up --provision 15 | 16 | ::pause 17 | """ > gitlab-runner.bat 18 | 19 | mv gitlab-runner.bat "$HOME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/StartUp" 20 | -------------------------------------------------------------------------------- /gitlab-runner/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sed -i 's/\r//g' .env 4 | source /tmp/.env 5 | 6 | if [ ! -z "$PROXY_HOST" ]; then 7 | echo "systemProp.http.proxyHost=$PROXY_HOST 8 | systemProp.http.proxyPort=$PROXY_PORT 9 | systemProp.http.nonProxyHosts=$NO_PROXY_HOST 10 | systemProp.https.proxyHost=$PROXY_HOST 11 | systemProp.https.proxyPort=$PROXY_PORT 12 | systemProp.https.nonProxyHosts=$NO_PROXY_HOST" > /opt/cache/gradle/gradle.properties 13 | else 14 | echo "" > /opt/cache/gradle/gradle.properties 15 | fi 16 | 17 | if [ ! -z "$(cat /etc/gitlab-runner/config.toml |grep url\ =\ \"$URL\")" ]; then 18 | echo "Runner is already registered." 19 | exit 0 20 | fi 21 | 22 | sudo gitlab-runner register \ 23 | --non-interactive \ 24 | --url "$URL" \ 25 | --registration-token "$TOKEN" \ 26 | --executor "docker" \ 27 | --docker-image openjdk:8-jdk \ 28 | --description "$(hostname)" \ 29 | --tag-list "docker,runner" \ 30 | --run-untagged="true" \ 31 | --locked="false" \ 32 | --docker-privileged \ 33 | --env "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/sdk/emulator/:/opt/sdk/tools/bin:/opt/sdk/tools:/opt/sdk/platform-tools:/opt/ndk:/opt/sdk/cmake/3.10.2.4988404/bin" \ 34 | --env "ANDROID_HOME=/opt/sdk" \ 35 | --env "ANDROID_SDK=/opt/sdk" \ 36 | --env "ANDROID_NDK=/opt/ndk" \ 37 | --env "ANDROID_NDK_HOME=/opt/ndk" \ 38 | --env "GRADLE_USER_HOME=/opt/cache/gradle" \ 39 | --docker-volumes "/opt/ndk:/opt/ndk:rw" \ 40 | --docker-volumes "/opt/sdk:/opt/sdk:rw" \ 41 | --docker-volumes "/opt/cache/gradle:/opt/cache/gradle:rw" \ 42 | --docker-volumes "/dev/kvm:/dev/kvm:rw" \ 43 | --docker-network-mode "host" \ 44 | --docker-extra-hosts "" \ 45 | --access-level="not_protected" 46 | 47 | -------------------------------------------------------------------------------- /gitlab-runner/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # All Vagrant configuration is done below. The "2" in Vagrant.configure 5 | # configures the configuration version (we support older styles for 6 | # backwards compatibility). Please don't change it unless you know what 7 | # you're doing. 8 | Vagrant.configure("2") do |config| 9 | # The most common configuration options are documented and commented below. 10 | # For a complete reference, please see the online documentation at 11 | # https://docs.vagrantup.com. 12 | 13 | # Every Vagrant development environment requires a box. You can search for 14 | # boxes at https://vagrantcloud.com/search. 15 | config.vm.box = "xdtianyu/gitlab-runner" 16 | # config.vm.box_url = ["https://YOUR_LAN_HOSTING/gitlab-runner.box"] 17 | 18 | config.vm.network :forwarded_port, guest: 22, host: 2322, id: "ssh" 19 | 20 | config.vm.provider 'virtualbox' do |vb| 21 | vb.customize ['modifyvm', :id, '--cableconnected1', 'on'] 22 | end 23 | 24 | config.vm.hostname = "#{`hostname`[0..-2]}-runner" 25 | 26 | # Disable automatic box update checking. If you disable this, then 27 | # boxes will only be checked for updates when the user runs 28 | # `vagrant box outdated`. This is not recommended. 29 | # config.vm.box_check_update = false 30 | 31 | # Create a forwarded port mapping which allows access to a specific port 32 | # within the machine from a port on the host machine. In the example below, 33 | # accessing "localhost:8080" will access port 80 on the guest machine. 34 | # NOTE: This will enable public access to the opened port 35 | # config.vm.network "forwarded_port", guest: 80, host: 8080 36 | 37 | # Create a forwarded port mapping which allows access to a specific port 38 | # within the machine from a port on the host machine and only allow access 39 | # via 127.0.0.1 to disable public access 40 | # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" 41 | 42 | # Create a private network, which allows host-only access to the machine 43 | # using a specific IP. 44 | # config.vm.network "private_network", ip: "192.168.33.10" 45 | 46 | # Create a public network, which generally matched to bridged network. 47 | # Bridged networks make the machine appear as another physical device on 48 | # your network. 49 | # config.vm.network "public_network" 50 | 51 | # Share an additional folder to the guest VM. The first argument is 52 | # the path on the host to the actual folder. The second argument is 53 | # the path on the guest to mount the folder. And the optional third 54 | # argument is a set of non-required options. 55 | # config.vm.synced_folder "../data", "/vagrant_data" 56 | 57 | # Provider-specific configuration so you can fine-tune various 58 | # backing providers for Vagrant. These expose provider-specific options. 59 | # Example for VirtualBox: 60 | # 61 | # config.vm.provider "virtualbox" do |vb| 62 | # # Display the VirtualBox GUI when booting the machine 63 | # vb.gui = true 64 | # 65 | # # Customize the amount of memory on the VM: 66 | # vb.memory = "1024" 67 | # end 68 | # 69 | # View the documentation for the provider you are using for more 70 | # information on available options. 71 | 72 | # Enable provisioning with a shell script. Additional provisioners such as 73 | # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the 74 | # documentation for more information about their specific syntax and use. 75 | 76 | config.vm.provision "shell", inline: <<-SHELL 77 | echo "Boot Completed." 78 | SHELL 79 | 80 | config.vm.provision :file do |file| 81 | file.source = ".env" 82 | file.destination = "/tmp/.env" 83 | end 84 | 85 | config.vm.provision "bootstrap", 86 | type: "shell", 87 | path: "bootstrap.sh" 88 | 89 | config.vm.synced_folder ".", "/vagrant", disabled: true 90 | end 91 | -------------------------------------------------------------------------------- /gitlab-runner/README.md: -------------------------------------------------------------------------------- 1 | # Vagrant Gitlab Runner for Android projects 2 | 3 | [中文:(Android 工程的 Vagrant Gitlab Runner)](https://busy.im/post/vagrant-gitlab-runner-for-android/) 4 | 5 | This vagrant box has included Android sdk and Android ndk inside, gitlab runner will **be registered after the first run** of `bootstrap.sh` script. 6 | 7 | ## Usage 8 | 9 | 1. Install Vagrant and VirtualBox, for Windows users, please upgrade PowerShell to 5.1. 10 | 11 | 2. Checkout this repo and copy `.env.example` file to `.env`, then modify environment variables: 12 | 13 | ``` 14 | URL="YOUR_GITLAB_URL" 15 | TOKEN="YOUR_TOKEN" 16 | PROXY_HOST="YOUR_PROXY_HOST" 17 | PROXY_PORT="YOUR_PROXY_PORT" 18 | ``` 19 | 20 | Set `PROXY_HOST` and `PROXY_PORT` to empty if you are not using proxy. 21 | 22 | 3. Run the following commands to get start: 23 | 24 | ``` 25 | vagrant up --provision 26 | ``` 27 | 28 | ## Shutdown the vm 29 | 30 | Run the following command to shutdown gitlab runner virtual machine 31 | 32 | ``` 33 | vagrant halt 34 | ``` 35 | 36 | You can always boot the vm using `vagrant up --provision`. 37 | 38 | ## Destroy 39 | 40 | Run the following commands to destroy gitlab runner virtual machine 41 | 42 | ``` 43 | vagrant destroy 44 | ``` 45 | 46 | And then remove the dead runner from gitlab. 47 | 48 | ## Hostname 49 | 50 | Virtual machine's hostname is set automatically based on host's name, it's set in `Vagrantfile` by the following line: 51 | 52 | ``` 53 | config.vm.hostname = "#{`hostname`[0..-2]}-runner" 54 | ``` 55 | 56 | For example, if your host machine's name is `Peter-Desktop`, the client virtual machine's name will be `Peter-Desktop-runner`. And the gitlab runner's name will be the same as the hostname of vm, This is very useful if multiple vagrant runners are running for same gitlab instance. 57 | 58 | ## Slow speed 59 | 60 | You can download the vm box file directly with your favorite Download Manager from the following link: 61 | 62 | [https://vagrantcloud.com/xdtianyu/boxes/gitlab-runner/versions/1.0.0/providers/virtualbox.box](https://vagrantcloud.com/xdtianyu/boxes/gitlab-runner/versions/1.0.0/providers/virtualbox.box) 63 | 64 | And then add box file to your vagrant box list by the following command: 65 | 66 | ``` 67 | vagrant box add xdtianyu/gitlab-runner gitlab-runner.box 68 | ``` 69 | 70 | You can also host the box file at your LAN server, and then edit `Vagrantfile` and modify the following line: 71 | 72 | ``` 73 | # config.vm.box_url = ["https://YOUR_LAN_HOSTING/gitlab-runner.box"] 74 | ``` 75 | For example, if you host this box file at `http://10.0.0.1:8080/gitlab-runner.box`, then update the config to: 76 | 77 | ``` 78 | config.vm.box_url = ["http://10.0.0.1:8080/gitlab-runner.box"] 79 | ``` 80 | Then distribute this repo with `.env` to your colleagues for quick setup, they can start the runner vm by running `vagrant up --provision` command. 81 | 82 | ## Login to vm runner 83 | 84 | Use the following command to login vm runner: 85 | 86 | ``` 87 | vagrant ssh 88 | ``` 89 | 90 | The default user is `vagrant` and the password for `vagrant` and `root` user is `vagrant`. You can run command with `sudo` without password. 91 | 92 | ## Start automatically after Windows restart 93 | 94 | You can run `bash add-windows-startup.sh` in `git-bash` to add a batch file `gitlab-runner.bat` in your startup directory. 95 | 96 | Or you can manually create `gitlab-runner.bat` file with the following content and save it in `%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup`. Please note that modify `D:/code/vagrant/gitlab-runner` to your own path. 97 | 98 | ```batch 99 | @echo off 100 | echo Starting GitLab Runner ... 101 | cd /D D:/code/vagrant/gitlab-runner 102 | vagrant up --provision 103 | ::pause 104 | ``` 105 | 106 | ## .gitlab-ci.yml example 107 | 108 | Check out project [xdtianyu/CallerInfo](https://github.com/xdtianyu/CallerInfo) 's `.gitlab-ci.yml` for more details. You can also config ndk build, unit test, android ui test with this vm runner. 109 | 110 | 111 | ## Project 112 | 113 | [https://github.com/xdtianyu/vagrant](https://github.com/xdtianyu/vagrant) 114 | 115 | ## License 116 | 117 | MIT 118 | --------------------------------------------------------------------------------