Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 13 additions & 9 deletions .github/workflows/build_and_push_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/[email protected]
- name: Build kubernetes-tools image
run: make build-image BUILD_TAG=${{ inputs.build_tag }}
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Buildx
id: buildx
uses: docker/[email protected]
- name: Show Buildx platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push kubernetes-tools image to Docker Hub
run: make push-image BUILD_TAG=${{ inputs.build_tag }}
- name: Push kubernetes-tools image build cache to Docker Hub
# only push cache to Dockerhub as ECR doesn't support it yet
# https://github.com/aws/containers-roadmap/issues/876
- name: Build and push image build cache to Docker Hub
if: ${{ inputs.push_cache }}
run: make push-image-cache BUILD_TAG=${{ inputs.build_tag }}
run: make push-image-cache
- name: Build and push image to Docker Hub
run: make push-image BUILD_TAG=${{ inputs.build_tag }}
- name: Tag latest to point to most recent release in Docker Hub
if: ${{ inputs.tag_latest }}
run: make tag-release-image-with-latest BUILD_TAG=${{ inputs.build_tag }}
Expand All @@ -55,9 +62,6 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Build and push image to ECR
run: make push-image-ecr BUILD_TAG=${{ inputs.build_tag }}
- name: Push kubernetes-tools image build cache to ECR
if: ${{ inputs.push_cache }}
run: make push-image-cache-ecr BUILD_TAG=${{ inputs.build_tag }}
- name: Tag latest to point to most recent release in ECR
if: ${{ inputs.tag_latest }}
run: make tag-release-image-with-latest-ecr BUILD_TAG=${{ inputs.build_tag }}
43 changes: 8 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
BUILD_TAG ?= dev-latest
BUILD_GO_CACHE_TAG = go-build-cache
BUILD_RUST_CACHE_TAG = rust-build-cache
IMAGE_NAME = kubernetes-tools
DOCKERHUB_REPO_NAME = sumologic
REPO_URL = $(DOCKERHUB_REPO_NAME)/$(IMAGE_NAME)
Expand All @@ -13,31 +11,13 @@ mdl:
mdl --style .markdownlint/style.rb .

build-image:
DOCKER_BUILDKIT=1 docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from $(REPO_URL):$(BUILD_GO_CACHE_TAG) \
--target go-builder \
--tag $(IMAGE_NAME):$(BUILD_GO_CACHE_TAG) \
.
TAG=$(BUILD_TAG) docker buildx bake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a nice feature 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bit more text in the docker-bake.hcl file than the shell commands it replaced, but I like the separation of concerns.


DOCKER_BUILDKIT=1 docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from $(REPO_URL):$(BUILD_RUST_CACHE_TAG) \
--target rust-builder \
--tag $(IMAGE_NAME):$(BUILD_RUST_CACHE_TAG) \
.

DOCKER_BUILDKIT=1 docker build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from $(REPO_URL):$(BUILD_GO_CACHE_TAG) \
--cache-from $(REPO_URL):$(BUILD_RUST_CACHE_TAG) \
--cache-from $(REPO_URL):dev-latest \
--tag $(IMAGE_NAME):$(BUILD_TAG) \
.
build-image-multiplatform:
TAG=$(BUILD_TAG) docker buildx bake tools-multiplatform

tag-release-image-with-latest:
docker tag $(IMAGE_NAME):$(BUILD_TAG) $(REPO_URL):latest
docker push $(REPO_URL):latest
make push-image BUILD_TAG=latest

tag-release-image-with-latest-ecr:
make tag-release-image-with-latest REPO_URL=$(ECR_REPO_URL)
Expand All @@ -46,19 +26,12 @@ test-image:
./scripts/test-image.sh "$(IMAGE_NAME):$(BUILD_TAG)"

push-image-cache:
docker tag $(IMAGE_NAME):$(BUILD_GO_CACHE_TAG) $(REPO_URL):$(BUILD_GO_CACHE_TAG)
docker push $(REPO_URL):$(BUILD_GO_CACHE_TAG)
docker tag $(IMAGE_NAME):$(BUILD_RUST_CACHE_TAG) $(REPO_URL):$(BUILD_RUST_CACHE_TAG)
docker push $(REPO_URL):$(BUILD_RUST_CACHE_TAG)
docker tag $(IMAGE_NAME):$(BUILD_TAG) $(REPO_URL):dev-latest
docker push $(REPO_URL):dev-latest

push-image-cache-ecr:
make push-image-cache REPO_URL=$(ECR_REPO_URL)
# only push cache to Dockerhub as ECR doesn't support it yet
# https://github.com/aws/containers-roadmap/issues/876
docker buildx bake cache-multiplatform

push-image:
docker tag $(IMAGE_NAME):$(BUILD_TAG) $(REPO_URL):$(BUILD_TAG)
docker push $(REPO_URL):$(BUILD_TAG)
IMAGE=$(REPO_URL) TAG=$(BUILD_TAG) docker buildx bake tools-multiplatform --push

push-image-ecr:
make push-image REPO_URL=$(ECR_REPO_URL)
Expand Down
87 changes: 87 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
variable "IMAGE" {
default = "kubernetes-tools"
}

variable "TAG" {
default = "dev-latest"
}

variable "CACHE_IMAGE" {
default = "sumologic/kubernetes-tools"
}

variable "BUILD_GO_CACHE_TAG" {
default = "go-build-cache"
}

variable "BUILD_RUST_CACHE_TAG" {
default = "rust-build-cache"
}

variable "TOOLS_CACHE_TAG" {
default = "tools-build-cache"
}

target "multiplatform" {
platforms = ["linux/amd64", "linux/arm64"]
output = ["type=image"]
}

target "default" {
dockerfile = "Dockerfile"
tags = ["${IMAGE}:${TAG}"]
cache-from = [
"${CACHE_IMAGE}:${BUILD_GO_CACHE_TAG}",
"${CACHE_IMAGE}:${BUILD_RUST_CACHE_TAG}",
"${CACHE_IMAGE}:${TOOLS_CACHE_TAG}",
]
output = ["type=docker"]
platforms = ["linux/amd64"]
}

target "tools-multiplatform" {
inherits = ["default", "multiplatform"]
}

group "cache" {
targets = ["rust-cache", "go-cache", "tools-cache"]
}

target "rust-cache" {
dockerfile = "Dockerfile"
cache-from = [
"${CACHE_IMAGE}:${BUILD_RUST_CACHE_TAG}",
]
cache-to = ["${CACHE_IMAGE}:${BUILD_RUST_CACHE_TAG}"]
target = "rust-builder"
}

target "go-cache" {
dockerfile = "Dockerfile"
cache-from = [
"${CACHE_IMAGE}:${BUILD_GO_CACHE_TAG}",
]
cache-to = ["${CACHE_IMAGE}:${BUILD_GO_CACHE_TAG}"]
target = "go-builder"
}

target "tools-cache" {
inherits = ["default"]
cache-to = ["${CACHE_IMAGE}:${TOOLS_CACHE_TAG}"]
}

group "cache-multiplatform" {
targets = ["rust-cache-multiplatform", "go-cache-multiplatform", "tools-cache-multiplatform"]
}

target "rust-cache-multiplatform" {
inherits = ["rust-cache", "multiplatform"]
}

target "go-cache-multiplatform" {
inherits = ["go-cache", "multiplatform"]
}

target "tools-cache-multiplatform" {
inherits = ["tools-cache", "multiplatform"]
}