Skip to content

Commit b8a6466

Browse files
authored
add docker support (#15)
motivation: enable CI changes: add docker files support for ubuntu 16.04 and 18.04 and swift 5.0 and 5.1 note that eventyally this will need to move to AL2 docker images, but we dont have official ones yet
1 parent 95cf94e commit b8a6466

File tree

9 files changed

+126
-10
lines changed

9 files changed

+126
-10
lines changed

Sources/SwiftAwsLambda/HttpClient.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ internal class HTTPClient {
4646
timeout: timeout ?? self.configuration.requestTimeout))
4747
}
4848

49-
5049
private func execute(_ request: Request) -> EventLoopFuture<Response> {
5150
self.lock.lock()
5251
switch self.state {
@@ -85,15 +84,15 @@ internal class HTTPClient {
8584
UnaryHandler(keepAlive: self.configuration.keepAlive)])
8685
}
8786
}
88-
87+
8988
do {
9089
// connect directly via socket address to avoid happy eyeballs (perf)
9190
let address = try SocketAddress(ipAddress: self.configuration.ip, port: self.configuration.port)
9291
return bootstrap.connect(to: address).flatMapThrowing { channel in
9392
self.state = .connected(channel)
9493
}
9594
} catch {
96-
return eventLoop.makeFailedFuture(error)
95+
return self.eventLoop.makeFailedFuture(error)
9796
}
9897
}
9998

Sources/SwiftAwsLambda/Lambda.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import Darwin.C
1919
#endif
2020

2121
import Backtrace
22+
import Dispatch
2223
import Logging
2324
import NIO
2425
import NIOConcurrencyHelpers
25-
import Dispatch
2626

