|
1 | 1 | # gitlab-fusion |
2 | 2 |
|
3 | | -A description of this package. |
| 3 | +`gitlab-fusion` is a [custom executor](https://docs.gitlab.com/13.4/runner/executors/custom.html) |
| 4 | +for GitLab Runner. This custom executor allows for the creation of a clean build |
| 5 | +environment from a known base state for every job executed by CI. |
| 6 | + |
| 7 | +This custom executor integrates well with |
| 8 | +[Console on Mac](https://support.apple.com/guide/console/log-messages-cnsl1012/mac) |
| 9 | +and the rest of the Swift ecosystem in an effort to provide easy development, |
| 10 | +debugging and integration on macOS. |
| 11 | + |
| 12 | +> ***NOTE***: All guests MUST have the VMware Fusion guest additions installed |
| 13 | +> and expose an SSH server. |
| 14 | +
|
| 15 | +## Dependencies |
| 16 | + |
| 17 | +macOS 10.13.x (High Sierra) or later is required as a host operating system. |
| 18 | +VMware Fusion host operating system support matrix can be |
| 19 | +found in [KB: 2088571 - Supported host operating systems for VMware Fusion and VMware Fusion Pro](https://kb.vmware.com/s/article/2088571). |
| 20 | +Fusion 11.5.x is known to work with this custom executor this is why macOS |
| 21 | +10.13.x (High Sierra) is the oldest supported host operating system. |
| 22 | + |
| 23 | +Additionally, `gitlab-fusion` has a runtime dependency on |
| 24 | +[libssh](https://www.libssh.org). There are multiple ways to install libssh but |
| 25 | +the recommended way is through [Homebrew](https://brew.sh). It is beyond the |
| 26 | +scope of this document to explain how to install libssh. Just ensure it is |
| 27 | +available on your runpath. |
| 28 | + |
| 29 | +## Build |
| 30 | + |
| 31 | +* Debug: `swift build` |
| 32 | +* Release: `swift build -c release` |
| 33 | + |
| 34 | +## Command Line Usage |
| 35 | + |
| 36 | +``` |
| 37 | +gitlab-fusion <subcommand> [OPTIONS] |
| 38 | +``` |
| 39 | + |
| 40 | +It is a goal that the tool itself has _adequate_ documentation in the help |
| 41 | +available at the point of usage. A good place to start is to simply run |
| 42 | +`gitlab-fusion --help` and see if the flag, option or argument is documented |
| 43 | +there. |
| 44 | + |
| 45 | +The `gitlab-fusion` tool provides 4 subcommands `config`, `prepare`, `run` and |
| 46 | +`cleanup`. These subcommands are designed to be called by the corresponding |
| 47 | +custom executor [stages](https://docs.gitlab.com/13.4/runner/executors/custom.html#stages) |
| 48 | +of the same names. |
| 49 | + |
| 50 | +Each subcommand accepts the configuration of the location of the VMware Fusion |
| 51 | +application and where the managed linked clones will be stored. |
| 52 | + |
| 53 | +* `--vmware-fusion`: Fully qualified path to the VMware Fusion application. |
| 54 | +(default: `/Applications/VMware Fusion.app`) |
| 55 | + |
| 56 | +* `--vm-images-path`: Fully qualified path to directory where cloned images are |
| 57 | +stored. (default: `$HOME/Virtual Machines.localized`) |
| 58 | + |
| 59 | +### Config |
| 60 | + |
| 61 | +This subcommand should be called by the |
| 62 | +[config_exec](https://docs.gitlab.com/runner/executors/custom.html#config) |
| 63 | +stage. |
| 64 | + |
| 65 | +This subcommand generates a properly formatted JSON string and serializes it to |
| 66 | +STDOUT. The keys of the JSON string are determined by the GitLab Runner custom |
| 67 | +executor API. While the values of the JSON are determined by the options |
| 68 | +provided by this step. |
| 69 | + |
| 70 | +See `gitlab-runner config --help` for more detail on the options. |
| 71 | + |
| 72 | +### Prepare |
| 73 | + |
| 74 | +This subcommand should be called by the |
| 75 | +[prepare_exec](https://docs.gitlab.com/runner/executors/custom.html#prepare) |
| 76 | +stage. |
| 77 | + |
| 78 | +This subcommand is responsible for creating the clean and isolated build |
| 79 | +environment that the job will use. |
| 80 | + |
| 81 | +To achieve the goal of a clean and isolated build environment this command must |
| 82 | +be provided the path to a base guest virtual machine. The `prepare` subcommand |
| 83 | +will then create a snapshot on base guest (if necessary) and then make a linked |
| 84 | +clone of the snapshot (if necessary). |
| 85 | + |
| 86 | +The linked clone will also have a snapshot created. This snapshots will |
| 87 | +represent the clean base state of any job. Finally, the subcommand will restore |
| 88 | +from the snapshot and start the cloned guest. |
| 89 | + |
| 90 | +Once the guest is started. The subcommand will wait for the guest to boot and |
| 91 | +provide its IP address via the VMware Guest Additions. Before signaling that |
| 92 | +the guest is working the prepare subcommand will also ensure that the SSH |
| 93 | +server is responding and that the supplied credentials work. |
| 94 | + |
| 95 | +See `gitlab-runner prepare --help` for more detail on the options and arguments. |
| 96 | + |
| 97 | +### Run |
| 98 | + |
| 99 | +This subcommand should be called by the |
| 100 | +[run_exec](https://docs.gitlab.com/runner/executors/custom.html#run) stage. |
| 101 | + |
| 102 | +The run subcommand is responsible for executing the scripts provided by GitLab |
| 103 | +Runner in the prepared guest virtual machine. |
| 104 | + |
| 105 | +Provided that the `prepare` stage has already been performed this command is |
| 106 | +safe to call multiple times. |
| 107 | + |
| 108 | +See `gitlab-runner run --help` for more detail on the options and arguments. |
| 109 | + |
| 110 | +### Cleanup |
| 111 | + |
| 112 | +This subcommand should be called by the |
| 113 | +[cleanup_exec](https://docs.gitlab.com/runner/executors/custom.html#cleanup) |
| 114 | +stage. |
| 115 | + |
| 116 | +The cleanup subcommand is responsible for stopping the cloned guest virtual |
| 117 | +machine. |
| 118 | + |
| 119 | +See `gitlab-runner cleanup --help` for more detail on the options and arguments. |
| 120 | + |
| 121 | +## Example Integration with GitLab Runner |
| 122 | + |
| 123 | +It is well beyond the scope of this project to explain how to install and configure |
| 124 | +a GitLab Runner. There are existing guides on how to do that. Please follow one |
| 125 | +of them. |
| 126 | + |
| 127 | +* [Install GitLab Runner](https://docs.gitlab.com/runner/install/) |
| 128 | +* [Install GitLab Runner](https://docs.gitlab.com/runner/#install-gitlab-runner) |
| 129 | +* [Registering runner](https://docs.gitlab.com/runner/register/index.html) |
| 130 | +* [The Custom executor](https://docs.gitlab.com/runner/executors/custom.html) |
| 131 | + |
| 132 | +At a high level, to use this executor one must install GitLab Runner. Then |
| 133 | +register a custom executor with GitLab Runner. Then finally configure the custom |
| 134 | +executor to use `gitlab-fusion`. |
| 135 | + |
| 136 | +That final step is where `gitlab-runner` needs to be told where the base VMware |
| 137 | +guest is located and be provided appropriate SSH credentials for that guest. |
| 138 | + |
| 139 | +The excerpt below assumes that the `gitlab-runner` executable is located at |
| 140 | +`/Users/buildbot/gitlab-fusion/.build/release/gitlab-fusion`. Additionally that |
| 141 | +the base guest virtual machine is located at |
| 142 | +`/Users/buildbot/base-macOS-10.15.7-19H2-xcode-12.0.0.vmwarevm/base-macOS-10.15.7-19H2-xcode-12.0.0.vmx`. |
| 143 | +Your path is likely different and should be updated accordingly. |
| 144 | + |
| 145 | +All of the arguments available to the `config_args`, `prepare_args`, `run_args` |
| 146 | +and `cleanup_args` should be located in the respective help of each subcommand. |
| 147 | + |
| 148 | +```toml |
| 149 | +... |
| 150 | + |
| 151 | +[[runners]] |
| 152 | + ... |
| 153 | + [runners.custom] |
| 154 | + config_exec = "/Users/buildbot/gitlab-fusion/.build/release/gitlab-fusion" |
| 155 | + config_args = [ |
| 156 | + "config" |
| 157 | + ] |
| 158 | + |
| 159 | + prepare_exec = "/Users/buildbot/gitlab-fusion/.build/release/gitlab-fusion" |
| 160 | + prepare_args = [ |
| 161 | + "prepare", |
| 162 | + "--ssh-username", "buildbot", |
| 163 | + "--ssh-key", "/Users/buildbot/Library/Application Support/me.lovelett.gitlab-fusion/id_ed25519", |
| 164 | + "/Users/buildbot/base-macOS-10.15.7-19H2-xcode-12.0.0.vmwarevm/base-macOS-10.15.7-19H2-xcode-12.0.0.vmx" |
| 165 | + ] |
| 166 | + |
| 167 | + run_exec = "/Users/buildbot/gitlab-fusion/.build/release/gitlab-fusion" |
| 168 | + run_args = [ |
| 169 | + "run", |
| 170 | + "--ssh-username", "buildbot", |
| 171 | + "--ssh-key", "/Users/buildbot/Library/Application Support/me.lovelett.gitlab-fusion/id_ed25519", |
| 172 | + "/Users/buildbot/base-macOS-10.15.7-19H2-xcode-12.0.0.vmwarevm/base-macOS-10.15.7-19H2-xcode-12.0.0.vmx" |
| 173 | + ] |
| 174 | + |
| 175 | + cleanup_exec = "/Users/buildbot/gitlab-fusion/.build/release/gitlab-fusion" |
| 176 | + cleanup_args = [ |
| 177 | + "cleanup", |
| 178 | + "/Users/buildbot/base-macOS-10.15.7-19H2-xcode-12.0.0.vmwarevm/base-macOS-10.15.7-19H2-xcode-12.0.0.vmx" |
| 179 | + ] |
| 180 | +``` |
0 commit comments