Skip to content

Add release workflow #12

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

Merged
merged 8 commits into from
Jun 30, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
29 changes: 28 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your 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).