Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a better Docker build script + update Dockerfile #4222

Merged
merged 22 commits into from
Dec 8, 2018
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
45a89f9
Add a Docker build script
Oct 23, 2018
aa01835
Add usage and error messages
Oct 23, 2018
8936d19
Add -r to reads
vomindoraan Oct 23, 2018
6d3a2ff
Add keyboard:keymap form, improve script
vomindoraan Oct 24, 2018
852129f
Add target argument, change usage forms in script
vomindoraan Oct 24, 2018
6dd7b8d
Add check for more than 3 args in keyboard:keymap:target form
vomindoraan Oct 24, 2018
2fce454
Change Docker base image to debian, use community repo
vomindoraan Oct 24, 2018
688c70b
Change build command format to keyboard:keymap
vomindoraan Oct 24, 2018
b67b170
Call make directly in container run command
vomindoraan Oct 25, 2018
247969c
Simplify script, remove 3-arg form
vomindoraan Oct 25, 2018
6b8c947
Add COPY to Dockerfile so images are usable in and of themselves
vomindoraan Oct 25, 2018
b23fd4f
Add USB pass-through for Linux and docker-machine hosts
vomindoraan Oct 25, 2018
ee6bfbc
Read directly into variables instead of array
vomindoraan Oct 25, 2018
882fe20
Alphabetically sort dependencies in Dockerfile
Oct 25, 2018
ecdf90e
Set executable bit on util/docker_build.sh
Nov 2, 2018
ca1b367
Update Docker docs
vomindoraan Nov 4, 2018
04f92da
Add warning about Docker on Windows
vomindoraan Nov 4, 2018
7417d5d
Expand comment in docs
vomindoraan Nov 5, 2018
2da3e73
Check docker-machine exit code instead of string
vomindoraan Nov 9, 2018
bb3c51e
Only match --help with whole arguments
vomindoraan Nov 9, 2018
f4e7233
Make script POSIX-compliant
vomindoraan Nov 9, 2018
e115747
Convert script indentation to tabs
vomindoraan Nov 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
FROM debian:jessie
MAINTAINER Erik Dasque <[email protected]>
FROM debian

