Skip to content

Commit 2546c08

Browse files
Update build.sh
1 parent 69bd63a commit 2546c08

24 files changed

+95
-4507
lines changed

.gitignore

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,3 @@
1-
# Xcode
2-
#
3-
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4-
5-
## Build generated
6-
build/
7-
DerivedData/
8-
9-
## Various settings
10-
*.pbxuser
11-
!default.pbxuser
12-
*.mode1v3
13-
!default.mode1v3
14-
*.mode2v3
15-
!default.mode2v3
16-
*.perspectivev3
17-
!default.perspectivev3
18-
xcuserdata/
19-
20-
## Other
21-
*.moved-aside
22-
*.xccheckout
23-
*.xcscmblueprint
24-
25-
## Obj-C/Swift specific
26-
*.hmap
27-
*.ipa
28-
*.dSYM.zip
29-
*.dSYM
30-
31-
## Playgrounds
32-
timeline.xctimeline
33-
playground.xcworkspace
34-
35-
# Swift Package Manager
36-
#
37-
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
38-
# Packages/
39-
# Package.pins
40-
# Package.resolved
41-
.build/
42-
43-
# CocoaPods
44-
#
45-
# We recommend against adding the Pods directory to your .gitignore. However
46-
# you should judge for yourself, the pros and cons are mentioned at:
47-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
48-
#
49-
# Pods/
50-
51-
# Carthage
52-
#
53-
# Add this line if you want to avoid checking in source code from Carthage dependencies.
54-
# Carthage/Checkouts
55-
56-
Carthage/Build
57-
58-
# fastlane
59-
#
60-
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
61-
# screenshots whenever they are needed.
62-
# For more information about the recommended setup visit:
63-
# https://docs.fastlane.tools/best-practices/source-control/#source-control
64-
65-
fastlane/report.xml
66-
fastlane/Preview.html
67-
fastlane/screenshots/**/*.png
68-
fastlane/test_output
69-
1+
build
2+
swift-shared-libs
703
.serverless

Dockerfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

Makefile

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,96 @@
1-
MOUNT_ROOT=$(shell pwd)
2-
DOCKER_IMAGE=benchmark-node:latest
1+
# Copyright 2019 (c) Andrea Scuderi - https://github.com/swift-sprinter
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Use this tag to build a customized local image
16+
17+
SWIFT_VERSION?=5.1.4
18+
LAYER_VERSION?=5-1-4
319

4-
SWIFT_EXECUTABLE?=GetProduct
5-
SWIFT_PROJECT_PATH?=./swift-rest-api
6-
LAMBDA_FUNCTION_NAME?=GetProduct
20+
DOCKER_TAG=nio-swift:$(SWIFT_VERSION)
21+
SWIFT_DOCKER_IMAGE=$(DOCKER_TAG)
22+
SWIFT_LAMBDA_LIBRARY=nio-swift-lambda-runtime-$(LAYER_VERSION)
23+
SWIFT_CONFIGURATION=release
24+
25+
SERVERLESS_BUILD=build
26+
SERVERLESS_LAYER=swift-lambda-runtime
27+
28+
# Configuration
29+
30+
# HelloWorld Example Configuration
31+
SWIFT_EXECUTABLE?=Products
32+
SWIFT_PROJECT_PATH?=Products
33+
LAMBDA_FUNCTION_NAME?=Products
734
LAMBDA_HANDLER?=$(SWIFT_EXECUTABLE).handler
835

