Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ RUN set -ex; \

RUN find \( -name 'hello' -or -name 'hello.txt' -or -name '.host-arch' \) -exec file '{}' + -exec ls -lh '{}' +

CMD [".host-arch/hello-world/hello"]
CMD [".host-arch/hello"]
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ SHELL := bash -Eeuo pipefail

TARGET_ARCH := amd64
export ARCH_TEST :=
C_TARGETS := $(addsuffix hello, $(wildcard $(TARGET_ARCH)/*/))
HELLO := $(TARGET_ARCH)/hello

# norelro: https://stackoverflow.com/a/59084373/433558
export CFLAGS := -Os -fdata-sections -ffunction-sections -Wl,-z,norelro -s $(EXTRA_CFLAGS)
STRIP := $(CROSS_COMPILE)strip

.PHONY: all
all: $(C_TARGETS)
all: $(HELLO)

MUSL_SRC := /usr/local/src/musl
MUSL_DIR := $(CURDIR)/musl/$(TARGET_ARCH)
Expand All @@ -23,11 +23,9 @@ $(MUSL_GCC):
.PHONY: musl
musl: $(MUSL_GCC)

$(C_TARGETS): hello.c $(MUSL_GCC)
$(HELLO): hello.c $(MUSL_GCC)
$(MUSL_GCC) $(CFLAGS) -Wl,--gc-sections -static \
-o '$@' \
-D DOCKER_IMAGE='"$(notdir $(@D))"' \
-D DOCKER_GREETING="\"$$(cat 'greetings/$(notdir $(@D)).txt')\"" \
-D DOCKER_ARCH='"$(TARGET_ARCH)"' \
'$<'
$(STRIP) --strip-all --remove-section=.comment '$@'
Expand All @@ -48,14 +46,13 @@ $(C_TARGETS): hello.c $(MUSL_GCC)

.PHONY: clean
clean:
-rm -vrf $(C_TARGETS) $(MUSL_DIR)
-rm -vrf $(HELLO) $(MUSL_DIR)

.PHONY: test
test: $(C_TARGETS)
test: $(HELLO)
@for b in $^; do \
if [ -n "$$ARCH_TEST" ] && command -v arch-test > /dev/null && arch-test "$$ARCH_TEST" > /dev/null; then \
( set -x && "./$$b" ); \
( set -x && "./$$b" | grep -q '"'"$$(basename "$$(dirname "$$b")")"'"' ); \
if [ ! -e .host-arch ] && arch-test -n "$$ARCH_TEST" > /dev/null; then \
ln -svfT "$${b%%/*}" .host-arch; \
fi; \
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions amd64/nanoserver-1809/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mcr.microsoft.com/windows/nanoserver:1809
COPY hello.txt C:
CMD ["cmd", "/C", "type C:\\hello.txt"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 8 additions & 10 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -eu

image="${1:-hello-world}"

self="$(basename "$BASH_SOURCE")"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"

Expand Down Expand Up @@ -45,8 +43,8 @@ join() {
echo "${out#$sep}"
}

arches=( *"/$image/hello" )
arches=( "${arches[@]%"/$image/hello"}" )
arches=( *"/hello" )
arches=( "${arches[@]%"/hello"}" )

echo
cat <<-EOE
Expand All @@ -55,19 +53,19 @@ cat <<-EOE
Architectures: $(join ', ' "${arches[@]}")
EOE
for arch in "${arches[@]}"; do
commit="$(dirCommit "$arch/$image")"
commit="$(dirCommit "$arch")"
cat <<-EOE
$arch-GitCommit: $commit
$arch-Directory: $arch/$image
$arch-Directory: $arch
EOE
done

for winVariant in \
nanoserver-ltsc2025 \
nanoserver-ltsc2022 \
; do
winArches=( *"/$image/$winVariant/hello.txt" )
winArches=( "${winArches[@]%"/$image/$winVariant/hello.txt"}" )
winArches=( *"/$winVariant/hello.txt" )
winArches=( "${winArches[@]%"/$winVariant/hello.txt"}" )

if [ "${#winArches[@]}" -gt 0 ]; then
echo
Expand All @@ -77,10 +75,10 @@ for winVariant in \
Architectures: $(join ', ' "${winArches[@]/#/windows-}")
EOE
for arch in "${winArches[@]}"; do
commit="$(dirCommit "$arch/$image/$winVariant")"
commit="$(dirCommit "$arch/$winVariant")"
cat <<-EOE
windows-$arch-GitCommit: $commit
windows-$arch-Directory: $arch/$image/$winVariant
windows-$arch-Directory: $arch/$winVariant
EOE
done
cat <<-EOE
Expand Down
1 change: 0 additions & 1 deletion greetings/hello-world.txt

This file was deleted.

12 changes: 2 additions & 10 deletions hello.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
#include <sys/syscall.h>
#include <unistd.h>

#ifndef DOCKER_IMAGE
#define DOCKER_IMAGE "hello-world"
#endif

#ifndef DOCKER_GREETING
#define DOCKER_GREETING "Hello from Docker!"
#endif

#ifndef DOCKER_ARCH
#define DOCKER_ARCH "amd64"
#endif

const char message[] =
"\n"
DOCKER_GREETING "\n"
"Hello from Docker!\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"
" 2. The Docker daemon pulled the \"hello-world\" image from the Docker Hub.\n"
" (" DOCKER_ARCH ")\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"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ docker run --rm hello-world:build sh -c 'find \( -name hello -or -name hello.txt
find -name hello -type f -exec dirname '{}' ';' | xargs -n1 -i'{}' cp Dockerfile-linux.template '{}/Dockerfile'
find -name hello.txt -type f -exec dirname '{}' ';' | xargs -n1 -i'{}' cp Dockerfile-windows.template '{}/Dockerfile'

for h in */*/nanoserver-*/Dockerfile; do
for h in */nanoserver-*/Dockerfile; do
nano="$(dirname "$h")"
nano="$(basename "$nano")"
nano="${nano#nanoserver-}"
sed -i 's!FROM .*!FROM mcr.microsoft.com/windows/nanoserver:'"$nano"'!' "$h"
done

for h in .host-arch/*/hello; do
for h in .host-arch/hello; do
d="$(dirname "$h")"
b="$(basename "$d")"
"$h" > /dev/null
docker build -t hello-world:"test-$b" "$d"
docker run --rm hello-world:"test-$b"
done

ls -lh */*/{hello,nanoserver*/hello.txt} || :
ls -lh */{hello,nanoserver*/hello.txt} || :
Loading