2727
public enum Lambda {
2828
/// Run a Lambda defined by implementing the `LambdaClosure` closure.
@@ -203,7 +203,7 @@ public enum Lambda {
203203

204204
init(id: String? = nil, maxTimes: Int? = nil, stopSignal: Signal? = nil) {
205205
self.id = id ?? "\(DispatchTime.now().uptimeNanoseconds)"
206-
self.maxTimes = maxTimes ?? env("MAX_REQUESTS").flatMap(Int.init) ?? 0
206+
self.maxTimes = maxTimes ?? env("MAX_REQUESTS").flatMap(Int.init) ?? 0
207207
self.stopSignal = stopSignal ?? env("STOP_SIGNAL").flatMap(Int32.init).flatMap(Signal.init) ?? Signal.TERM
208208
precondition(self.maxTimes >= 0, "maxTimes must be equal or larger than 0")
209209
}

docker/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
ARG swift_version=5.0
2+
ARG ubuntu_version=bionic
3+
FROM swift:$swift_version-$ubuntu_version
4+
# needed to do again after FROM due to docker limitation
5+
ARG swift_version
6+
ARG ubuntu_version
7+
8+
# set as UTF-8
9+
RUN apt-get update && apt-get install -y locales locales-all
10+
ENV LC_ALL en_US.UTF-8
11+
ENV LANG en_US.UTF-8
12+
ENV LANGUAGE en_US.UTF-8
13+
14+
# dependencies
15+
RUN apt-get update && apt-get install -y wget
16+
RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools curl jq # used by integration tests
17+
18+
# ruby and jazzy for docs generation
19+
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev
20+
RUN gem install jazzy --no-ri --no-rdoc
21+
22+
# tools
23+
RUN mkdir -p $HOME/.tools
24+
RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile
25+
26+
# script to allow mapping framepointers on linux (until part of the toolchain)
27+
RUN wget -q https://raw.githubusercontent.com/apple/swift/master/utils/symbolicate-linux-fatal -O $HOME/.tools/symbolicate-linux-fatal
28+
RUN chmod 755 $HOME/.tools/symbolicate-linux-fatal
29+
30+
# swiftformat (until part of the toolchain)
31+
32+
ARG swiftformat_version=0.40.12
33+
RUN git clone --branch $swiftformat_version --depth 1 https://github.com/nicklockwood/SwiftFormat $HOME/.tools/swift-format
34+
RUN cd $HOME/.tools/swift-format && swift build -c release
35+
RUN ln -s $HOME/.tools/swift-format/.build/release/swiftformat $HOME/.tools/swiftformat

docker/docker-compose.1604.51.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3"
2+
3+
services:
4+
5+
runtime-setup:
6+
image: swift-aws-lambda:16.04-5.1
7+
build:
8+
args:
9+
ubuntu_version: "xenial"
10+
swift_version: "5.1"
11+
12+
test:
13+
image: swift-aws-lambda:16.04-5.1
14+
15+
shell:
16+
image: swift-aws-lambda:16.04-5.1

docker/docker-compose.1804.50.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3"
2+
3+
services:
4+
5+
runtime-setup:
6+
image: swift-aws-lambda:18.04-5.0
7+
build:
8+
args:
9+
ubuntu_version: "bionic"
10+
swift_version: "5.0"
11+
12+
test:
13+
image: swift-aws-lambda:18.04-5.0
14+
15+
shell:
16+
image: swift-aws-lambda:18.04-5.0

docker/docker-compose.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# this file is not designed to be run directly
2+
# instead, use the docker-compose.<os>.<swift> files
3+
# eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.1804.50.yaml run test
4+
version: "3"
5+
6+
services:
7+
8+
runtime-setup:
9+
image: swift-aws-lambda:default
10+
build:
11+
context: .
12+
dockerfile: Dockerfile
13+
14+
common: &common
15+
image: swift-aws-lambda:default
16+
depends_on: [runtime-setup]
17+
volumes:
18+
- ~/.ssh:/root/.ssh
19+
- ..:/code:z
20+
working_dir: /code
21+
cap_drop:
22+
- CAP_NET_RAW
23+
- CAP_NET_BIND_SERVICE
24+
25+
sanity:
26+
<<: *common
27+
command: /bin/bash -cl "./scripts/sanity.sh"
28+
29+
test:
30+
<<: *common
31+
command: /bin/bash -cl "swift test -Xswiftc -warnings-as-errors"
32+
33+
# util
34+
35+
shell:
36+
<<: *common
37+
entrypoint: /bin/bash

scripts/generate_linux_tests.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ def createLinuxMain(testsDirectory, allTestSubDirectories, files)
9696

9797
file.write "#if os(Linux) || os(FreeBSD)\n"
9898
for testSubDirectory in allTestSubDirectories.sort { |x, y| x <=> y }
99-
file.write ' @testable import ' + testSubDirectory + "\n"
99+
file.write '@testable import ' + testSubDirectory + "\n"
100100
end
101101
file.write "\n"
102-
file.write " XCTMain([\n"
102+
file.write "XCTMain([\n"
103103

104104
testCases = []
105105
for classes in files
@@ -109,9 +109,9 @@ def createLinuxMain(testsDirectory, allTestSubDirectories, files)
109109
end
110110

111111
for testCase in testCases.sort { |x, y| x <=> y }
112-
file.write ' testCase(' + testCase + ".allTests),\n"
112+
file.write ' testCase(' + testCase + ".allTests),\n"
113113
end
114-
file.write " ])\n"
114+
file.write "])\n"
115115
file.write "#endif\n"
116116
end
117117
end

scripts/linux_performance_setup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftAwsLambda open source project
5+
##
6+
## Copyright (c) 2020 Apple Inc. and the SwiftAwsLambda project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftAwsLambda project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
215

316
# docker run --cap-add SYS_ADMIN -it -v `pwd`:/code -w /code swift:5.1 bash
417

scripts/sanity.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1919

2020
function replace_acceptable_years() {
2121
# this needs to replace all acceptable forms with 'YEARS'
22-
sed -e 's/2017-2018/YEARS/' -e 's/2017-2019/YEARS/' -e 's/2019/YEARS/'
22+
sed -e 's/2017-2018/YEARS/' -e 's/2017-2019/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/'
2323
}
2424

2525
printf "=> Checking linux tests... "

0 commit comments

Comments
 (0)