Update building documentation for macOS (#4850)

Update building documentation for macOS

Problem: The k3s build scripts rely on GNU utils, like sed, so when
these scripts are run on a macOS environment they don't work as
expected.

Solution: Update the documentation to point out this scenario and
suggest the reader to spin up the Linux virtual machine defined on
the Vagrantfile within this project.

Signed-off-by: Jonnatan Jossemar Cordero <jonnatan.cordero@suse.com>
This commit is contained in:
Jossemar Cordero 2022-01-10 10:46:18 -06:00 committed by GitHub
parent 0144d23bb2
commit a3190bd146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,34 +1,49 @@
See the [release](https://github.com/k3s-io/k3s/releases/latest) page for pre-built releases.
**Note:** In case you are looking for the pre-built releases see the [release page](https://github.com/k3s-io/k3s/releases/latest).
## Build k3s from source
Before getting started, bear in mind that this repository includes all of Kubernetes history, so consider shallow cloning with (`--depth 1`) to speed up the process.
The clone will be much faster on this repo if you do
```bash
git clone --depth 1 https://github.com/rancher/k3s.git
```
This repo includes all of Kubernetes history so `--depth 1` will avoid most of that.
The k3s build process requires some autogenerated code and remote artifacts that are not checked in to version control. To prepare these resources for your build environment, run:
The k3s build process requires some autogenerated code and remote artifacts that are not checked in to version control.
To prepare these resources for your build environment, run:.
```bash
mkdir -p build/data && make download && make generate
```
To build the full release binary, you may now run `make`, which will create `./dist/artifacts/k3s`.
To build the binaries using without running linting (ie; if you have uncommitted changes):
To build the binaries using `make` without running linting (i.e.: if you have uncommitted changes):
```bash
SKIP_VALIDATE=true make
```
If you make any changes to go.mod and want to update the vendored modules, you should run the following before running `make`:
In case you make any changes to [go.mod](go.mod), you should run `go mod tidy` before running `make`.
### macOS considerations
The shell scripts in charge of the build process (the ones behind `make`) rely on GNU utils (i.e., `sed`), [which slightly differ on macOS](https://unix.stackexchange.com/a/79357). So, if you need to build k3s on a macOS environment, it is suggested to use the virtual machine defined on this repository's [Vagrantfile](Vagrantfile) to perform the tasks mentioned above.
To start the virtual machine, you will need [vagrant](https://www.vagrantup.com/) and [virtual box](https://www.virtualbox.org/) installed. Then prompt:
```bash
go mod vendor && go mod tidy
$ vagrant up
[... vm provisioning logs ...]
```
Kubernetes Source
-----------------
Once the virtual machine is provisioned, you should be able to ssh into it by doing `vagrant ssh` and perform any building task there:
The source code for Kubernetes is in `vendor/` and the location from which that is copied
is in `./go.mod`. Go to the referenced repo/tag and you'll find all the patches applied
to upstream Kubernetes.
```bash
$ vagrant ssh
[... ssh connection logs ..]
$ uname -a
Linux k3s-0-alpine312 5.11.0-41-generic
$ make
[... k3s build logs ...]
```
All the artifacts built within the VM will be synchronized with the directory where the `vagrant up` command was issued. For vagrant related commands please refer to [its cli documentation](https://www.vagrantup.com/docs/cli).