36+
# Internals
37+
LAMBDA_ZIP=lambda.zip
38+
SHARED_LIBS_FOLDER=swift-shared-libs
39+
LAYER_ZIP=swift-lambda-runtime-$(LAYER_VERSION).zip
40+
ROOT_BUILD_PATH=./build
41+
LAYER_BUILD_PATH=$(ROOT_BUILD_PATH)
42+
LAMBDA_BUILD_PATH=$(ROOT_BUILD_PATH)
43+
44+
# use this for local development
45+
MOUNT_ROOT=$(shell pwd)
46+
DOCKER_PROJECT_PATH=$(SWIFT_PROJECT_PATH)
47+
948
docker_build:
10-
docker build --tag $(DOCKER_IMAGE) .
49+
docker build --tag $(DOCKER_TAG) docker/$(SWIFT_VERSION)/.
50+
51+
build_lambda:
52+
docker run \
53+
--rm \
54+
--volume "$(MOUNT_ROOT)/:/src" \
55+
--workdir "/src/$(DOCKER_PROJECT_PATH)" \
56+
$(SWIFT_DOCKER_IMAGE) \
57+
/bin/bash -c "swift build --configuration $(SWIFT_CONFIGURATION)"
1158

12-
docker_bash:
59+
cp_to_serverless_build: create_build_directory
1360
docker run \
14-
-it \
1561
--rm \
1662
--volume "$(MOUNT_ROOT)/:/src" \
63+
--workdir "/src/$(DOCKER_PROJECT_PATH)" \
64+
$(SWIFT_DOCKER_IMAGE) \
65+
/bin/bash -c "swift build -c $(SWIFT_CONFIGURATION) --show-bin-path | tr '\n' '/' > .build/path.txt; echo '$(SWIFT_EXECUTABLE)' >> .build/path.txt | cat .build/path.txt | xargs cp -t ../$(SERVERLESS_BUILD); rm .build/path.txt"
66+
67+
create_build_directory:
68+
if [ ! -d "$(LAMBDA_BUILD_PATH)" ]; then mkdir -p $(LAMBDA_BUILD_PATH); fi
69+
if [ ! -d "$(LAYER_BUILD_PATH)" ]; then mkdir -p $(LAYER_BUILD_PATH); fi
70+
if [ ! -d "$(SERVERLESS_BUILD)" ]; then mkdir -p $(SERVERLESS_BUILD); fi
71+
72+
package_lambda: create_build_directory build_lambda
73+
zip -r -j $(LAMBDA_BUILD_PATH)/$(LAMBDA_ZIP) $(SWIFT_PROJECT_PATH)/.build/$(SWIFT_CONFIGURATION)/$(SWIFT_EXECUTABLE)
74+
75+
package_layer: create_build_directory
76+
$(eval SHARED_LIBRARIES := $(shell cat docker/$(SWIFT_VERSION)/swift-shared-libraries.txt | tr '\n' ' '))
77+
mkdir -p $(SHARED_LIBS_FOLDER)/lib
78+
docker run \
79+
--rm \
80+
--volume "$(shell pwd)/:/src" \
81+
--workdir "/src" \
82+
$(SWIFT_DOCKER_IMAGE) \
83+
cp /lib64/ld-linux-x86-64.so.2 $(SHARED_LIBS_FOLDER)
84+
docker run \
85+
--rm \
86+
--volume "$(shell pwd)/:/src" \
1787
--workdir "/src" \
18-
$(DOCKER_IMAGE) \
19-
/bin/bash
88+
$(SWIFT_DOCKER_IMAGE) \
89+
cp -t $(SHARED_LIBS_FOLDER)/lib $(SHARED_LIBRARIES)
90+
zip -r $(LAYER_BUILD_PATH)/$(LAYER_ZIP) bootstrap $(SHARED_LIBS_FOLDER)
91+
92+
unzip_package_to_build: create_build_directory
93+
if [ ! -d "./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER)" ]; then mkdir -p ./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER); fi
94+
cp $(LAYER_BUILD_PATH)/$(LAYER_ZIP) ./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER)/$(LAYER_ZIP)
95+
unzip ./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER)/$(LAYER_ZIP) -d ./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER)
96+
rm ./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER)/$(LAYER_ZIP)

swift-rest-api/.gitignore renamed to Products/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
/Packages
44
/*.xcodeproj
55
xcuserdata/
6-
swift-shared-libs
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)