Use Bazel to build Docker image
This commit is contained in:
parent
3b309ad1af
commit
b0e61af98b
|
@ -1,5 +1,10 @@
|
|||
*
|
||||
!Plugins
|
||||
!.bazelrc
|
||||
!.bazelversion
|
||||
!bazel
|
||||
!tools/bazelw
|
||||
!BUILD
|
||||
!ci.bazelrc
|
||||
!MODULE.bazel
|
||||
!Source
|
||||
!Tests
|
||||
!Package.*
|
||||
!WORKSPACE
|
||||
|
|
|
@ -29,17 +29,29 @@ jobs:
|
|||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
uses: docker/setup-buildx-action@v2
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
- name: Log in to GitHub registry
|
||||
uses: docker/login-action@v1
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
registry: ghcr.io
|
||||
- uses: docker/build-push-action@v2
|
||||
- name: Configure BuildBuddy
|
||||
run: |
|
||||
cat > ci.bazelrc <<EOF
|
||||
build --bes_results_url=https://app.buildbuddy.io/invocation/
|
||||
build --bes_backend=grpcs://remote.buildbuddy.io
|
||||
build --remote_cache=grpcs://remote.buildbuddy.io
|
||||
build --remote_timeout=3600
|
||||
build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY
|
||||
EOF
|
||||
env:
|
||||
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
|
||||
- uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ env.DOCKER_TAG }}
|
||||
|
|
30
Dockerfile
30
Dockerfile
|
@ -1,24 +1,22 @@
|
|||
# Explicitly specify `jammy` to keep the Swift & Ubuntu images in sync.
|
||||
ARG BUILDER_IMAGE=swift:jammy
|
||||
ARG RUNTIME_IMAGE=ubuntu:jammy
|
||||
ARG BUILDER_IMAGE=swift:focal
|
||||
ARG RUNTIME_IMAGE=ubuntu:focal
|
||||
|
||||
# builder image
|
||||
FROM ${BUILDER_IMAGE} AS builder
|
||||
RUN apt-get update && apt-get install -y \
|
||||
curl \
|
||||
libcurl4-openssl-dev \
|
||||
libxml2-dev \
|
||||
&& rm -r /var/lib/apt/lists/*
|
||||
WORKDIR /workdir/
|
||||
COPY Plugins Plugins/
|
||||
COPY Source Source/
|
||||
COPY Tests Tests/
|
||||
COPY Package.* ./
|
||||
ENV CC=clang
|
||||
COPY . .
|
||||
|
||||
RUN ./tools/bazelw build --config release swiftlint
|
||||
|
||||
RUN swift package update
|
||||
ARG SWIFT_FLAGS="-c release -Xswiftc -static-stdlib -Xlinker -lCFURLSessionInterface -Xlinker -lCFXMLInterface -Xlinker -lcurl -Xlinker -lxml2 -Xswiftc -I. -Xlinker -fuse-ld=lld -Xlinker -L/usr/lib/swift/linux"
|
||||
RUN swift build $SWIFT_FLAGS --product swiftlint
|
||||
RUN mkdir -p /executables
|
||||
RUN install -v `swift build $SWIFT_FLAGS --show-bin-path`/swiftlint /executables
|
||||
RUN mv bazel-bin/swiftlint /executables
|
||||
|
||||
# runtime image
|
||||
FROM ${RUNTIME_IMAGE}
|
||||
|
@ -30,10 +28,20 @@ RUN apt-get update && apt-get install -y \
|
|||
COPY --from=builder /usr/lib/libsourcekitdInProc.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libBlocksRuntime.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libdispatch.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libFoundation.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libFoundationNetworking.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libFoundationXML.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libicudataswift.so.65 /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libicui18nswift.so.65 /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libicuucswift.so.65 /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libswift_Concurrency.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libswift_RegexParser.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libswift_StringProcessing.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libswiftCore.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libswiftDispatch.so /usr/lib
|
||||
COPY --from=builder /usr/lib/swift/linux/libswiftGlibc.so /usr/lib
|
||||
COPY --from=builder /executables/* /usr/bin
|
||||
|
||||
RUN swiftlint version
|
||||
RUN echo "_ = 0" | swiftlint --use-stdin
|
||||
|
||||
CMD ["swiftlint"]
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
readonly bazelisk_version="1.15.0"
|
||||
|
||||
if [[ $OSTYPE == darwin* ]]; then
|
||||
readonly bazel_os="darwin"
|
||||
else
|
||||
readonly bazel_os="linux"
|
||||
fi
|
||||
|
||||
raw_arch="$(uname -m)"
|
||||
readonly raw_arch
|
||||
|
||||
if [[ -n "${BAZELW_ARCH+x}" ]]; then
|
||||
readonly bazel_arch="${BAZELW_ARCH}"
|
||||
elif [[ "$raw_arch" == "aarch64" || "$raw_arch" == "arm64" ]]; then
|
||||
readonly bazel_arch="arm64"
|
||||
else
|
||||
readonly bazel_arch="amd64"
|
||||
fi
|
||||
|
||||
bazel_platform="$bazel_os-$bazel_arch"
|
||||
case "$bazel_platform" in
|
||||
darwin-arm64)
|
||||
readonly bazel_version_sha="dfc36f30c1d5f86d72c9870cdeb995ac894787887089fd9b61e64f27c8bc184c"
|
||||
;;
|
||||
darwin-amd64)
|
||||
readonly bazel_version_sha="cf876f4303223e6b1867db6c30c55b5bc0208d7c8003042a9872b8ec112fd3c0"
|
||||
;;
|
||||
linux-arm64)
|
||||
readonly bazel_version_sha="3862ab0857b776411906d0a65215509ca72f6d4923f01807e11299a8d419db80"
|
||||
;;
|
||||
linux-amd64)
|
||||
readonly bazel_version_sha="19fd84262d5ef0cb958bcf01ad79b528566d8fef07ca56906c5c516630a0220b"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unsupported platform $OSTYPE $raw_arch" >&2
|
||||
exit 1
|
||||
esac
|
||||
|
||||
readonly bazel_version_url="https://github.com/bazelbuild/bazelisk/releases/download/v$bazelisk_version/bazelisk-$bazel_platform"
|
||||
script_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
readonly bazelisk="$script_root/tmp/bazel/versions/bazelisk-$bazelisk_version-$bazel_platform"
|
||||
|
||||
if [[ ! -x "$bazelisk" ]]; then
|
||||
echo "Installing bazelisk..." >&2
|
||||
mkdir -p "$(dirname "$bazelisk")"
|
||||
|
||||
download_bazelisk() {
|
||||
curl --fail -L --retry 5 --retry-connrefused --silent --progress-bar \
|
||||
--output "$bazelisk" "$bazel_version_url"
|
||||
}
|
||||
|
||||
download_bazelisk || download_bazelisk
|
||||
if echo "$bazel_version_sha $bazelisk" | shasum --check --status; then
|
||||
chmod +x "$bazelisk"
|
||||
else
|
||||
echo "Bazelisk sha mismatch" >&2
|
||||
rm -f "$bazelisk"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
exec "$bazelisk" "$@"
|
Loading…
Reference in New Issue