Skip to content
Permalink
Browse files

Build multi-arch docker images

Signed-off-by: Matevz Mihalic <matevz.mihalic@gmail.com>
  • Loading branch information...
matevzmihalic authored and alexellis committed Oct 10, 2019
1 parent 4525c35 commit 2e3371dd3c6aee22edb3159ca2ef8a2bf74247a0
Showing with 29 additions and 14 deletions.
  1. +1 −0 .travis.yml
  2. +11 −11 Dockerfile
  3. +17 −3 Makefile
@@ -13,6 +13,7 @@ script:
after_success:
- make docker-login
- make push
- make manifest

before_deploy:
- ./ci/hashgen.sh
@@ -1,4 +1,4 @@
FROM golang:1.11 as build
FROM golang:1.11-alpine as build

WORKDIR /go/src/github.com/alexellis/inlets

@@ -10,22 +10,22 @@ COPY main.go .

ARG GIT_COMMIT
ARG VERSION
ARG OPTS

RUN CGO_ENABLED=0 go build -ldflags "-s -w -X main.GitCommit=${GIT_COMMIT} -X main.Version=${VERSION}" -a -installsuffix cgo -o /usr/bin/inlets
# add user in this stage because it cannot be done in next stage which is built from scratch
# in next stage we'll copy user and group information from this stage
RUN env ${OPTS} CGO_ENABLED=0 go build -ldflags "-s -w -X main.GitCommit=${GIT_COMMIT} -X main.Version=${VERSION}" -a -installsuffix cgo -o /usr/bin/inlets \
&& addgroup -S app \
&& adduser -S -g app app

FROM alpine:3.10
RUN apk add --force-refresh ca-certificates

# Add non-root user
RUN addgroup -S app && adduser -S -g app app \
&& mkdir -p /home/app || : \
&& chown -R app /home/app
FROM scratch

COPY --from=build /etc/passwd /etc/group /etc/
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /usr/bin/inlets /usr/bin/
WORKDIR /home/app

USER app
EXPOSE 80

ENTRYPOINT ["inlets"]
ENTRYPOINT ["/usr/bin/inlets"]
CMD ["--help"]
@@ -1,7 +1,10 @@
Version := $(shell git describe --tags --dirty)
GitCommit := $(shell git rev-parse HEAD)
LDFLAGS := "-s -w -X main.Version=$(Version) -X main.GitCommit=$(GitCommit)"
PLATFORM := $(shell ./hack/platform-tag.sh)

# docker manifest command will work with Docker CLI 18.03 or newer
# but for now it's still experimental feature so we need to enable that
export DOCKER_CLI_EXPERIMENTAL=enabled

.PHONY: all
all: docker
@@ -16,12 +19,23 @@ dist:

.PHONY: docker
docker:
docker build --build-arg VERSION=$(Version) --build-arg GIT_COMMIT=$(GitCommit) -t alexellis2/inlets:$(Version)$(PLATFORM) .
docker build --build-arg VERSION=$(Version) --build-arg GIT_COMMIT=$(GitCommit) -t alexellis2/inlets:$(Version)-amd64 .
docker build --build-arg VERSION=$(Version) --build-arg GIT_COMMIT=$(GitCommit) --build-arg OPTS="GOARCH=arm64" -t alexellis2/inlets:$(Version)-arm64 .
docker build --build-arg VERSION=$(Version) --build-arg GIT_COMMIT=$(GitCommit) --build-arg OPTS="GOARCH=arm GOARM=6" -t alexellis2/inlets:$(Version)-armhf .

.PHONY: docker-login
docker-login:
echo -n "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin

.PHONY: push
push:
docker push alexellis2/inlets:$(Version)$(PLATFORM)
docker push alexellis2/inlets:$(Version)-amd64
docker push alexellis2/inlets:$(Version)-arm64
docker push alexellis2/inlets:$(Version)-armhf

.PHONY: manifest
manifest:
docker manifest create --amend alexellis2/inlets:$(Version) alexellis2/inlets:$(Version)-amd64 alexellis2/inlets:$(Version)-arm64 alexellis2/inlets:$(Version)-armhf
docker manifest annotate alexellis2/inlets:$(Version) alexellis2/inlets:$(Version)-arm64 --os linux --arch arm64
docker manifest annotate alexellis2/inlets:$(Version) alexellis2/inlets:$(Version)-armhf --os linux --arch arm --variant v6
docker manifest push alexellis2/inlets:$(Version)

0 comments on commit 2e3371d

Please sign in to comment.
You can’t perform that action at this time.