Skip to content

Commit

Permalink
capi/Makefile: support all Flatcar Container Linux channels
Browse files Browse the repository at this point in the history
This change adds support for building all channels of Flatcar
Container Linux. It also fixes an issue that made the build fail
when make was called directly instead of using the wrapper script
hack/image-build-flatcar.sh.
  • Loading branch information
t-lo authored and Dongsu Park committed Jun 8, 2020
1 parent 4cf25b5 commit 9e35bd9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 17 deletions.
11 changes: 9 additions & 2 deletions images/capi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,17 @@ PACKER_VAR_FILES := $(foreach f,$(abspath $(PACKER_VAR_FILES)),-var-file="$(f)"
## Platform and version combinations
## --------------------------------------
CENTOS_VERSIONS := centos-7
FLATCAR_VERSIONS := flatcar-stable
FLATCAR_VERSIONS := flatcar
PHOTON_VERSIONS := photon-3
UBUNTU_VERSIONS := ubuntu-1804 ubuntu-2004

# Set Flatcar Container Linux channel and version if not supplied
FLATCAR_CHANNEL ?= stable
FLATCAR_VERSION ?= $(shell hack/image-grok-latest-flatcar-version.sh $(FLATCAR_CHANNEL))

export FLATCAR_CHANNEL FLATCAR_VERSION


PLATFORMS_AND_VERSIONS := $(CENTOS_VERSIONS) \
$(FLATCAR_VERSIONS) \
$(PHOTON_VERSIONS) \
Expand All @@ -144,7 +151,7 @@ AZURE_BUILD_NAMES ?= azure-sig-ubuntu-1804 azure-vhd-ubuntu-1804

DO_BUILD_NAMES ?= do-default

QEMU_BUILD_NAMES ?= qemu-flatcar-stable qemu-ubuntu-1804
QEMU_BUILD_NAMES ?= qemu-flatcar qemu-ubuntu-1804

## --------------------------------------
## Dynamic build targets
Expand Down
34 changes: 33 additions & 1 deletion images/capi/README-flatcar.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@ Before running `packer build` command, please make sure the following:

## Usage

Provisioning and `kubeadm` initialisation is automated; start a new build with
Flatcar qemu images can be built using the Makefile; a convenience wrapper
script is provided to import the VM into vagrant and to initialise `kubeadm`.

### Convenience wrapper script

The wrapper script will call `make` (see below) to build an image,
import the image to vagrant, start a VM, and initialise `kubeadm`. After the
script concluded, users are all set up and can start interacting with kubernetes.

Start a new build with
```shell
./hack/image-build-flatcar.sh [<channel>] [<release-version>]
```

Flatcar Container Linux maintains four distinct
channels: `alpha`, `beta`, `stable`, and `edge`. For details please refer to
the [releases page](https://www.flatcar-linux.org/releases/).

The build script will default to the latest release of the `stable` channel.

After provisioning concluded the script will ask you to export flatcar channel
Expand All @@ -54,6 +67,25 @@ Kubernetes master is running at https://10.0.2.15:6443
KubeDNS is running at https://10.0.2.15:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
```
Get an overview of all images built by using `hack/boxes-flatcar.sh`. The
helper script will list all available images / VMs and will output environment
variables for convenient copy/paste.
### Makefile build
Make target `build-qemu-flatcar` will build a Flatcar Container Linux qemu
image. The make variables `FLATCAR_CHANNEL` and `FLATCAR_VERSION` can be set to
build specific releases. THe build will default to the current stable release.
Example usage:
```shell
$ make build-qemu-flatcar
or
$ make FLATCAR_CHANNEL=beta build-qemu-flatcar
or
$ make FLATCAR_CHANNEL=stable FLATCAR_VERSION=2512.2.0 build-qemu-flatcar
```
## Notes
* It needs to disable `gather_facts` in `images/capi/ansible/node.yml`, because it is not possible to run python before running setup tasks. Note that python is not installed by default in Flatcar.
Expand Down
26 changes: 12 additions & 14 deletions images/capi/hack/image-build-flatcar.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/sh -e

set -e
#set -u

usage() {
echo "Usage: $0 [<channel>] [<version>]"
echo " <channel> is one of: edge alpha beta stable (defaults to"
Expand All @@ -12,12 +9,13 @@ usage() {
}
# --

list_releases() {
check_for_release() {
channel="$1"
release="$2"
curl -s \
"https://www.flatcar-linux.org/releases-json/releases-$1.json" \
"https://www.flatcar-linux.org/releases-json/releases-$channel.json" \
| jq -r 'to_entries[] | "\(.key)"' \
| grep -v "current" \
| sort
| grep -q "$release"
}
# --

Expand All @@ -34,13 +32,14 @@ case $channel in
esac

release="$2"
if [ -z "$release" ] ; then
release=$(list_releases "$channel" | tail -n1)
else
list_releases "$channel" | grep -q "$release" || {
if [ -n "$release" ] ; then
check_for_release "$channel" "$release" || {
echo "Unknown release '$release' for channel '$channel'."
usage
exit 1; }
else
release="$(\
"$(dirname "$0")"/image-grok-latest-flatcar-version.sh "$channel")"
fi


Expand All @@ -53,9 +52,8 @@ export FLATCAR_CHANNEL FLATCAR_VERSION

rm -rf ./output/flatcar-"${channel}-${release}"-kube-*

# for now the Makefile only supports flatcar-stable.
# TODO: make it support multiple channels and versions
make build-qemu-flatcar-stable
make FLATCAR_CHANNEL="$channel" FLATCAR_VERSION="$release" \
build-qemu-flatcar

echo "#### Importing $channel-$release box to vagrant and setting up kubeadm."

Expand Down
10 changes: 10 additions & 0 deletions images/capi/hack/image-grok-latest-flatcar-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh -ue

channel="$1"

curl -s \
"https://www.flatcar-linux.org/releases-json/releases-$channel.json" \
| jq -r 'to_entries[] | "\(.key)"' \
| grep -v "current" \
| sort \
| tail -n1
File renamed without changes.

0 comments on commit 9e35bd9

Please sign in to comment.