Because the `WORKDIR` instruction specifies the home directory of the
`linuxbrew` user, there is no need to use absolute paths to reference
paths within the home directory, nor is there a need to call `cd` (this
is actually an anti-pattern [0]) to move into a subdirectory before
creating folders.
[0]: https://github.com/hadolint/hadolint/wiki/DL3003
These are no longer necessary due to the fact that the second `RUN`
instruction runs as the `linuxbrew` user (as of commit
77afe94446e78e688ebde7a5e2b1249fc0a4afcd).
This commit refactors the Dockerfile in order to resolve build errors
caused by attempting to execute `brew` commands as the root user. We
need to create the `/home/linuxbrew/.linuxbrew` folder prior to copying
the local directory into `/home/linuxbrew/.linuxbrew/Homebrew` (and
ensure the appropriate user owns it), as failing to do so will create
`/home/linuxbrew/.linuxbrew` with root user and group ownership, causing
the subsequent `mkdir` command called in the second `RUN` instruction to
fail.
closes#11802
- My editor converted some of these to spaces when I changed the lines
in the previous commit. We should be consistent, so I made all of them
into spaces.
- I suggested this for the contents of
[Linuxbrew/docker](https://github.com/Linuxbrew/docker) in
https://github.com/Linuxbrew/docker/issues/75. People agreed, and
Shaun asked me to do the same here.
- This adds a step to CI to lint the Dockerfile, via
[hadolint](https://github.com/hadolint/hadolint), on Ubuntu.
- The linting errors it surfaced on this Dockerfile were:
```
Dockerfile:4 DL3008 Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
Dockerfile:30 DL3020 Use COPY instead of ADD for files and folders
Dockerfile:32 DL3003 Use WORKDIR to switch to a directory
```
- [DL3008](https://github.com/hadolint/hadolint/wiki/DL3008) - pinning
versions in `apt-get install` - is at odds with what we recommend in the
normal Homebrew on Linux dependency install instructions. We don't
want the dependency management of having to check each of these
Dockerfiles periodically for the latest version numbers of packages
and have to update them. So I've disabled this lint.
- [DL3003](https://github.com/hadolint/hadolint/wiki/DL3003) - use
WORKDIR to `cd` - is disabled in this case due to [review
comments](https://github.com/Homebrew/brew/pull/7433/files#r415098255).