Skip to content

Commit 4f138dd

Browse files
committed
Support multi-arch
Signed-off-by: Ali Ariff <[email protected]>
1 parent f1a476f commit 4f138dd

File tree

4 files changed

+93
-31
lines changed

4 files changed

+93
-31
lines changed

Dockerfile-multi-arch

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ARG svc_name
2+
3+
# go build stage
4+
FROM --platform=$BUILDPLATFORM golang:1.15.0 as golang
5+
WORKDIR /emojivoto-build
6+
7+
# install protobuf
8+
RUN apt-get update && apt-get install -y protobuf-compiler
9+
RUN go get github.com/golang/protobuf/protoc-gen-go
10+
11+
# cache go dependencies
12+
COPY go.mod go.sum .
13+
RUN go mod download
14+
15+
# compile
16+
COPY . .
17+
ARG TARGETARCH
18+
ARG svc_name
19+
RUN GOARCH=$TARGETARCH make -C $svc_name clean protoc compile
20+
21+
# webpack stage
22+
FROM --platform=$BUILDPLATFORM node:14-buster as webpack-bundle
23+
WORKDIR /emojivoto-build
24+
COPY . .
25+
RUN make -C emojivoto-web clean webpack package-web
26+
27+
FROM golang as build-emojivoto-emoji-svc
28+
FROM golang as build-emojivoto-voting-svc
29+
FROM golang as build-emojivoto-web
30+
COPY --from=webpack-bundle /emojivoto-build/emojivoto-web/target/ /emojivoto-build/emojivoto-web/target/
31+
32+
FROM build-$svc_name as build
33+
34+
# runtime image
35+
FROM debian:bullseye
36+
RUN apt-get update \
37+
&& apt-get install -y --no-install-recommends \
38+
curl \
39+
dnsutils \
40+
iptables \
41+
jq \
42+
nghttp2 \
43+
&& rm -rf /var/lib/apt/lists/*
44+
45+
ARG svc_name
46+
COPY --from=build /emojivoto-build/$svc_name/target/ /usr/local/bin/
47+
48+
# ARG variables arent available for ENTRYPOINT
49+
ENV SVC_NAME $svc_name
50+
ENTRYPOINT cd /usr/local/bin && $SVC_NAME

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ voting-svc:
1818

1919
build: web emoji-svc voting-svc
2020

21+
multi-arch:
22+
$(MAKE) -C emojivoto-web build-multi-arch
23+
$(MAKE) -C emojivoto-emoji-svc build-multi-arch
24+
$(MAKE) -C emojivoto-voting-svc build-multi-arch
25+
2126
deploy-to-minikube:
2227
$(MAKE) -C emojivoto-web build-container
2328
$(MAKE) -C emojivoto-emoji-svc build-container

README.md

+34-31
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,35 @@ Deploy the application to Minikube using the Linkerd2 service mesh.
1919

2020
1. Install the `linkerd` CLI
2121

22-
```bash
23-
curl https://run.linkerd.io/install | sh
24-
```
22+
```bash
23+
curl https://run.linkerd.io/install | sh
24+
```
2525

2626
1. Install Linkerd2
2727

28-
```bash
29-
linkerd install | kubectl apply -f -
30-
```
28+
```bash
29+
linkerd install | kubectl apply -f -
30+
```
3131

3232
1. View the dashboard!
3333

34-
```bash
35-
linkerd dashboard
36-
```
34+
```bash
35+
linkerd dashboard
36+
```
3737

3838
1. Inject, Deploy, and Enjoy
3939

40-
```bash
41-
kubectl kustomize kustomize/deployment | \
42-
linkerd inject - | \
43-
kubectl apply -f -
44-
```
40+
```bash
41+
kubectl kustomize kustomize/deployment | \
42+
linkerd inject - | \
43+
kubectl apply -f -
44+
```
4545

4646
1. Use the app!
4747

48-
```bash
49-
minikube -n emojivoto service web-svc
50-
```
48+
```bash
49+
minikube -n emojivoto service web-svc
50+
```
5151

5252
### In docker-compose
5353

@@ -89,28 +89,31 @@ go run emojivoto-web/cmd/vote-bot/main.go
8989
9090
## Releasing a new version
9191
92-
To update the docker images:
92+
To build and push multi-arch docker images:
9393
9494
1. Update the tag name in `common.mk`
95-
1. Update the base image tags in `Makefile` and `Dockerfile`
96-
1. Build base docker image `make build-base-docker-image`
97-
1. Build docker images `make build`
98-
1. Push the docker images to hub.docker.com
95+
1. Create the Buildx builder instance
96+
97+
```bash
98+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
99+
docker buildx create --name=multiarch-builder --driver=docker-container --use
100+
docker buildx inspect multiarch-builder --bootstrap
101+
```
102+
103+
1. Build & push the multi-arch docker images to hub.docker.com
99104
100105
```bash
101106
docker login
102-
docker push buoyantio/emojivoto-svc-base:v10
103-
docker push buoyantio/emojivoto-emoji-svc:v10
104-
docker push buoyantio/emojivoto-voting-svc:v10
105-
docker push buoyantio/emojivoto-web:v10
107+
make multi-arch
106108
```
107109
108110
1. Update:
109-
- `docker-compose.yml`
110-
- (`kustomize/deployment/emoji.yml`),
111-
- (`kustomize/deployment/vote-bot.yml`),
112-
- (`kustomize/deployment/voting.yml`),
113-
- (`kustomize/deployment/web.yml`),
111+
- `docker-compose.yml`
112+
- `kustomize/deployment/emoji.yml`
113+
- `kustomize/deployment/vote-bot.yml`
114+
- `kustomize/deployment/voting.yml`
115+
- `kustomize/deployment/web.yml`
116+
114117
1. Distribute to the Linkerd website repo
115118
116119
```bash

common.mk

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ package: protoc compile build-container
1818
build-container:
1919
docker build .. -t "buoyantio/$(svc_name):$(IMAGE_TAG)" --build-arg svc_name=$(svc_name)
2020

21+
build-multi-arch:
22+
docker buildx build .. -t "buoyantio/$(svc_name):$(IMAGE_TAG)" --build-arg svc_name=$(svc_name) \
23+
-f ../Dockerfile-multi-arch --platform linux/amd64,linux/arm64,linux/arm/v7 --push
24+
2125
compile:
2226
GOOS=linux go build -v -o $(target_dir)/$(svc_name) cmd/server.go
2327

0 commit comments

Comments
 (0)