Add base image (busybox) for other arch's
parent
43e119bda6
commit
1a7aa69e44
|
@ -2,3 +2,4 @@
|
||||||
/.go
|
/.go
|
||||||
/.push-*
|
/.push-*
|
||||||
/.container-*
|
/.container-*
|
||||||
|
/.dockerfile-*
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
FROM alpine:3.4
|
FROM ARG_FROM
|
||||||
|
|
||||||
MAINTAINER Tim Hockin <thockin@google.com>
|
MAINTAINER Tim Hockin <thockin@google.com>
|
||||||
|
|
||||||
ARG ARCH
|
ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN
|
||||||
|
|
||||||
ADD bin/${ARCH}/myapp /myapp
|
|
||||||
|
|
||||||
USER nobody:nobody
|
USER nobody:nobody
|
||||||
ENTRYPOINT ["/myapp"]
|
ENTRYPOINT ["/ARG_BIN"]
|
28
Makefile
28
Makefile
|
@ -30,7 +30,21 @@ ARCH ?= amd64
|
||||||
|
|
||||||
SRC_DIRS := cmd pkg # directories which hold app source (not vendored)
|
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)
|
IMAGE := $(REGISTRY)/$(BIN)-$(ARCH)
|
||||||
|
|
||||||
|
@ -81,6 +95,7 @@ bin/$(ARCH)/$(BIN): build-dirs
|
||||||
-v $$(pwd)/.go:/go \
|
-v $$(pwd)/.go:/go \
|
||||||
-v $$(pwd):/go/src/$(PKG) \
|
-v $$(pwd):/go/src/$(PKG) \
|
||||||
-v $$(pwd)/bin/$(ARCH):/go/bin \
|
-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 \
|
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \
|
||||||
-w /go/src/$(PKG) \
|
-w /go/src/$(PKG) \
|
||||||
$(BUILD_IMAGE) \
|
$(BUILD_IMAGE) \
|
||||||
|
@ -94,8 +109,13 @@ bin/$(ARCH)/$(BIN): build-dirs
|
||||||
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(VERSION)
|
DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(VERSION)
|
||||||
|
|
||||||
container: .container-$(DOTFILE_IMAGE) container-name
|
container: .container-$(DOTFILE_IMAGE) container-name
|
||||||
.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile
|
.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in
|
||||||
@docker build -t $(IMAGE):$(VERSION) --build-arg ARCH=$(ARCH) .
|
@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) > $@
|
@docker images -q $(IMAGE):$(VERSION) > $@
|
||||||
|
|
||||||
container-name:
|
container-name:
|
||||||
|
@ -133,7 +153,7 @@ build-dirs:
|
||||||
clean: container-clean bin-clean
|
clean: container-clean bin-clean
|
||||||
|
|
||||||
container-clean:
|
container-clean:
|
||||||
rm -rf .container-* .push-*
|
rm -rf .container-* .dockerfile-* .push-*
|
||||||
|
|
||||||
bin-clean:
|
bin-clean:
|
||||||
rm -rf .go bin
|
rm -rf .go bin
|
||||||
|
|
16
README.md
16
README.md
|
@ -14,21 +14,25 @@ Makefile:
|
||||||
- change `BIN` to your binary name
|
- change `BIN` to your binary name
|
||||||
- change `PKG` to the Go import path of this repo
|
- change `PKG` to the Go import path of this repo
|
||||||
- change `REGISTRY` to the Docker registry you want to use
|
- 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:
|
Dockerfile.in:
|
||||||
- change all `myapp` to your binary name
|
- change the `MAINTAINER` to you
|
||||||
|
- maybe change or remove the `USER` if you need
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Run `make` or `make build` to compile your app. This will use a Docker image
|
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
|
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
|
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
|
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.
|
Run `make clean` to clean up.
|
||||||
|
|
Loading…
Reference in New Issue