RUN apt-get update && apt-get install --no-install-recommends -y build-essential \
gcc \
unzip \
wget \
zip \
gcc-avr \
binutils-avr \
RUN apt-get update && apt-get install --no-install-recommends -y \
avr-libc \
avrdude \
binutils-arm-none-eabi \
binutils-avr \
build-essential \
dfu-programmer \
dfu-util \
gcc \
gcc-arm-none-eabi \
binutils-arm-none-eabi \
libnewlib-arm-none-eabi \
gcc-avr \
git \
libnewlib-arm-none-eabi \
software-properties-common \
avrdude \
unzip \
wget \
zip \
&& rm -rf /var/lib/apt/lists/*

ENV keyboard=ergodox
ENV subproject=ez
ENV keymap=default
ENV KEYBOARD=ergodox_ez
ENV KEYMAP=default
vomindoraan marked this conversation as resolved.
Show resolved Hide resolved

VOLUME /qmk_firmware
WORKDIR /qmk_firmware
COPY . .
vomindoraan marked this conversation as resolved.
Show resolved Hide resolved

VOLUME /qmk
WORKDIR /qmk
CMD make clean ; make keyboard=${keyboard} subproject=${subproject} keymap=${keymap}
CMD make $KEYBOARD:$KEYMAP
vomindoraan marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 14 additions & 11 deletions docs/getting_started_build_tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,27 @@ If you have trouble and want to ask for help, it is useful to generate a *Win_Ch

## Docker

If this is a bit complex for you, Docker might be the turn-key solution you need. After installing [Docker](https://www.docker.com/products/docker), run the following command at the root of the QMK folder to build a keyboard/keymap:

If this is a bit complex for you, Docker might be the turn-key solution you need. After installing [Docker CE](https://docs.docker.com/install/#supported-platforms), run the following command from the `qmk_firmware` directory to build a keyboard/keymap:
```bash
# You'll run this every time you want to build a keymap
# modify the keymap and keyboard assignment to compile what you want
# defaults are ergodox/default

docker run -e keymap=gwen -e keyboard=ergodox_ez --rm -v $('pwd'):/qmk:rw edasque/qmk_firmware
util/docker_build.sh keyboard:keymap
# For example: util/docker_build.sh ergodox_ez:steno
```
This will compile the targeted keyboard/keymap and leave the resulting `.hex` or `.bin` file in the QMK directory for you to flash. If `:keymap` is omitted, the `default` keymap is used. Note that the parameter format is the same as when building with `make`.

On Windows Docker seems to have issues with the VOLUME tag in Dockerfile, and `$('pwd')` won't print a Windows compliant path; use full path instead, like this:

You can also start the script without any parameters, in which case it will ask you to input the build parameters one by one:
```bash
docker run -e keymap=default -e keyboard=ergodox_ez --rm -v D:/Users/Sacapuces/Documents/Repositories/qmk:/qmk:rw edasque/qmk_firmware
util/docker_build.sh
# Reads parameters as input
vomindoraan marked this conversation as resolved.
Show resolved Hide resolved
```

There is also support for building _and_ flashing the keyboard straight from Docker by specifying the `target` as well:
```bash
util/docker_build.sh keyboard:keymap:target
# For example: util/docker_build.sh planck/rev6:default:dfu-util
```
If you're on Linux, this should work out of the box. On Windows and macOS, it requires [Docker Machine](http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos/) to be running. This is tedious to set up, so it's not recommended; use QMK Toolbox instead.

This will compile the targeted keyboard/keymap and leave it in your QMK directory for you to flash.
!> Docker for Windows requires [Hyper-V](https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v) to be enabled. This means that it cannot work on versions of Windows which don't have Hyper-V, such as Windows 7, Windows 8 and **Windows 10 Home**.

## Vagrant
If you have any problems building the firmware, you can try using a tool called Vagrant. It will set up a virtual computer with a known configuration that's ready-to-go for firmware building. OLKB does NOT host the files for this virtual computer. Details on how to set up Vagrant are in the [vagrant guide](getting_started_vagrant.md).
43 changes: 43 additions & 0 deletions util/docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

USAGE="Usage: $0 [keyboard[:keymap[:target]]]"

# Check preconditions
if [[ $* =~ "--help" ]]; then
echo "$USAGE"
exit 0
elif [[ $# -gt 1 ]]; then
echo "$USAGE" >&2
exit 1
elif [[ ! $(command -v docker) ]]; then
echo "Error: docker not found" >&2
echo "See https://docs.docker.com/install/#supported-platforms for installation instructions" >&2
exit 2
fi

# Determine arguments
if [[ $# -eq 0 ]]; then
read -rp "keyboard=" keyboard
[[ -n $keyboard ]] && read -rp "keymap=" keymap
[[ -n $keymap ]] && read -rp "target=" target
else
IFS=':' read -r keyboard keymap target x <<< "$1"
if [[ -n $x ]]; then
echo "$USAGE" >&2
exit 1
fi
fi
if [[ -n $target ]]; then
if [[ $(uname) == "Linux" || $(docker-machine active 2>/dev/null) ]]; then
usb_args="--privileged -v /dev/bus/usb:/dev/bus/usb"
else
echo "Error: target requires docker-machine to work on your platform" >&2
echo "See http://gw.tnode.com/docker/docker-machine-with-usb-support-on-windows-macos" >&2
exit 3
fi
fi
dir=$(pwd -W 2>/dev/null) || dir=$PWD # Use Windows path if on Windows

# Run container and build firmware
docker run --rm $usb_args -v "$dir":/qmk_firmware qmkfm/qmk_firmware \
make "$keyboard${keymap:+:$keymap}${target:+:$target}"