Skip to content

Commit

Permalink
Build additional Docker image with Swift 5.5 (realm#3904)
Browse files Browse the repository at this point in the history
* Build additional Docker image with Swift 5.5
* Build `swiftlint_linux_swift_5_5.zip`
  • Loading branch information
jpsim authored and coffmark committed Apr 11, 2022
1 parent dd4830d commit c161ea0
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,41 @@ jobs:
with:
push: true
tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ env.DOCKER_TAG }}

build_5_5:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Extract DOCKER_TAG using tag name
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "DOCKER_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Use default DOCKER_TAG
if: startsWith(github.ref, 'refs/tags/') != true
run: |
echo "DOCKER_TAG=latest" >> $GITHUB_ENV
- name: Set lowercase repository name
run: |
echo "REPOSITORY_LC=${REPOSITORY,,}" >>${GITHUB_ENV}
env:
REPOSITORY: '${{ github.repository }}'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Github registry
uses: docker/login-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io

- uses: docker/build-push-action@v2
with:
push: true
file: Dockerfile@swift-5.5
tags: ghcr.io/${{ env.REPOSITORY_LC }}:5.5-${{ env.DOCKER_TAG }}
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ xcuserdata
# SwiftLint

SwiftLint.pkg
SwiftLintFramework.framework.zip
*.zip
benchmark_*
portable_swiftlint.zip
swiftlint_linux.zip
osscheck/
docs/
rule_docs/
Expand Down
40 changes: 40 additions & 0 deletions Dockerfile@swift-5.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Explicitly specify `focal` because `swift:latest` does not use `ubuntu:latest`.
ARG BUILDER_IMAGE=swift:5.5-focal
ARG RUNTIME_IMAGE=ubuntu:focal

# builder image
FROM ${BUILDER_IMAGE} AS builder
RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libxml2-dev \
&& rm -r /var/lib/apt/lists/*
WORKDIR /workdir/
COPY Source Source/
COPY Tests Tests/
COPY Package.* ./

RUN ln -s /usr/lib/swift/_InternalSwiftSyntaxParser .

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
RUN mkdir -p /executables
RUN for executable in $(swift package completion-tool list-executables); do \
install -v `swift build $SWIFT_FLAGS --show-bin-path`/$executable /executables; \
done

# runtime image
FROM ${RUNTIME_IMAGE}
LABEL org.opencontainers.image.source https://github.com/realm/SwiftLint
RUN apt-get update && apt-get install -y \
libcurl4 \
libxml2 \
&& rm -r /var/lib/apt/lists/*
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/lib_InternalSwiftSyntaxParser.so /usr/lib
COPY --from=builder /executables/* /usr/bin

RUN swiftlint version

CMD ["swiftlint"]
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ zip_linux_release:
cp -f "$(LICENSE_PATH)" "$(TMP_FOLDER)"
(cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "LICENSE") > "./swiftlint_linux.zip"

zip_linux_release_5_5:
$(eval TMP_FOLDER := $(shell mktemp -d))
docker run ghcr.io/realm/swiftlint:5.5-$(VERSION_STRING) cat /usr/bin/swiftlint > "$(TMP_FOLDER)/swiftlint"
chmod +x "$(TMP_FOLDER)/swiftlint"
cp -f "$(LICENSE_PATH)" "$(TMP_FOLDER)"
(cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "LICENSE") > "./swiftlint_linux_swift_5_5.zip"

package: build
$(eval PACKAGE_ROOT := $(shell mktemp -d))
cp "$(SWIFTLINT_EXECUTABLE)" "$(PACKAGE_ROOT)"
Expand All @@ -128,7 +135,7 @@ package: build
--version $(VERSION_STRING) \
"$(OUTPUT_PACKAGE)"

release: package portable_zip zip_linux_release
release: package portable_zip zip_linux_release zip_linux_release_5_5

docker_image:
docker build --platform linux/amd64 --force-rm --tag swiftlint .
Expand Down

0 comments on commit c161ea0

Please sign in to comment.