Overhaul Makefile and Dockerfile
Trying to standardize builds across architectures. We wrote this basic Makefile/Dockerfile template for another container, but it works well, so reuse it here.
This commit is contained in:
parent
4bff742689
commit
5f4837491f
|
|
@ -0,0 +1 @@
|
||||||
|
/bin
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
FROM gcr.io/google_containers/ubuntu-slim:0.1
|
FROM gcr.io/google_containers/ubuntu-slim:0.1
|
||||||
|
|
||||||
|
ARG ARCH
|
||||||
|
ADD bin/git-sync-${ARCH} /git-sync
|
||||||
|
|
||||||
ENV GIT_SYNC_DEST /git
|
ENV GIT_SYNC_DEST /git
|
||||||
VOLUME ["/git"]
|
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install -y git ca-certificates --no-install-recommends && \
|
apt-get install -y git ca-certificates --no-install-recommends && \
|
||||||
|
|
@ -9,8 +11,6 @@ RUN apt-get update && \
|
||||||
apt-get clean -y && \
|
apt-get clean -y && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY git-sync /git-sync
|
|
||||||
|
|
||||||
# Move the existing SSH binary, then replace it with the wrapper script
|
# Move the existing SSH binary, then replace it with the wrapper script
|
||||||
RUN mv /usr/bin/ssh /usr/bin/ssh-binary
|
RUN mv /usr/bin/ssh /usr/bin/ssh-binary
|
||||||
COPY ssh-wrapper.sh /usr/bin/ssh
|
COPY ssh-wrapper.sh /usr/bin/ssh
|
||||||
|
|
|
||||||
94
Makefile
94
Makefile
|
|
@ -1,17 +1,89 @@
|
||||||
all: push
|
# Copyright 2016 The Kubernetes Authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
# 0.0 shouldn't clobber any released builds
|
.PHONY: all push push-legacy container clean
|
||||||
TAG = 0.0
|
|
||||||
PREFIX = gcr.io/google_containers/git-sync
|
|
||||||
|
|
||||||
binary: main.go
|
REGISTRY ?= gcr.io/google_containers
|
||||||
CGO_ENABLED=0 GOOS=linux godep go build -a -installsuffix cgo -ldflags '-w' -o git-sync
|
IMAGE = $(REGISTRY)/git-sync-$(ARCH)
|
||||||
|
LEGACY_AMD64_IMAGE = $(REGISTRY)/git-sync
|
||||||
|
|
||||||
container: binary
|
TAG = 1.0
|
||||||
docker build -t $(PREFIX):$(TAG) .
|
|
||||||
|
|
||||||
push: container
|
# Architectures supported: amd64, arm, arm64 and ppc64le
|
||||||
gcloud docker push $(PREFIX):$(TAG)
|
ARCH ?= amd64
|
||||||
|
|
||||||
|
# TODO: get a base image for non-x86 archs
|
||||||
|
# arm arm64 ppc64le
|
||||||
|
ALL_ARCH = amd64
|
||||||
|
|
||||||
|
KUBE_CROSS_IMAGE ?= gcr.io/google_containers/kube-cross
|
||||||
|
KUBE_CROSS_VERSION ?= v1.6.3-2
|
||||||
|
|
||||||
|
GO_PKG = k8s.io/git-sync
|
||||||
|
BIN = git-sync
|
||||||
|
SRCS = main.go
|
||||||
|
|
||||||
|
# If you want to build all containers, see the 'all-container' rule.
|
||||||
|
# If you want to build AND push all containers, see the 'all-push' rule.
|
||||||
|
all: all-build
|
||||||
|
|
||||||
|
sub-container-%:
|
||||||
|
$(MAKE) ARCH=$* container
|
||||||
|
|
||||||
|
sub-push-%:
|
||||||
|
$(MAKE) ARCH=$* push
|
||||||
|
|
||||||
|
all-build: $(addprefix bin/$(BIN)-,$(ALL_ARCH))
|
||||||
|
|
||||||
|
all-container: $(addprefix sub-container-,$(ALL_ARCH))
|
||||||
|
|
||||||
|
all-push: $(addprefix sub-push-,$(ALL_ARCH))
|
||||||
|
|
||||||
|
build: bin/$(BIN)-$(ARCH)
|
||||||
|
|
||||||
|
bin/$(BIN)-$(ARCH): $(SRCS)
|
||||||
|
mkdir -p bin
|
||||||
|
docker run \
|
||||||
|
-u $$(id -u):$$(id -g) \
|
||||||
|
-v $$(pwd):/go/src/$(GO_PKG) \
|
||||||
|
$(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \
|
||||||
|
/bin/bash -c " \
|
||||||
|
cd /go/src/$(GO_PKG) && \
|
||||||
|
CGO_ENABLED=0 godep go build \
|
||||||
|
-installsuffix cgo \
|
||||||
|
-ldflags '-w' \
|
||||||
|
-o $@"
|
||||||
|
|
||||||
|
container: .container-$(ARCH)
|
||||||
|
.container-$(ARCH): bin/$(BIN)-$(ARCH)
|
||||||
|
docker build -t $(IMAGE):$(TAG) --build-arg ARCH=$(ARCH) .
|
||||||
|
ifeq ($(ARCH),amd64)
|
||||||
|
docker tag $(IMAGE):$(TAG) $(LEGACY_AMD64_IMAGE):$(TAG)
|
||||||
|
endif
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
push: .push-$(ARCH)
|
||||||
|
.push-$(ARCH): .container-$(ARCH)
|
||||||
|
gcloud docker push $(IMAGE):$(TAG)
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
push-legacy: .push-legacy-$(ARCH)
|
||||||
|
.push-legacy-$(ARCH): .container-$(ARCH)
|
||||||
|
ifeq ($(ARCH),amd64)
|
||||||
|
gcloud docker push $(LEGACY_AMD64_IMAGE):$(TAG)
|
||||||
|
endif
|
||||||
|
touch $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
docker rmi -f $(PREFIX):$(TAG) || true
|
rm -rf .container-* .push-* bin/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue