diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 6d8280a8..df439120 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-18.04 steps: - name: Checkout code - # actions/checkout@v2 + # actions/checkout@v2.0.0 uses: actions/checkout@722adc6 - name: Setup KinD # engineerd/setup-kind@v0.4.0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..6ac6dc72 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: Release +on: + push: + tags: + - "*" +jobs: + buildx: + name: Build & Push Multi Arch Images + runs-on: ubuntu-18.04 + steps: + - name: Checkout code + # actions/checkout@v2.0.0 + uses: actions/checkout@722adc6 + - name: Configure gcloud + # linkerd/linkerd2-action-gcloud@v1.0.1 + uses: linkerd/linkerd2-action-gcloud@308c4df + with: + cloud_sdk_service_account_key: ${{ secrets.CLOUD_SDK_SERVICE_ACCOUNT_KEY }} + gcp_project: ${{ secrets.GCP_PROJECT }} + gcp_zone: ${{ secrets.GCP_ZONE }} + - name: Set up Docker Buildx + # crazy-max/ghaction-docker-buildx@v3.1.0 + uses: crazy-max/ghaction-docker-buildx@373dafb + - name: Docker Buildx (build) + run: make images + - name: Docker Buildx (push) + run: make push + - name: Docker Check Manifest + run: make inspect-manifest diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index 327b4ec1..bd792d37 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -15,7 +15,7 @@ jobs: image: golang:1.13.4 steps: - name: Checkout code - # actions/checkout@v2 + # actions/checkout@v2.0.0 uses: actions/checkout@722adc6 - name: Lint # golangci/golangci-lint-action@v1.2.1 @@ -29,7 +29,7 @@ jobs: image: golang:1.13.4 steps: - name: Checkout code - # actions/checkout@v2 + # actions/checkout@v2.0.0 uses: actions/checkout@722adc6 - name: Format run: make fmt diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 9c399bcc..af35afa3 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -15,7 +15,7 @@ jobs: image: golang:1.13.4 steps: - name: Checkout code - # actions/checkout@v2 + # actions/checkout@v2.0.0 uses: actions/checkout@722adc6 - name: Run unit tests run: make test diff --git a/Dockerfile b/Dockerfile index 531fda50..f777c5bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,19 @@ ## compile proxy-init utility -FROM golang:1.12.9 as golang +FROM --platform=$BUILDPLATFORM golang:1.12.9 as golang WORKDIR /build + +# cache dependencies +COPY go.mod . +COPY go.sum . +RUN go mod download + +# build COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -o /out/linkerd2-proxy-init -mod=readonly -ldflags "-s -w" -v +ARG TARGETARCH +RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -o /out/linkerd2-proxy-init -mod=readonly -ldflags "-s -w" -v ## package runtime -FROM debian:stretch-20190812-slim +FROM --platform=$TARGETPLATFORM debian:stretch-20190812-slim RUN apt-get update \ && apt-get install -y --no-install-recommends \ iptables \ diff --git a/Makefile b/Makefile index e662b75e..bf107661 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ DOCKER_REGISTRY ?= gcr.io/linkerd-io REPO = $(DOCKER_REGISTRY)/proxy-init TESTER_REPO = buoyantio/iptables-tester +VERSION ?= $(shell git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD) +SUPPORTED_ARCHS = linux/amd64,linux/arm64,linux/arm/v7 +PUSH_IMAGE ?= false .DEFAULT_GOAL := help @@ -39,7 +42,7 @@ integration-test: image ## Perform integration test ############### .PHONY: image image: ## Build docker image for the project - docker build -t $(REPO):latest . + DOCKER_BUILDKIT=1 docker build -t $(REPO):latest . .PHONY: tester-image tester-image: ## Build docker image for the tester component @@ -49,3 +52,27 @@ tester-image: ## Build docker image for the tester component kind-load: image tester-image ## Load the required image to KinD cluster kind load docker-image $(REPO):latest kind load docker-image $(TESTER_REPO):v1 + +.PHONY: images +images: ## Build multi arch docker images for the project + docker buildx build \ + --platform $(SUPPORTED_ARCHS) \ + --output "type=image,push=$(PUSH_IMAGE)" \ + --tag $(REPO):$(VERSION) \ + --tag $(REPO):latest \ + . + +.PHONY: push +push: ## Push multi arch docker images to the registry + PUSH_IMAGE=true make images + +.PHONY: inspect-manifest +inspect-manifest: ## Check the resulting images supported architecture + docker run --rm mplatform/mquery $(REPO):$(VERSION) + docker run --rm mplatform/mquery $(REPO):latest + +.PHONY: builder +builder: ## Create the Buildx builder instance + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + docker buildx create --name=multiarch-builder --driver=docker-container --platform="$(SUPPORTED_ARCHS)" --use + docker buildx inspect multiarch-builder --bootstrap diff --git a/README.md b/README.md index f2ad46ed..f1f38a95 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,27 @@ Then run the tests with: ```bash make integration-test ``` + +# Build Multi-Architecture Docker Images with Buildx + +Please refer to [Docker Docs](https://docs.docker.com/buildx/working-with-buildx) to enable Buildx. + +Run `make images` to start build the images. + +Run `make push` to push the images into registry. +Registry repo can be configured with environment variable: + +```bash +DOCKER_REGISTRY= make push +``` + +In some local environments like Ubuntu, where the default Buildx builder uses the `docker` driver, the `make images` command might fail with the following error: + +```bash +$ make images +multiple platforms feature is currently not supported for docker driver. Please switch to a different driver (eg. "docker buildx create --use") +Makefile:57: recipe for target 'images' failed +make: *** [images] Error 1 +``` + +To fix this, you can create a new Buildx builder instance by running `make builder`. This command will create a builder that uses the `docker-container` driver that can build multi-platform images. For more information, see the Buildx builder [documentation](https://docs.docker.com/buildx/working-with-buildx/#work-with-builder-instances).