Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Swift Support #364

Merged
merged 26 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cfb1c80
Add Swift Dependencies
SimonRice Dec 29, 2019
ba0c352
Add Swift Version parameter to start image
SimonRice Dec 29, 2019
42ffdb0
Add Swift Version to test-build
SimonRice Dec 29, 2019
b455980
Swift install
SimonRice Dec 29, 2019
3512229
Swift Env Vars Correction
SimonRice Dec 29, 2019
1b5ca2e
Remove extra quote mark
SimonRice Dec 29, 2019
9128838
Temporarily skip verification of Swift
SimonRice Dec 29, 2019
5df930d
Reinstated GPG Swift checks
SimonRice Dec 29, 2019
9b922ad
Removed Swift keys from apt-key stages
SimonRice Dec 29, 2019
a22251e
Unsilencing cURL
SimonRice Dec 29, 2019
f0c33e3
SPM/Swift Caching
SimonRice Dec 29, 2019
7b5ccb6
Minor Swift changes
SimonRice Dec 29, 2019
af2d276
Swift cachability
SimonRice Dec 29, 2019
e80ce69
Remove SWIFT_VERSION parameter
SimonRice Dec 31, 2019
af61e16
Added Swiftenv
SimonRice Jan 2, 2020
aae1d18
Use Swiftenv as part of build
SimonRice Jan 3, 2020
bf2d026
Swiftenv fixes
SimonRice Jan 3, 2020
84429f2
Added Swift to included software docs
SimonRice Jan 3, 2020
4fb8898
Used skip if installed swiftenv parameter
SimonRice Jan 4, 2020
0254532
Extracted out Docker Swift version to its own env variable
SimonRice Jan 6, 2020
3f270f0
Removed extra space from run build script
SimonRice Jan 6, 2020
a300cdf
Rehash cached Swift build
SimonRice Jan 6, 2020
d71ef1e
Removed unnecessary clang dependency
SimonRice Mar 1, 2020
c82fb19
Renamed env variable to NETLIFY_BUILD_SWIFT_VERSION, to be consistent…
SimonRice Mar 1, 2020
8893e9a
Swift 5.2 update
SimonRice Mar 26, 2020
c31a76c
Document that versions of Swift 4.x and older will not run
Benaiah Apr 24, 2020
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
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,21 @@ ENV PATH "$PATH:/opt/buildhome/.dotnet"
ENV DOTNET_ROOT "/opt/buildhome/.dotnet"
#populate local package cache
RUN dotnet new


################################################################################
#
# Swift
#
################################################################################
USER buildbot
ENV NETLIFY_BUILD_SWIFT_VERSION 5.2
ENV SWIFTENV_ROOT "/opt/buildhome/.swiftenv"
RUN git clone --depth 1 https://github.com/kylef/swiftenv.git "$SWIFTENV_ROOT"
ENV PATH "$SWIFTENV_ROOT/bin:$SWIFTENV_ROOT/shims:$PATH"
RUN swiftenv install ${NETLIFY_BUILD_SWIFT_VERSION}
RUN swift --version

WORKDIR /

# Cleanup
Expand Down
3 changes: 3 additions & 0 deletions included_software.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ The specific patch versions included will depend on when the image was last buil
* 7.4
* Go - `GO_VERSION`
* 1.12 (default)
* Swift - `SWIFT_VERSION`, `.swift-version`
* 5.2 (default)
* Any version that `swiftenv` can install.
* Java
* 8 (default)
* Emacs
Expand Down
63 changes: 62 additions & 1 deletion run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export GIMME_CGO_ENABLED=true

export NVM_DIR="$HOME/.nvm"
export RVM_DIR="$HOME/.rvm"
export SWIFTENV_ROOT="${SWIFTENV_ROOT:-${HOME}/.swiftenv}"

# Pipenv configuration
export PIPENV_RUNTIME=2.7
Expand All @@ -32,13 +33,15 @@ NC="\033[0m" # No Color
# language versions
mkdir -p $NETLIFY_CACHE_DIR/node_version
mkdir -p $NETLIFY_CACHE_DIR/ruby_version
mkdir -p $NETLIFY_CACHE_DIR/swift_version

# pwd caches
mkdir -p $NETLIFY_CACHE_DIR/node_modules
mkdir -p $NETLIFY_CACHE_DIR/.bundle
mkdir -p $NETLIFY_CACHE_DIR/bower_components
mkdir -p $NETLIFY_CACHE_DIR/.venv
mkdir -p $NETLIFY_CACHE_DIR/wapm_packages
mkdir -p $NETLIFY_CACHE_DIR/.build

