Skip to content

Commit 61d38f6

Browse files
Build images in GitHub Actions (#3)
1 parent 7877cb0 commit 61d38f6

37 files changed

+902
-84
lines changed

.github/workflows/images.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Images
2+
on:
3+
push:
4+
branches: [master]
5+
6+
jobs:
7+
build-and-push:
8+
name: Build and push all images
9+
runs-on: ubuntu-18.04
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: docker://docker.io/errordeveloper/image-maker:2831b3fa8bc8a1412ed8eb59b158a123fe0459ef
13+
name: Register binfmt from multi-platform builds
14+
with:
15+
entrypoint: docker
16+
args: run --privileged linuxkit/binfmt:5d33e7346e79f9c13a73c6952669e47a53b063d4
17+
- uses: docker://docker.io/errordeveloper/image-maker:2831b3fa8bc8a1412ed8eb59b158a123fe0459ef
18+
name: Run make lint
19+
with:
20+
entrypoint: make
21+
args: lint
22+
- uses: docker://docker.io/errordeveloper/image-maker:2831b3fa8bc8a1412ed8eb59b158a123fe0459ef
23+
name: Run make maker-image
24+
env:
25+
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
26+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
27+
with:
28+
entrypoint: make
29+
args: maker-image PUSH=true
30+
- uses: docker://docker.io/errordeveloper/image-maker:2831b3fa8bc8a1412ed8eb59b158a123fe0459ef
31+
name: Run make compilers-image
32+
env:
33+
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
34+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
35+
with:
36+
entrypoint: make
37+
args: compilers-image PUSH=true
38+
- uses: docker://docker.io/errordeveloper/image-maker:2831b3fa8bc8a1412ed8eb59b158a123fe0459ef
39+
name: Run make bpftool-image
40+
env:
41+
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
42+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
43+
with:
44+
entrypoint: make
45+
args: bpftool-image PUSH=true
46+
- uses: docker://docker.io/errordeveloper/image-maker:2831b3fa8bc8a1412ed8eb59b158a123fe0459ef
47+
name: Run make iproute2-image
48+
env:
49+
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
50+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
51+
with:
52+
entrypoint: make
53+
args: iproute2-image PUSH=true
54+
- uses: docker://docker.io/errordeveloper/image-maker:2831b3fa8bc8a1412ed8eb59b158a123fe0459ef
55+
name: Run make llvm-image
56+
env:
57+
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
58+
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
59+
with:
60+
entrypoint: make
61+
args: llvm-image PUSH=true

.github/workflows/pr-checks.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: PR Check
2+
on: [pull_request,push]
3+
4+
jobs:
5+
lint:
6+
name: Run static checks
7+
runs-on: ubuntu-18.04
8+
steps:
9+
- uses: actions/checkout@v1
10+
- uses: docker://docker.io/cilium/image-maker:2831b3fa8bc8a1412ed8eb59b158a123fe0459ef
11+
name: Run make lint
12+
with:
13+
entrypoint: make
14+
args: lint

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.buildx_builder
2+
.buildx

.hadolint.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ignored:
2+
# it cannot parse `FROM ${BASE_IMAGE}`
3+
- DL3006
4+
# alpine doesn't keep old versions around, so we cannot rely on package pinning
5+
- DL3018
6+
# this one just needs to be set, but since `FROM ${BASE_IMAGE}` cannot be parse,
7+
# there isn't a way to leverage this feature anyway
8+
allowedRegistries: []

Dockerfile.bpftool

Lines changed: 0 additions & 26 deletions
This file was deleted.

Dockerfile.iproute2

Lines changed: 0 additions & 27 deletions
This file was deleted.

Dockerfile.llvm

Lines changed: 0 additions & 31 deletions
This file was deleted.

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2020 Authors of Cilium. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2020 Authors of Cilium
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
REGISTRY_PREFIX ?= docker.io/cilium
5+
PUSH ?= false
6+
7+
OUTPUT := "type=docker"
8+
ifeq ($(PUSH),true)
9+
OUTPUT := "type=registry,push=true"
10+
endif
11+
12+
all-images: lint maker-image update-maker-image compilers-image update-compilers-image bpftool-image iproute2-image llvm-image
13+
14+
lint:
15+
scripts/lint.sh
16+
17+
.buildx_builder:
18+
mkdir -p .buildx
19+
docker buildx create --platform linux/amd64,linux/arm64 > $@
20+
21+
maker-image: .buildx_builder
22+
scripts/build-image.sh $(REGISTRY_PREFIX)/image-maker images/maker linux/amd64 $(OUTPUT) "$$(cat .buildx_builder)"
23+
24+
update-maker-image:
25+
scripts/update-maker-image.sh $(REGISTRY_PREFIX)
26+
27+
compilers-image: .buildx_builder
28+
scripts/build-image.sh $(REGISTRY_PREFIX)/image-compilers images/compilers linux/amd64 $(OUTPUT) "$$(cat .buildx_builder)"
29+
30+
update-compilers-image:
31+
scripts/update-compilers-image.sh $(REGISTRY_PREFIX)
32+
33+
bpftool-image: .buildx_builder
34+
scripts/build-image.sh $(REGISTRY_PREFIX)/bpftool images/bpftool linux/amd64,linux/arm64 $(OUTPUT) "$$(cat .buildx_builder)"
35+
36+
iproute2-image: .buildx_builder
37+
scripts/build-image.sh $(REGISTRY_PREFIX)/iproute2 images/iproute2 linux/amd64,linux/arm64 $(OUTPUT) "$$(cat .buildx_builder)"
38+
39+
llvm-image: .buildx_builder
40+
scripts/build-image.sh $(REGISTRY_PREFIX)/llvm images/llvm linux/amd64,linux/arm64 $(OUTPUT) "$$(cat .buildx_builder)"

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Cilium Dependency Packaging
2+
3+
This repository contains build definitions for a number of images that are components of the official and development images of Cilium.
4+
5+
The builds are currently hosted in GitHub Actions, but can be ported to any other container-based CI system.
6+
7+
## Images
8+
9+
### [`images/maker`](images/maker/Dockerfile)
10+
11+
This image consists of core tools used for building all other images, which include `bash`, `make` and `docker` (with [`buildx`](https://github.com/docker/buildx))
12+
and [`crane`](https://github.com/google/go-containerregistry/blob/master/cmd/crane).
13+
This image enables using latest BuildKit features without depending on whatever Docker daemon/client CI host provides.
14+
Since `buildx` runs a BuildKit daemon inside a container, it's largely independent of what version of Docker daemon it runs on.
15+
16+
This image also includes a secure credentials helper - [`docker-credential-env`](http://github.com/errordeveloper/docker-credential-env),
17+
which prevents having to use `docker login` which stores a plain text token in `${DOCKER_CONFIG}/config.json`.
18+
19+
### [`images/compiler`](images/compilers/Dockerfile)
20+
21+
This image consists of compilers and libraries needed to build other images for `amd64` and `arm64`.
22+
23+
### [`images/bpftool`](images/bpftool/Dockerfile)
24+
25+
This image builds `bpftool` binary for `amd64` and `arm64` using a cross-compiler. The resulting image has only one file -
26+
`/bin/bpftool`, it is a proper multi-platform image. The binary is dynamically linked to Ubuntu 20.04 glibc and other dependencies.
27+
28+
This image is uses a recent version of `bpftool` from `bpf-next` Linux kernel tree.
29+
30+
### [`images/iproute2`](images/iproute2/Dockerfile)
31+
32+
This image builds `ip` and `tc` binaries for `amd64` and `arm64` using a cross-compiler. The resulting image has only two files -
33+
`/bin/ip` and `/bin/tc`, it is a proper multi-platform image. The binaries are dynamically linked to Ubuntu 20.04 glibc and other
34+
dependencies.
35+
36+
This image is uses [a fork of `iproute2`](https://github.com/cilium/iproute2), it has features that Cilium relies on.
37+
38+
### [`images/llvm`](images/llvm/Dockerfile)
39+
40+
This image builds `llc` and `clang` binaries for `amd64` and `arm64` using a cross-compiler. The resulting image has only two
41+
files - `/bin/llc` and `/bin/clang`, it is a proper multi-platform image. The binaries are dynamically linked to Ubuntu 20.04 glibc
42+
and other dependencies.
43+
44+
This image is a custom BPF-only distribution of LLVM.
45+
46+
## Usage
47+
48+
### Making changes
49+
50+
All images get automatic tags based on checked-in contents of image subdirectory. At any point in git history of a subdirectory
51+
there exists a unique [git tree object hash](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects), that is what's used for
52+
image tags.
53+
54+
As the result of this, following stands:
55+
56+
- image build definitions can be obtained with `git show <tag>`
57+
- image build is defined by contents of a directory
58+
- when changes are committed to image directory, new tag is generated
59+
- if there is a new tag, image is rebuilt and pushed with that new tag
60+
61+
This does not cater for reproducible builds, however it serves as basis for reliable builds, especially when following rules
62+
are also applied to any build definitions:
63+
64+
- all `FROM` statements use digests (use `scripts/get-image-digest.sh`)
65+
- any system packages are installed in a separate image that is references by a digests (that's how `images/compilers` is designed)
66+
- pining system packages can be quite laborious, especially because most of the time what you want is latest that the distribution offers,
67+
so what's much easier to let the package manager get the latest and then pin down the result by digest, so every time there is a change
68+
in underlying system packages, that is explicitly recorded by change of digest in each image that uses the base image
69+
70+
Be sure to use `make lint`, which will run [`shellcheck`](https://github.com/koalaman/shellcheck) and [`hadolint`](https://github.com/hadolint/hadolint).
71+
72+
For details of how this works, see the following:
73+
74+
- [`Makefile`](Makefile)
75+
- [`scripts/build-image.sh`](`scripts/build-image.sh`)
76+
- [`scripts/make-image-tag.sh`](scripts/make-image-tag.sh).
77+
- [`images/maker`](images/maker/Dockerfile)
78+
- [`images/compilers`](images/compilers/Dockerfile)
79+
80+
### Building Locally
81+
82+
One should be able to build images locally as long as they have Docker installed with [`buildx` plug-in](https://docs.docker.com/buildx/working-with-buildx/).
83+
84+
#### `images/{maker,compilers}`
85+
86+
When you have dependencies that need to be added to these image before using them in one of the other images, e.g. if you need to add a system
87+
library in `compilers` image that will be used for compiling something else, you should make a PR to update `compilers` first.
88+
However, that's only required for full integration, and you can build images locally if you prefer, you can also push them to your own Docker Hub
89+
account or whatever is your preferred registry.
90+
91+
When changes to these images are merged into master, builds should run and push new images to each of the registries.
92+
Once new images are out, a PR will be required to update all dependent images, please use the following commands to
93+
make updates and commit the resulting changes:
94+
95+
> NOTE: You can only use the `update-*-image` make targets when you are _not building localy_. For example, if you have built a new `compilers`
96+
> locally, or perahps even pushed it your Docker Hyb account, and you want to consume this new version to build new `llvm` image - you need to uptade
97+
> `images/llvm/Dockerfile` manually, as the `scripts/update-*-images.sh` is not capable of handling this.
98+
99+
- `make update-maker-image`
100+
- `make update-compilers-image`

0 commit comments

Comments
 (0)