Add base image (busybox) for other arch's

master
Tim Hockin 2016-09-22 22:45:29 -07:00
parent 43e119bda6
commit 1a7aa69e44
4 changed files with 38 additions and 15 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/.go
/.push-*
/.container-*
/.dockerfile-*

View File

@ -12,13 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
FROM alpine:3.4
FROM ARG_FROM
MAINTAINER Tim Hockin <thockin@google.com>
ARG ARCH
ADD bin/${ARCH}/myapp /myapp
ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN
USER nobody:nobody
ENTRYPOINT ["/myapp"]
ENTRYPOINT ["/ARG_BIN"]

View File

@ -30,7 +30,21 @@ ARCH ?= amd64
SRC_DIRS := cmd pkg # directories which hold app source (not vendored)
ALL_ARCH := amd64 arm arm64 ppc64le # TODO: base image for non-x86 archs?
ALL_ARCH := amd64 arm arm64 ppc64le
# Set default base image dynamically for each arch
ifeq ($(ARCH),amd64)
BASEIMAGE?=alpine
endif
ifeq ($(ARCH),arm)
BASEIMAGE?=armel/busybox
endif
ifeq ($(ARCH),arm64)
BASEIMAGE?=aarch64/busybox
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE?=ppc64le/busybox
endif
IMAGE := $(REGISTRY)/$(BIN)-$(ARCH)
@ -81,6 +95,7 @@ bin/$(ARCH)/$(BIN): build-dirs
-v $$(pwd)/.go:/go \
-v $$(pwd):/go/src/$(PKG) \
-v $$(pwd)/bin/$(ARCH):/go/bin \
-v $$(pwd)/bin/$(ARCH):/go/bin/$$(go env GOOS)_$(ARCH) \
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
@ -94,8 +109,13 @@ bin/$(ARCH)/$(BIN): build-dirs
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(VERSION)
container: .container-$(DOTFILE_IMAGE) container-name
.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile
@docker build -t $(IMAGE):$(VERSION) --build-arg ARCH=$(ARCH) .
.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in
@sed \
-e 's|ARG_BIN|$(BIN)|g' \
-e 's|ARG_ARCH|$(ARCH)|g' \
-e 's|ARG_FROM|$(BASEIMAGE)|g' \
Dockerfile.in > .dockerfile-$(ARCH)
@docker build -t $(IMAGE):$(VERSION) -f .dockerfile-$(ARCH) .
@docker images -q $(IMAGE):$(VERSION) > $@
container-name:
@ -133,7 +153,7 @@ build-dirs:
clean: container-clean bin-clean
container-clean:
rm -rf .container-* .push-*
rm -rf .container-* .dockerfile-* .push-*
bin-clean:
rm -rf .go bin

View File

@ -14,21 +14,25 @@ Makefile:
- change `BIN` to your binary name
- change `PKG` to the Go import path of this repo
- change `REGISTRY` to the Docker registry you want to use
- maybe change `SRC_DIRS` if youuse some other layout
- maybe change `SRC_DIRS` if you use some other layout
Dockerfile:
- change all `myapp` to your binary name
Dockerfile.in:
- change the `MAINTAINER` to you
- maybe change or remove the `USER` if you need
## Building
Run `make` or `make build` to compile your app. This will use a Docker image
to build your app, with the current directory volume-mounted into place. This
will store incremental state for the fastest possible build.
will store incremental state for the fastest possible build. Run `make
all-build` to build for all architectures.
Run `make container` to build the container image. It will calculate the image
tag based on the most recent git tag, and whether the repo is "dirty" since
that tag (see `make version`).
that tag (see `make version`). Run `make all-container` to build containers
for all architectures.
Run `make push` to push the container image to `REGISTRY`.
Run `make push` to push the container image to `REGISTRY`. Run `make all-push`
to push the container images for all architectures.
Run `make clean` to clean up.