diff --git a/Dockerfile.build b/Dockerfile.build index 26a16396..ed3de7ce 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -1,10 +1,17 @@ +# explicitly use Debian for maximum cross-architecture compatibility FROM debian:jessie -RUN apt-get update && apt-get install -y make nasm && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + libc6-dev \ + make \ + && rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/hello COPY . . -RUN make clean all test +RUN set -x \ + && make clean all test \ + && ls -l */hello CMD ["./hello-world/hello"] diff --git a/Dockerfile.template b/Dockerfile.template deleted file mode 100644 index d4ff707c..00000000 --- a/Dockerfile.template +++ /dev/null @@ -1,3 +0,0 @@ -FROM scratch -COPY hello / -CMD ["/hello"] diff --git a/Makefile b/Makefile index fe91e7ce..d0b0b633 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,21 @@ -IMAGES := \ - hello-world \ - hola-mundo \ - hello-seattle +C_TARGETS := $(addsuffix hello, $(wildcard */)) -ASM_TARGETS := $(addsuffix /hello, $(IMAGES)) +CC := gcc +CFLAGS := -static -Os -nostartfiles -fno-asynchronous-unwind-tables .PHONY: all -all: $(ASM_TARGETS) +all: $(C_TARGETS) -$(ASM_TARGETS): hello.asm - mkdir -p '$(dir $@)' - nasm -o '$@' -DDOCKER_IMAGE="'$$(dirname '$@')'" '$<' - chmod +x '$@' +$(C_TARGETS): hello.c + $(CC) $(CFLAGS) -o '$@' -D DOCKER_IMAGE='"$(@D)"' -D DOCKER_GREETING="\"$$(cat '$(@D)/greeting.txt')\"" '$<' + strip -R .comment -s '$@' .PHONY: clean clean: - -rm -vrf $(addsuffix /, $(IMAGES)) + -rm -vrf $(C_TARGETS) .PHONY: test -test: $(ASM_TARGETS) +test: $(C_TARGETS) @for b in $^; do \ ( set -x && "./$$b" ); \ ( set -x && "./$$b" | grep -q '"'"$$(dirname "$$b")"'"' ); \ diff --git a/hello-seattle/greeting.txt b/hello-seattle/greeting.txt new file mode 100644 index 00000000..a2a137d5 --- /dev/null +++ b/hello-seattle/greeting.txt @@ -0,0 +1 @@ +Hello from DockerCon 2016 (Seattle)! diff --git a/hello-seattle/hello b/hello-seattle/hello index dd34b001..f7ef94c4 100755 Binary files a/hello-seattle/hello and b/hello-seattle/hello differ diff --git a/hello-world/greeting.txt b/hello-world/greeting.txt new file mode 100644 index 00000000..97e9ced7 --- /dev/null +++ b/hello-world/greeting.txt @@ -0,0 +1 @@ +Hello from Docker! diff --git a/hello-world/hello b/hello-world/hello index 218c3e26..7f3f7f8f 100755 Binary files a/hello-world/hello and b/hello-world/hello differ diff --git a/hello.asm b/hello.asm deleted file mode 100644 index d5aa8caa..00000000 --- a/hello.asm +++ /dev/null @@ -1,93 +0,0 @@ -; this is especially thanks to: -; http://web.archive.org/web/20140528193301/http://blog.markloiseau.com/2012/05/tiny-64-bit-elf-executables - -BITS 64 - org 0x00400000 ; Program load offset - -; 64-bit ELF header -ehdr: - ; 1), 0 (ABI ver.) - db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident - times 8 db 0 ; reserved (zeroes) - - dw 2 ; e_type: Executable file - dw 0x3e ; e_machine: AMD64 - dd 1 ; e_version: current version - dq _start ; e_entry: program entry address (0x78) - dq phdr - $$ ; e_phoff program header offset (0x40) - dq 0 ; e_shoff no section headers - dd 0 ; e_flags no flags - dw ehdrsize ; e_ehsize: ELF header size (0x40) - dw phdrsize ; e_phentsize: program header size (0x38) - dw 1 ; e_phnum: one program header - dw 0 ; e_shentsize - dw 0 ; e_shnum - dw 0 ; e_shstrndx - -ehdrsize equ $ - ehdr - -; 64-bit ELF program header -phdr: - dd 1 ; p_type: loadable segment - dd 5 ; p_flags read and execute - dq 0 ; p_offset - dq $$ ; p_vaddr: start of the current section - dq $$ ; p_paddr: " " - dq filesize ; p_filesz - dq filesize ; p_memsz - dq 0x200000 ; p_align: 2^11=200000 = section alignment - -; program header size -phdrsize equ $ - phdr - -; Hello World!/your program here -_start: - - ; sys_write(stdout, message, length) - mov rax, 1 ; sys_write - mov rdi, 1 ; stdout - mov rsi, message ; message address - mov rdx, length ; message string length - syscall - - ; sys_exit(return_code) - mov rax, 60 ; sys_exit - mov rdi, 0 ; return 0 (success) - syscall - -%ifndef DOCKER_IMAGE - %define DOCKER_IMAGE 'hello-world' -%endif - - message: - db 0x0A -%ifidn DOCKER_IMAGE, 'hola-mundo' - db '¡Hola de DockerCon EU 2015 (Barcelona)!', 0x0A -%elifidn DOCKER_IMAGE, 'hello-seattle' - db 'Hello from DockerCon 2016 (Seattle)!', 0x0A -%else - db 'Hello from Docker!', 0x0A -%endif - db 'This message shows that your installation appears to be working correctly.', 0x0A - db 0x0A - db 'To generate this message, Docker took the following steps:', 0x0A - db ' 1. The Docker client contacted the Docker daemon.', 0x0A - db ' 2. The Docker daemon pulled the "', DOCKER_IMAGE, '" image from the Docker Hub.', 0x0A - db ' 3. The Docker daemon created a new container from that image which runs the', 0x0A - db ' executable that produces the output you are currently reading.', 0x0A - db ' 4. The Docker daemon streamed that output to the Docker client, which sent it', 0x0A - db ' to your terminal.', 0x0A - db 0x0A - db 'To try something more ambitious, you can run an Ubuntu container with:', 0x0A - db ' $ docker run -it ubuntu bash', 0x0A - db 0x0A - db 'Share images, automate workflows, and more with a free Docker Hub account:', 0x0A - db ' https://hub.docker.com', 0x0A - db 0x0A - db 'For more examples and ideas, visit:', 0x0A - db ' https://docs.docker.com/engine/userguide/', 0x0A - db 0x0A - length: equ $-message ; message length calculation - -; File size calculation -filesize equ $ - $$ diff --git a/hello.c b/hello.c new file mode 100644 index 00000000..ea913caf --- /dev/null +++ b/hello.c @@ -0,0 +1,41 @@ +//#include +#include + +#ifndef DOCKER_IMAGE + #define DOCKER_IMAGE "hello-world" +#endif + +#ifndef DOCKER_GREETING + #define DOCKER_GREETING "Hello from Docker!" +#endif + +const char message[] = + "\n" + DOCKER_GREETING "\n" + "This message shows that your installation appears to be working correctly.\n" + "\n" + "To generate this message, Docker took the following steps:\n" + " 1. The Docker client contacted the Docker daemon.\n" + " 2. The Docker daemon pulled the \"" DOCKER_IMAGE "\" image from the Docker Hub.\n" + " 3. The Docker daemon created a new container from that image which runs the\n" + " executable that produces the output you are currently reading.\n" + " 4. The Docker daemon streamed that output to the Docker client, which sent it\n" + " to your terminal.\n" + "\n" + "To try something more ambitious, you can run an Ubuntu container with:\n" + " $ docker run -it ubuntu bash\n" + "\n" + "Share images, automate workflows, and more with a free Docker Hub account:\n" + " https://hub.docker.com\n" + "\n" + "For more examples and ideas, visit:\n" + " https://docs.docker.com/engine/userguide/\n" + "\n"; + +void _start() { + //write(1, message, sizeof(message) - 1); + syscall(SYS_write, 1, message, sizeof(message) - 1); + + //_exit(0); + syscall(SYS_exit, 0); +} diff --git a/hola-mundo/greeting.txt b/hola-mundo/greeting.txt new file mode 100644 index 00000000..e9740fd6 --- /dev/null +++ b/hola-mundo/greeting.txt @@ -0,0 +1 @@ +¡Hola de DockerCon EU 2015 (Barcelona)! diff --git a/hola-mundo/hello b/hola-mundo/hello index 0d8f5df7..4d6496d3 100755 Binary files a/hola-mundo/hello and b/hola-mundo/hello differ diff --git a/update.sh b/update.sh index a89dc1a2..040b3252 100755 --- a/update.sh +++ b/update.sh @@ -4,13 +4,15 @@ set -e cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" set -x + docker build -f Dockerfile.build -t hello-world:build . -rm -rf */ -docker run --rm hello-world:build sh -c 'tar -c */' | tar -x -for d in */; do - d="${d%/}" - cp -v Dockerfile.template "$d/Dockerfile" - "./$d/hello" > /dev/null + +rm -rf */hello +docker run --rm hello-world:build sh -c 'tar --create */hello' | tar --extract --wildcards '*/hello' + +for h in */hello; do + d="$(dirname "$h")" + "$h" > /dev/null docker build -t hello-world:"test-$d" "$d" docker run --rm hello-world:"test-$d" done