mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 10:31:35 +00:00
Use docker run to compile C code not docker build
C version of #1006 Note that I switched all the C builds to use -O2 and that meant that the compiler found some more warnings so I also fixed these up. The possibly undefined ones were harmless, the aliasing one is now more correct. As these are small programs, the caching from `docker build` makes no real difference, and worst case compile time is much better. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
6f07ca1a8f
commit
b5d9ff8cda
15
alpine/base/c-compile/Dockerfile
Normal file
15
alpine/base/c-compile/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
FROM alpine:3.5
|
||||||
|
RUN \
|
||||||
|
apk update && apk upgrade && \
|
||||||
|
apk add \
|
||||||
|
curl \
|
||||||
|
gcc \
|
||||||
|
git \
|
||||||
|
libc-dev \
|
||||||
|
linux-headers \
|
||||||
|
util-linux-dev \
|
||||||
|
&& true
|
||||||
|
|
||||||
|
COPY compile.sh /usr/bin/
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/compile.sh"]
|
29
alpine/base/c-compile/Makefile
Normal file
29
alpine/base/c-compile/Makefile
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
.PHONY: tag push
|
||||||
|
|
||||||
|
BASE=alpine:3.5
|
||||||
|
IMAGE=c-compile
|
||||||
|
|
||||||
|
default: push
|
||||||
|
|
||||||
|
hash: Dockerfile compile.sh
|
||||||
|
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
|
||||||
|
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
|
||||||
|
docker run --rm --entrypoint=/bin/sh $(IMAGE):build -c 'cat /lib/apk/db/installed /usr/bin/compile.sh | sha1sum' | sed 's/ .*//' > hash
|
||||||
|
|
||||||
|
push: hash
|
||||||
|
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
||||||
|
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
|
||||||
|
docker push mobylinux/$(IMAGE):$(shell cat hash))
|
||||||
|
docker rmi $(IMAGE):build
|
||||||
|
rm -f hash
|
||||||
|
|
||||||
|
tag: hash
|
||||||
|
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
||||||
|
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
|
||||||
|
docker rmi $(IMAGE):build
|
||||||
|
rm -f hash
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f hash
|
||||||
|
|
||||||
|
.DELETE_ON_ERROR:
|
56
alpine/base/c-compile/compile.sh
Executable file
56
alpine/base/c-compile/compile.sh
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# This is designed to compile a single package to a single binary
|
||||||
|
# so it makes some assumptions about things to simplify config
|
||||||
|
# to output a single binary (in a tarball) just use -o file
|
||||||
|
# use --docker to output a tarball for input to docker build -
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: -o file"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
[ $# = 0 ] && usage
|
||||||
|
|
||||||
|
while [ $# -gt 0 ]
|
||||||
|
do
|
||||||
|
flag="$1"
|
||||||
|
case "$flag" in
|
||||||
|
-o)
|
||||||
|
[ $# -eq 1 ] && usage
|
||||||
|
out="$2"
|
||||||
|
mkdir -p "$(dirname $2)"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-l*)
|
||||||
|
LIBS="$LIBS $1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option $1"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -z "$out" ] && usage
|
||||||
|
|
||||||
|
package=$(basename "$out")
|
||||||
|
|
||||||
|
dir="/src/$package"
|
||||||
|
|
||||||
|
mkdir -p $dir
|
||||||
|
|
||||||
|
# untar input
|
||||||
|
tar xf - -C $dir
|
||||||
|
|
||||||
|
(
|
||||||
|
cd $dir
|
||||||
|
CFILES=$(find . -name '*.c')
|
||||||
|
cc -static -O2 -Wall -Werror -o ../../$out $CFILES $LIBS
|
||||||
|
)
|
||||||
|
|
||||||
|
tar cf - $out
|
||||||
|
exit 0
|
@ -1,10 +0,0 @@
|
|||||||
# Tag: b77cfc4ad0033d4366df830ed697afc7bab458a2
|
|
||||||
FROM mobylinux/alpine-build-c@sha256:53739ea6042cb0ac39cf6e262012c1c4224206b2c9b719569fe7efa3a381348c
|
|
||||||
|
|
||||||
COPY . /9pmount-vsock
|
|
||||||
|
|
||||||
WORKDIR /9pmount-vsock
|
|
||||||
|
|
||||||
RUN cc -Wall -Werror 9pmount-vsock.c hvsock.c -lpthread -o 9pmount-vsock
|
|
||||||
|
|
||||||
CMD ["tar", "cf", "-", "9pmount-vsock"]
|
|
@ -1,12 +1,13 @@
|
|||||||
DEPS=Dockerfile $(wildcard *.c *.h)
|
# Tag: ac075fed7c87e4af30d8490ae0504166cceb0df3
|
||||||
|
C_COMPILE=mobylinux/c-compile@sha256:0e82d441ce112d638f904a08199c76b022c065a2dbf8908bb366755267d4417f
|
||||||
|
|
||||||
9pmount-vsock: $(DEPS)
|
default: sbin/9pmount-vsock
|
||||||
mkdir -p sbin
|
|
||||||
BUILD=$$( tar cf - $(DEPS) | docker build -q - ) && \
|
|
||||||
[ -n "$$BUILD" ] && \
|
|
||||||
echo "Built $$BUILD" && \
|
|
||||||
docker run --rm --net=none $$BUILD | tar xf - -C sbin
|
|
||||||
|
|
||||||
|
DEPS=$(wildcard *.c *.h)
|
||||||
|
|
||||||
|
sbin/9pmount-vsock: $(DEPS)
|
||||||
|
mkdir -p $(dir $@)
|
||||||
|
tar cf - $(DEPS) | docker run --rm --net=none --log-driver=none -i $(C_COMPILE) -o $@ -lpthread | tar xf -
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf sbin
|
rm -rf sbin
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
# Tag: b77cfc4ad0033d4366df830ed697afc7bab458a2
|
|
||||||
FROM mobylinux/alpine-build-c@sha256:53739ea6042cb0ac39cf6e262012c1c4224206b2c9b719569fe7efa3a381348c
|
|
||||||
|
|
||||||
COPY . /nc-vsock
|
|
||||||
|
|
||||||
WORKDIR /nc-vsock
|
|
||||||
|
|
||||||
RUN cc -Wall -Werror -o nc-vsock nc-vsock.c -luuid
|
|
||||||
|
|
||||||
CMD ["tar", "cf", "-", "nc-vsock"]
|
|
@ -1,11 +1,13 @@
|
|||||||
DEPS=Dockerfile $(wildcard *.c *.h)
|
# Tag: ac075fed7c87e4af30d8490ae0504166cceb0df3
|
||||||
|
C_COMPILE=mobylinux/c-compile@sha256:0e82d441ce112d638f904a08199c76b022c065a2dbf8908bb366755267d4417f
|
||||||
|
|
||||||
|
default: usr/bin/nc-vsock
|
||||||
|
|
||||||
|
DEPS=$(wildcard *.c *.h)
|
||||||
|
|
||||||
usr/bin/nc-vsock: $(DEPS)
|
usr/bin/nc-vsock: $(DEPS)
|
||||||
mkdir -p usr/bin
|
mkdir -p $(dir $@)
|
||||||
BUILD=$$( tar cf - $(DEPS) | docker build -q - ) && \
|
tar cf - $(DEPS) | docker run --rm --net=none --log-driver=none -i $(C_COMPILE) -o $@ -luuid | tar xf -
|
||||||
[ -n "$$BUILD" ] && \
|
|
||||||
echo "Built $$BUILD" && \
|
|
||||||
docker run --rm --net=none $$BUILD | tar xf - -C usr/bin
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf usr
|
rm -rf usr
|
||||||
|
@ -193,7 +193,7 @@ static int hvsock_listen(const char *port_str)
|
|||||||
|
|
||||||
static int tcp_connect(const char *node, const char *service)
|
static int tcp_connect(const char *node, const char *service)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
int ret;
|
int ret;
|
||||||
const struct addrinfo hints = {
|
const struct addrinfo hints = {
|
||||||
.ai_family = AF_INET,
|
.ai_family = AF_INET,
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
# Tag: b77cfc4ad0033d4366df830ed697afc7bab458a2
|
|
||||||
FROM mobylinux/alpine-build-c@sha256:53739ea6042cb0ac39cf6e262012c1c4224206b2c9b719569fe7efa3a381348c
|
|
||||||
|
|
||||||
COPY . /tap-vsockd
|
|
||||||
|
|
||||||
WORKDIR /tap-vsockd
|
|
||||||
|
|
||||||
RUN cc -Wall -Werror tap-vsockd.c hvsock.c protocol.c -lpthread -o tap-vsockd
|
|
||||||
|
|
||||||
CMD ["tar", "cf", "-", "tap-vsockd"]
|
|
@ -1,11 +1,13 @@
|
|||||||
DEPS=Dockerfile $(wildcard *.c *.h)
|
# Tag: ac075fed7c87e4af30d8490ae0504166cceb0df3
|
||||||
|
C_COMPILE=mobylinux/c-compile@sha256:0e82d441ce112d638f904a08199c76b022c065a2dbf8908bb366755267d4417f
|
||||||
|
|
||||||
|
default: sbin/tap-vsockd
|
||||||
|
|
||||||
|
DEPS=$(wildcard *.c *.h)
|
||||||
|
|
||||||
sbin/tap-vsockd: $(DEPS)
|
sbin/tap-vsockd: $(DEPS)
|
||||||
mkdir -p sbin
|
mkdir -p $(dir $@)
|
||||||
BUILD=$$( tar cf - $(DEPS) | docker build -q - ) && \
|
tar cf - $(DEPS) | docker run --rm --net=none --log-driver=none -i $(C_COMPILE) -o $@ -lpthread | tar xf -
|
||||||
[ -n "$$BUILD" ] && \
|
|
||||||
echo "Built $$BUILD" && \
|
|
||||||
docker run --rm --net=none $$BUILD | tar xf - -C sbin
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf sbin
|
rm -rf sbin
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
# Tag: b77cfc4ad0033d4366df830ed697afc7bab458a2
|
|
||||||
FROM mobylinux/alpine-build-c@sha256:53739ea6042cb0ac39cf6e262012c1c4224206b2c9b719569fe7efa3a381348c
|
|
||||||
|
|
||||||
COPY . /transfused
|
|
||||||
|
|
||||||
WORKDIR /transfused
|
|
||||||
|
|
||||||
RUN cc -g -static -Wall -Werror -o transfused transfused.c transfused_log.c transfused_vsock.c
|
|
||||||
|
|
||||||
CMD ["tar", "cf", "-", "transfused"]
|
|
@ -1,11 +1,13 @@
|
|||||||
DEPS=Dockerfile $(wildcard *.c *.h)
|
# Tag: ac075fed7c87e4af30d8490ae0504166cceb0df3
|
||||||
|
C_COMPILE=mobylinux/c-compile@sha256:0e82d441ce112d638f904a08199c76b022c065a2dbf8908bb366755267d4417f
|
||||||
|
|
||||||
|
default: sbin/transfused
|
||||||
|
|
||||||
|
DEPS=$(wildcard *.c *.h)
|
||||||
|
|
||||||
sbin/transfused: $(DEPS)
|
sbin/transfused: $(DEPS)
|
||||||
mkdir -p sbin
|
mkdir -p $(dir $@)
|
||||||
BUILD=$$( tar cf - $(DEPS) | docker build -q - ) && \
|
tar cf - $(DEPS) | docker run --rm --net=none --log-driver=none -i $(C_COMPILE) -o $@ | tar xf -
|
||||||
[ -n "$$BUILD" ] && \
|
|
||||||
echo "Built $$BUILD" && \
|
|
||||||
docker run --rm --net=none $$BUILD | tar xf - -C sbin
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf sbin
|
rm -rf sbin
|
||||||
|
@ -97,7 +97,7 @@ void unlock(char *const descr, pthread_mutex_t *mutex)
|
|||||||
|
|
||||||
int bind_socket(const char *socket)
|
int bind_socket(const char *socket)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock = -1;
|
||||||
|
|
||||||
if (socket[0] == 0)
|
if (socket[0] == 0)
|
||||||
die(2, NULL, NULL, "Socket family required");
|
die(2, NULL, NULL, "Socket family required");
|
||||||
@ -118,7 +118,7 @@ int bind_socket(const char *socket)
|
|||||||
|
|
||||||
int connect_socket(const char *socket)
|
int connect_socket(const char *socket)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock = -1;
|
||||||
|
|
||||||
if (socket[0] == 0)
|
if (socket[0] == 0)
|
||||||
die(2, NULL, NULL, "Socket family required");
|
die(2, NULL, NULL, "Socket family required");
|
||||||
@ -549,12 +549,15 @@ void start_writer(connection_t *connection, int fuse)
|
|||||||
void negotiate_notify_channel(char *mount_point, int notify_sock)
|
void negotiate_notify_channel(char *mount_point, int notify_sock)
|
||||||
{
|
{
|
||||||
int len = strlen(mount_point);
|
int len = strlen(mount_point);
|
||||||
char hdr[6];
|
struct {
|
||||||
|
uint32_t len;
|
||||||
|
uint16_t channel;
|
||||||
|
} __attribute__((packed)) hdr;
|
||||||
|
|
||||||
*((uint32_t *)hdr) = 6 + len;
|
hdr.len = 6 + len;
|
||||||
*((uint16_t *)(hdr + 4)) = TRANSFUSE_NOTIFY_CHANNEL;
|
hdr.channel = TRANSFUSE_NOTIFY_CHANNEL;
|
||||||
|
|
||||||
write_exactly("negotiate_notify_channel hdr", notify_sock, hdr, 6);
|
write_exactly("negotiate_notify_channel hdr", notify_sock, &hdr, 6);
|
||||||
write_exactly("negotiate_notify_channel mnt",
|
write_exactly("negotiate_notify_channel mnt",
|
||||||
notify_sock, mount_point, len);
|
notify_sock, mount_point, len);
|
||||||
}
|
}
|
||||||
@ -1087,7 +1090,7 @@ void serve(parameters *params)
|
|||||||
char subproto_selector;
|
char subproto_selector;
|
||||||
pthread_t child;
|
pthread_t child;
|
||||||
connection_t *conn;
|
connection_t *conn;
|
||||||
void *(*connection_handler_thread)(void *);
|
void *(*connection_handler_thread)(void *) = NULL;
|
||||||
|
|
||||||
if (listen(params->data_sock, 16))
|
if (listen(params->data_sock, 16))
|
||||||
die(1, NULL, "listen", "");
|
die(1, NULL, "listen", "");
|
||||||
|
Loading…
Reference in New Issue
Block a user