# HOME caches
mkdir -p $NETLIFY_CACHE_DIR/.yarn_cache
Expand Down Expand Up @@ -162,6 +165,7 @@ install_dependencies() {
local defaultYarnVersion=$3
local defaultPHPVersion=$4
local installGoVersion=$5
local defaultSwiftVersion=$6

# Python Version
if [ -f runtime.txt ]
Expand Down Expand Up @@ -401,6 +405,48 @@ install_dependencies() {
fi
fi

# Swift Version
: ${SWIFT_VERSION="$defaultSwiftVersion"}
if [ -f .swift-version ]
then
SWIFT_VERSION=$(cat .swift-version)
echo "Attempting Swift version '$SWIFT_VERSION' from .swift-version"
fi

swiftenv global ${SWIFT_VERSION} > /dev/null 2>&1
export CUSTOM_SWIFT=$?

if [ -d $NETLIFY_CACHE_DIR/swift_version/$SWIFT_VERSION ]
then
echo "Started restoring cached Swift version"
rm -rf $SWIFTENV_ROOT/versions/$SWIFT_VERSION
cp -p -r $NETLIFY_CACHE_DIR/swift_version/${SWIFT_VERSION} $SWIFTENV_ROOT/versions/
swiftenv rehash
echo "Finished restoring cached Swift version"
fi

if swiftenv install -s $SWIFT_VERSION
then
echo "Using Swift version $SWIFT_VERSION"
else
echo "Failed to install Swift version '$SWIFT_VERSION'"
exit 1
fi

# SPM dependencies
if [ -f Package.swift ]
then
echo "Building Swift Package"
restore_cwd_cache ".build" "swift build"
if swift build
then
echo "Swift package Built"
else
echo "Error building Swift package"
exit 1
fi
fi

# NPM Dependencies
: ${YARN_VERSION="$defaultYarnVersion"}

Expand Down Expand Up @@ -627,7 +673,8 @@ cache_artifacts() {
cache_cwd_directory "bower_components" "bower components"
cache_cwd_directory "node_modules" "node modules"
cache_cwd_directory ".venv" "python virtualenv"
cache_cwd_directory "wapm_packages", "wapm packages"
cache_cwd_directory "wapm_packages" "wapm packages"
cache_cwd_directory ".build" "swift build"

cache_home_directory ".yarn_cache" "yarn cache"
cache_home_directory ".cache" "pip cache"
Expand Down Expand Up @@ -669,6 +716,20 @@ cache_artifacts() {
else
rm -rf $NETLIFY_CACHE_DIR/ruby_version
fi

# cache the version of Swift installed
if [[ "$CUSTOM_SWIFT" -ne "0" ]]
then
if ! [ -d $NETLIFY_CACHE_DIR/swift_version/$SWIFT_VERSION ]
then
rm -rf $NETLIFY_CACHE_DIR/swift_version
mkdir $NETLIFY_CACHE_DIR/swift_version
mv $SWIFTENV_ROOT/versions/$SWIFT_VERSION $NETLIFY_CACHE_DIR/swift_version/
echo "Cached Swift version $SWIFT_VERSION"
fi
else
rm -rf $NETLIFY_CACHE_DIR/swift_version
fi
}

move_cache() {
Expand Down
3 changes: 2 additions & 1 deletion run-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ cd $NETLIFY_REPO_DIR
: ${YARN_VERSION="1.13.0"}
: ${PHP_VERSION="5.6"}
: ${GO_VERSION="1.12"}
: ${SWIFT_VERSION="5.2"}

echo "Installing dependencies"
install_dependencies $NODE_VERSION $RUBY_VERSION $YARN_VERSION $PHP_VERSION $GO_VERSION
install_dependencies $NODE_VERSION $RUBY_VERSION $YARN_VERSION $PHP_VERSION $GO_VERSION $SWIFT_VERSION

echo "Installing missing commands"
install_missing_commands
Expand Down
1 change: 1 addition & 0 deletions test-tools/start-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ docker run --rm -t -i \
-e HUGO_VERSION \
-e PHP_VERSION \
-e GO_VERSION \
-e SWIFT_VERSION \
-v ${REPO_PATH}:/opt/repo \
-v ${BASE_PATH}/run-build.sh:/usr/local/bin/build \
-v ${BASE_PATH}/run-build-functions.sh:/usr/local/bin/run-build-functions.sh \
Expand Down
2 changes: 2 additions & 0 deletions test-tools/test-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fi
: ${HUGO_VERSION="0.54.0"}
: ${PHP_VERSION="5.6"}
: ${GO_VERSION="1.12"}
: ${SWIFT_VERSION="5.2"}

BASE_PATH=$(pwd)
REPO_PATH="$(cd $1 && pwd)"
Expand Down Expand Up @@ -51,6 +52,7 @@ docker run --rm \
-e NETLIFY_VERBOSE \
-e GO_VERSION \
-e GO_IMPORT_PATH \
-e SWIFT_VERSION \
-v "${REPO_PATH}:/opt/repo" \
-v "${BASE_PATH}/run-build.sh:/usr/local/bin/build" \
-v "${BASE_PATH}/run-build-functions.sh:/usr/local/bin/run-build-functions.sh" \
Expand Down