Skip to content

Commit

Permalink
Merge pull request #164 from tonistiigi/tonistiigi/20240619-deps-updates
Browse files Browse the repository at this point in the history
update dockerfile and linting dependencies
  • Loading branch information
crazy-max authored Jun 20, 2024
2 parents 33808b0 + 6d7ca78 commit aea9196
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 57 deletions.
2 changes: 1 addition & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ variable "TEST_BASE_TYPE" {
}

variable "TEST_BASE_IMAGE" {
default = TEST_BASE_TYPE == "alpine" ? "alpine:3.19" : TEST_BASE_TYPE == "debian" ? "debian:bookworm" : null
default = TEST_BASE_TYPE == "alpine" ? "alpine:3.20" : TEST_BASE_TYPE == "debian" ? "debian:bookworm" : null
}

variable "DEV_SDK_PLATFORM" {
Expand Down
9 changes: 5 additions & 4 deletions hack/dockerfiles/shellcheck.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# syntax = docker/dockerfile:1.5
FROM koalaman/shellcheck-alpine:v0.7.2
# syntax=docker/dockerfile:1.8
# check=error=true

FROM koalaman/shellcheck-alpine:v0.10.0
WORKDIR /src
COPY src .
RUN shellcheck xx-*
RUN --mount=type=bind,src=src shellcheck xx-*
32 changes: 23 additions & 9 deletions hack/dockerfiles/shfmt.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
# syntax = docker/dockerfile:1.5
FROM mvdan/shfmt:v3.2.1-alpine AS shfmt
# syntax=docker/dockerfile:1.8
# check=error=true

FROM mvdan/shfmt:v3.8.0-alpine AS shfmt
WORKDIR /src
ARG SHFMT_FLAGS="-i 2 -ci"

FROM shfmt AS generate
WORKDIR /out
RUN --mount=target=/src \
cp -a /src/* ./ && \
shfmt -l -w -ln posix $SHFMT_FLAGS . && \
for f in */test-*.bats; do shfmt -l -w -ln bats $SHFMT_FLAGS "$f"; done
RUN --mount=target=/src <<EOF
set -ex
cp -a /src/* ./
for f in */xx-*; do
shfmt -l -w -ln posix $SHFMT_FLAGS "$f";
done
for f in */test-*.bats; do
shfmt -l -w -ln bats $SHFMT_FLAGS "$f";
done
EOF

FROM scratch AS update
COPY --from=generate /out /

FROM shfmt AS validate
RUN --mount=target=. \
shfmt -ln posix $SHFMT_FLAGS -d . && \
for f in */test-*.bats; do shfmt -ln bats $SHFMT_FLAGS -d "$f" || return; done;
RUN --mount=type=bind <<EOF
set -ex
for f in */xx-*; do
shfmt -ln posix $SHFMT_FLAGS -d "$f"
done
for f in */test-*.bats; do
shfmt -ln bats $SHFMT_FLAGS -d "$f"
done
EOF
5 changes: 3 additions & 2 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# syntax=docker/dockerfile:1.5
# syntax=docker/dockerfile:1.8
# check=error=true

ARG TEST_BASE_TYPE=alpine
ARG TEST_BASE_IMAGE=${TEST_BASE_TYPE}
Expand Down Expand Up @@ -113,4 +114,4 @@ COPY fixtures fixtures
COPY *.bats test_helper.bash ./

# default is alias to build xx image
FROM xx as default
FROM xx AS default
13 changes: 8 additions & 5 deletions src/ld/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#syntax=docker/dockerfile:1.5
#syntax=docker/dockerfile:1.8
#check=error=true

ARG ALPINE_VERSION=3.20
ARG LIBTAPI_VERSION=1300.6.5
Expand All @@ -14,8 +15,9 @@ FROM --platform=${BUILDPLATFORM} alpine:${ALPINE_VERSION} AS libtapi-base
RUN apk add --no-cache git clang lld cmake make python3 bash
COPY --link --from=xx / /
ARG LIBTAPI_VERSION
WORKDIR /work
RUN git clone https://github.com/tpoechtrager/apple-libtapi --depth 1 -b ${LIBTAPI_VERSION}
WORKDIR ./apple-libtapi
WORKDIR apple-libtapi
RUN --mount=target=/tmp/libtapi-cmake-args.patch,source=libtapi-cmake-args.patch \
git apply /tmp/libtapi-cmake-args.patch
RUN apk add --no-cache gcc g++
Expand Down Expand Up @@ -61,11 +63,12 @@ FROM --platform=${BUILDPLATFORM} alpine:${ALPINE_VERSION} AS libdispatch-base
RUN apk add git clang lld cmake samurai patch
ARG LIBDISPATCH_VERSION
COPY --link --from=xx / /
WORKDIR /work
RUN --mount=target=/patches,from=patches-libdispatch \
git clone -b ${LIBDISPATCH_VERSION} --depth 1 https://github.com/apple/swift-corelibs-libdispatch.git && \
cd swift-corelibs-libdispatch && \
for f in /patches/*; do patch -p1 < $f; done
WORKDIR ./swift-corelibs-libdispatch
WORKDIR swift-corelibs-libdispatch
ARG TARGETPLATFORM
RUN xx-apk add --no-cache gcc g++ musl-dev linux-headers bsd-compat-headers
RUN cmake $(xx-clang --print-cmake-defines) -G Ninja -B build -DCMAKE_INSTALL_PREFIX=/out/libdispatch -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=False -DCMAKE_BUILD_TYPE=MinSizeRel && \
Expand All @@ -85,7 +88,7 @@ WORKDIR /work
ARG CCTOOLS_REPO=https://github.com/tpoechtrager/cctools-port
ARG CCTOOLS_VERSION
RUN git clone $CCTOOLS_REPO -b ${CCTOOLS_VERSION}
WORKDIR ./cctools-port/cctools
WORKDIR cctools-port/cctools
ARG TARGETPLATFORM
RUN --mount=target=/libdispatch,from=libdispatch \
xx-apk add --no-cache musl-dev gcc g++ libdispatch-dev && \
Expand Down Expand Up @@ -129,7 +132,7 @@ ARG SIGTOOL_VERSION
RUN git clone https://github.com/thefloweringash/sigtool && \
cd sigtool && \
git checkout ${SIGTOOL_VERSION}
WORKDIR ./sigtool
WORKDIR sigtool
RUN --mount=target=/tmp/sigtool-static.patch,source=sigtool-static.patch \
git apply /tmp/sigtool-static.patch
ARG TARGETPLATFORM
Expand Down
3 changes: 2 additions & 1 deletion src/llvm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#syntax=docker/dockerfile:1.5
#syntax=docker/dockerfile:1.8
#check=error=true

FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx

Expand Down
14 changes: 7 additions & 7 deletions src/xx-cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ setup() {
if [ "$exp" = "riscv64" ]; then
exp="riscv"
fi
if ld -V 2>/dev/null | grep $exp >/dev/null; then
if ld -V 2>/dev/null | grep "$exp" >/dev/null; then
ln -s "$(command -v ld)" "/usr/bin/${target}-ld"
linker="/usr/bin/${target}-ld"
XX_CC_PREFER_LINKER=
Expand Down Expand Up @@ -538,7 +538,7 @@ EOT
}

check_compiler() {
if [ ! -f /usr/bin/$name ]; then
if [ ! -f "/usr/bin/$name" ]; then
echo >&2 "/usr/bin/$name not found. Make sure package is installed. xx doesn't currently support binaries in custom location"
exit
fi
Expand All @@ -560,7 +560,7 @@ downloadLD=
for p in "$@"; do
# ignore if custom --config already set
if [ "${p}" = "--config" ]; then
exec /usr/bin/$name "$@"
exec "/usr/bin/$name" "$@"
fi
if [ "${p}" = "--print-target-triple" ] || [ "${p}" = "-print-target-triple" ]; then
printTarget=1
Expand Down Expand Up @@ -667,15 +667,15 @@ if [ -z "${target}" ] && [ ! -f /etc/llvm/xx-default.cfg ] && [ -n "$wrapped" ];
setup
fi

if [ ! -f /usr/bin/$name ]; then
if [ ! -f "/usr/bin/$name" ]; then
echo >&2 "/usr/bin/$name not found. Make sure package is installed. xx doesn't currently support binaries in custom location"
exit
fi

if [ -z "$target" ] && [ -f /etc/llvm/xx-default.cfg ]; then
exec /usr/bin/$name --config /etc/llvm/xx-default.cfg "$@"
exec "/usr/bin/$name" --config /etc/llvm/xx-default.cfg "$@"
elif [ -f "/usr/bin/${target}.cfg" ]; then
exec /usr/bin/$name --config "/usr/bin/${target}.cfg" "$@"
exec "/usr/bin/$name" --config "/usr/bin/${target}.cfg" "$@"
else
exec /usr/bin/$name "$@"
exec "/usr/bin/$name" "$@"
fi
18 changes: 9 additions & 9 deletions src/xx-go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ for l in $(xx-info env); do
export "${l?}"
done

export GOOS=${TARGETOS}
export GOARCH=${TARGETARCH}
export GOOS="${TARGETOS}"
export GOARCH="${TARGETARCH}"

case "$TARGETARCH" in
"amd64")
Expand Down Expand Up @@ -67,37 +67,37 @@ ar_set=
pkgconfig_set=

if command -v "$XX_TRIPLE-gcc" >/dev/null 2>/dev/null; then
export CC=$XX_TRIPLE-gcc
export CC="$XX_TRIPLE-gcc"
c_set=1
fi

if command -v "$XX_TRIPLE-g++" >/dev/null 2>/dev/null; then
export CXX=$XX_TRIPLE-g++
export CXX="$XX_TRIPLE-g++"
cxx_set=1
fi

if command -v clang >/dev/null 2>/dev/null; then
triple=$(xx-clang --print-target-triple || true)
if [ -n "$triple" ]; then
export CC=$triple-clang
export CXX=$triple-clang++
export CC="$triple-clang"
export CXX="$triple-clang++"
c_set=1
cxx_set=1
fi
fi

if command -v "$XX_TRIPLE-ar" >/dev/null 2>/dev/null; then
export AR=$XX_TRIPLE-ar
export AR="$XX_TRIPLE-ar"
ar_set=1
fi

if command -v "$XX_TRIPLE-pkg-config" >/dev/null 2>/dev/null; then
export PKG_CONFIG=$XX_TRIPLE-pkg-config
export PKG_CONFIG="$XX_TRIPLE-pkg-config"
pkgconfig_set=1
fi

if [ -z "$GOBIN" ] && [ -n "$GOPATH" ] && [ -n "$GOARCH" ] && [ -n "$GOOS" ]; then
export PATH=${GOPATH}/bin/${GOOS}_${GOARCH}:${PATH}
export PATH="${GOPATH}/bin/${GOOS}_${GOARCH}:${PATH}"
fi

wrap() {
Expand Down
28 changes: 14 additions & 14 deletions src/xx-info
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ fi

# break up TARGETPLATFORM if provided
if [ -n "$TARGETPLATFORM" ]; then
os="$(echo $TARGETPLATFORM | cut -d"/" -f1)"
arch="$(echo $TARGETPLATFORM | cut -d"/" -f2)"
os="$(echo "$TARGETPLATFORM" | cut -d"/" -f1)"
arch="$(echo "$TARGETPLATFORM" | cut -d"/" -f2)"
if [ -n "$os" ] && [ -n "$arch" ]; then
TARGETOS="$os"
TARGETARCH="$arch"
case "$arch" in
"amd64")
case "$(echo $TARGETPLATFORM | cut -d"/" -f3)" in
case "$(echo "$TARGETPLATFORM" | cut -d"/" -f3)" in
"v2")
TARGETVARIANT="v2"
;;
Expand All @@ -96,7 +96,7 @@ if [ -n "$TARGETPLATFORM" ]; then
esac
;;
"arm")
case "$(echo $TARGETPLATFORM | cut -d"/" -f3)" in
case "$(echo "$TARGETPLATFORM" | cut -d"/" -f3)" in
"v5")
TARGETVARIANT="v5"
;;
Expand All @@ -112,7 +112,7 @@ if [ -n "$TARGETPLATFORM" ]; then
esac
;;
"mips"*)
TARGETVARIANT="$(echo $TARGETPLATFORM | cut -d"/" -f3)"
TARGETVARIANT="$(echo "$TARGETPLATFORM" | cut -d"/" -f3)"
;;
esac
fi
Expand Down Expand Up @@ -375,31 +375,31 @@ case "$1" in
fi
;;
"arch")
echo $TARGETARCH
echo "$TARGETARCH"
;;
"variant")
echo $TARGETVARIANT
echo "$TARGETVARIANT"
;;
"os")
echo $TARGETOS # TODO:
echo "$TARGETOS" # TODO:
;;
"os-version")
echo "$XX_OS_VERSION"
;;
"march")
echo $XX_MARCH
echo "$XX_MARCH"
;;
"debian-arch")
echo $XX_DEBIAN_ARCH
echo "$XX_DEBIAN_ARCH"
;;
"alpine-arch")
echo $XX_ALPINE_ARCH
echo "$XX_ALPINE_ARCH"
;;
"rhel-arch")
echo $XX_RHEL_ARCH
echo "$XX_RHEL_ARCH"
;;
"pkg-arch")
echo $XX_PKG_ARCH
echo "$XX_PKG_ARCH"
;;
"triple")
echo "$XX_TRIPLE"
Expand All @@ -408,7 +408,7 @@ case "$1" in
echo "$XX_VENDOR"
;;
"libc") # this is not abi, just the prefix
echo $XX_LIBC
echo "$XX_LIBC"
;;
"env")
echo "XX_OS=${TARGETOS}"
Expand Down
4 changes: 2 additions & 2 deletions src/xx-windres
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,14 @@ else
fi

if [ "$outputf" = "res" ]; then
run cp $resfile $output
run cp "$resfile" "$output"
else
if ! command -v llvm-cvtres 2>/dev/null >/dev/null; then
echo >&2 "llvm-cvtres not installed"
exit 1
fi

run llvm-cvtres -machine:$machine -out:$output $resfile
run llvm-cvtres -machine:$machine "-out:$output" "$resfile"
fi

if [ -f "$tmpfile" ]; then
Expand Down
9 changes: 7 additions & 2 deletions util/bats-assert/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
FROM --platform=$BUILDPLATFORM alpine AS build
#syntax=docker/dockerfile:1.8
#check=error=true

ARG ALPINE_VERSION=3.20

FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS build
RUN apk add --no-cache git
WORKDIR /work
RUN git clone --bare https://github.com/ztombol/bats-support && \
Expand All @@ -16,7 +21,7 @@ RUN echo 'source "$(dirname "${BASH_SOURCE[0]}")/bats-support/load.bash"' > /out
FROM scratch AS release
COPY --from=build /out /

FROM alpine:3.19 AS test-gen
FROM alpine:${ALPINE_VERSION} AS test-gen
RUN apk add --no-cache bats
WORKDIR /work
COPY --from=release . .
Expand Down
2 changes: 1 addition & 1 deletion util/bats-assert/test.bats.golden
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ not ok 5 run-fail

The following warnings were encountered during tests:
BW01: `run`'s command `./foobar` exited with code 127, indicating 'Command not found'. Use run's return code checks, e.g. `run -127`, to fix this message.
(from function `run' in file /usr/lib/bats-core/test_functions.bash, line 421,
(from function `run' in file /usr/lib/bats-core/test_functions.bash, line 426,
in test file test.bats, line 15)

0 comments on commit aea9196

Please sign in to comment.