-
Notifications
You must be signed in to change notification settings - Fork 40k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reimplement 'pause' in C - smaller footprint all around #23009
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.container-* | ||
/.push-* | ||
/bin |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,42 +12,85 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
.PHONY: build push | ||
.PHONY: all push push-legacy container clean | ||
|
||
TAG=2.0 | ||
REGISTRY?="gcr.io/google_containers" | ||
REGISTRY ?= gcr.io/google_containers | ||
IMAGE = $(REGISTRY)/pause-$(ARCH) | ||
LEGACY_AMD64_IMAGE = $(REGISTRY)/pause | ||
|
||
TAG = 3.0 | ||
|
||
# Architectures supported: amd64, arm, arm64 and ppc64le | ||
ARCH?=amd64 | ||
GOLANG_VERSION=1.6 | ||
TEMP_DIR:=$(shell mktemp -d) | ||
ARCH ?= amd64 | ||
|
||
ALL_ARCH = amd64 arm arm64 ppc64le | ||
|
||
CFLAGS = -Os -Wall -static | ||
KUBE_CROSS_IMAGE ?= gcr.io/google_containers/kube-cross | ||
KUBE_CROSS_VERSION ?= $(shell cat ../build-image/cross/VERSION) | ||
|
||
BIN = pause | ||
SRCS = pause.c | ||
|
||
all: push-legacy-too | ||
ifeq ($(ARCH),amd64) | ||
TRIPLE ?= x86_64-linux-gnu | ||
endif | ||
|
||
build: | ||
cp pause.go Dockerfile $(TEMP_DIR) | ||
ifeq ($(ARCH),arm) | ||
TRIPLE ?= arm-linux-gnueabi | ||
endif | ||
|
||
docker run -it -v $(TEMP_DIR):/build golang:$(GOLANG_VERSION) /bin/bash -c \ | ||
"cd /build && CGO_ENABLED=0 GOARM=6 GOARCH=$(ARCH) go build -a -installsuffix cgo -ldflags '-w' ./pause.go" | ||
ifeq ($(ARCH),arm64) | ||
TRIPLE ?= aarch64-linux-gnu | ||
endif | ||
|
||
ifeq ($(ARCH),$(filter $(ARCH),amd64 arm)) | ||
# Run goupx for amd64 and arm. The condition above is equal to 'if [[ $ARCH == "amd64" || $ARCH == "arm" ]]' in bash | ||
docker run -it -v $(TEMP_DIR):/build golang:$(GOLANG_VERSION) /bin/bash -c \ | ||
"cd /build && apt-get update && apt-get install -y upx \ | ||
&& go get github.com/pwaller/goupx && goupx pause" | ||
ifeq ($(ARCH),ppc64le) | ||
TRIPLE ?= powerpc64le-linux-gnu | ||
endif | ||
|
||
# And build the image | ||
docker build -t $(REGISTRY)/pause-$(ARCH):$(TAG) $(TEMP_DIR) | ||
# If you want to build AND push all containers, see the 'all-push' rule. | ||
all: all-container | ||
|
||
sub-container-%: | ||
$(MAKE) ARCH=$* container | ||
|
||
sub-push-%: | ||
$(MAKE) ARCH=$* push | ||
|
||
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):/build \ | ||
$(KUBE_CROSS_IMAGE):$(KUBE_CROSS_VERSION) \ | ||
/bin/bash -c "\ | ||
cd /build && \ | ||
$(TRIPLE)-gcc $(CFLAGS) -o $@ $^ && \ | ||
$(TRIPLE)-strip $@" | ||
|
||
container: .container-$(ARCH) | ||
.container-$(ARCH): bin/$(BIN)-$(ARCH) | ||
docker build -t $(IMAGE):$(TAG) --build-arg ARCH=$(ARCH) . | ||
ifeq ($(ARCH),amd64) | ||
docker tag -f $(REGISTRY)/pause-$(ARCH):$(TAG) $(REGISTRY)/pause:$(TAG) | ||
docker tag -f $(IMAGE):$(TAG) $(LEGACY_AMD64_IMAGE):$(TAG) | ||
endif | ||
touch $@ | ||
|
||
push: build | ||
gcloud docker --server=gcr.io push $(REGISTRY)/pause-$(ARCH):$(TAG) | ||
push: .push-$(ARCH) | ||
.push-$(ARCH): .container-$(ARCH) | ||
gcloud docker push $(IMAGE):$(TAG) | ||
touch $@ | ||
|
||
push-legacy-too: push | ||
push-legacy: .push-legacy-$(ARCH) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thockin I'm not sure if we should push legacy of this image anymore, as we've updated all refs to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to just leave it for a while. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, fine |
||
.push-legacy-$(ARCH): .container-$(ARCH) | ||
ifeq ($(ARCH),amd64) | ||
gcloud docker push $(REGISTRY)/pause:$(TAG) | ||
gcloud docker push $(LEGACY_AMD64_IMAGE):$(TAG) | ||
endif | ||
touch $@ | ||
|
||
clean: | ||
rm -rf .container-* .push-* bin/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
// +build linux | ||
|
||
/* | ||
Copyright 2014 The Kubernetes Authors All rights reserved. | ||
Copyright 2016 The Kubernetes Authors All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -16,18 +14,23 @@ See the License for the specific language governing permissions and | |
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
func main() { | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM) | ||
static void sigdown(int signo) { | ||
psignal(signo, "shutting down, got signal"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consistent tabs and spaces. Use tabs for indent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
exit(0); | ||
} | ||
|
||
// Block until a signal is received. | ||
<-c | ||
int main() { | ||
if (signal(SIGINT, sigdown) == SIG_ERR) | ||
return 1; | ||
if (signal(SIGTERM, sigdown) == SIG_ERR) | ||
return 2; | ||
signal(SIGKILL, sigdown); | ||
for (;;) pause(); | ||
fprintf(stderr, "error: infinite loop terminated\n"); | ||
return 42; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a var that is a list of supported ARCH values since you have to un-edit CHANGELOG :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand the purpose of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking a
make containers
rule would loop for all supported architectures, and amake pushes
would push them all. Bad idea?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, though I named the rules all-container and all-push.