This repository was archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
112 lines (93 loc) · 3.94 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2019 (c) Andrea Scuderi - https://github.com/swift-sprinter
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Use this tag to build a customized local image
SWIFT_VERSION?=nightly-amazonlinux2
LAYER_VERSION?=nightly-amazonlinux2
DOCKER_OS?=amazonlinux2
# SWIFT_VERSION?=5.2.3
# LAYER_VERSION?=5-2-3
# DOCKER_OS=xenial
DOCKER_TAG=nio-swift:$(SWIFT_VERSION)
SWIFT_DOCKER_IMAGE=$(DOCKER_TAG)
SWIFT_LAMBDA_LIBRARY=nio-swift-lambda-runtime-$(LAYER_VERSION)
SWIFT_CONFIGURATION=release
BUILD_PATH=.build
SERVERLESS_BUILD=build
SERVERLESS_LAYER=swift-lambda-runtime
# Configuration
# HelloWorld Example Configuration
SWIFT_EXECUTABLE?=Hello
SWIFT_PROJECT_PATH?=Hello
LAMBDA_FUNCTION_NAME?=Hello
LAMBDA_HANDLER?=$(SWIFT_EXECUTABLE).hello
# Internals
LAMBDA_ZIP=lambda.zip
SHARED_LIBS_FOLDER=swift-shared-libs
LAYER_ZIP=swift-lambda-runtime-$(LAYER_VERSION).zip
ROOT_BUILD_PATH=./build
LAYER_BUILD_PATH=$(ROOT_BUILD_PATH)
LAMBDA_BUILD_PATH=$(ROOT_BUILD_PATH)
# use this for local development
MOUNT_ROOT=$(shell pwd)
DOCKER_PROJECT_PATH=$(SWIFT_PROJECT_PATH)
ROOT_BUILD_PATH=./.build
LAYER_BUILD_PATH=$(ROOT_BUILD_PATH)/layer
LAMBDA_BUILD_PATH=$(ROOT_BUILD_PATH)/lambda
LOCAL_LAMBDA_PATH=$(ROOT_BUILD_PATH)/local
LOCALSTACK_TMP=$(ROOT_BUILD_PATH)/.tmp
TMP_BUILD_PATH=$(ROOT_BUILD_PATH)/tmp
DATETIME=$(shell date +'%y%m%d-%H%M%S')
DOCKER_FOLDER=docker
BOOTSTRAP=$(DOCKER_FOLDER)/$(SWIFT_VERSION)/bootstrap
docker_build:
docker build --tag $(DOCKER_TAG) $(DOCKER_FOLDER)/$(SWIFT_VERSION)/.
build_lambda:
docker run \
--rm \
--volume "$(MOUNT_ROOT)/:/src" \
--workdir "/src/$(DOCKER_PROJECT_PATH)" \
$(SWIFT_DOCKER_IMAGE) \
/bin/bash -c "swift build --configuration $(SWIFT_CONFIGURATION)"
cp_lambda_to_sls_build_local: create_build_directory
docker run \
--rm \
--volume "$(MOUNT_ROOT)/:/src" \
--workdir "/src/$(DOCKER_PROJECT_PATH)" \
$(SWIFT_DOCKER_IMAGE) \
/bin/bash -c "swift build -c $(SWIFT_CONFIGURATION) --show-bin-path | tr '\n' '/' > $(BUILD_PATH)/path.txt; echo '$(SWIFT_EXECUTABLE)' >> $(BUILD_PATH)/path.txt | cat $(BUILD_PATH)/path.txt | xargs cp -t ../$(SERVERLESS_BUILD); rm $(BUILD_PATH)/path.txt"
create_build_directory:
if [ ! -d "$(LAMBDA_BUILD_PATH)" ]; then mkdir -p $(LAMBDA_BUILD_PATH); fi
if [ ! -d "$(LAYER_BUILD_PATH)" ]; then mkdir -p $(LAYER_BUILD_PATH); fi
if [ ! -d "$(SERVERLESS_BUILD)" ]; then mkdir -p $(SERVERLESS_BUILD); fi
package_lambda: create_build_directory build_lambda
zip -r -j $(LAMBDA_BUILD_PATH)/$(LAMBDA_ZIP) $(SWIFT_PROJECT_PATH)/$(BUILD_PATH)/$(SWIFT_CONFIGURATION)/$(SWIFT_EXECUTABLE)
package_layer: create_build_directory
$(eval SHARED_LIBRARIES := $(shell cat docker/$(SWIFT_VERSION)/swift-shared-libraries.txt | tr '\n' ' '))
mkdir -p $(SHARED_LIBS_FOLDER)/lib
ifeq '$(DOCKER_OS)' 'xenial'
docker run \
--rm \
--volume "$(shell pwd)/:/src" \
--workdir "/src" \
$(SWIFT_DOCKER_IMAGE) \
cp /lib64/ld-linux-x86-64.so.2 $(SHARED_LIBS_FOLDER)
endif
docker run \
--rm \
--volume "$(shell pwd)/:/src" \
--workdir "/src" \
$(SWIFT_DOCKER_IMAGE) \
cp -t $(SHARED_LIBS_FOLDER)/lib $(SHARED_LIBRARIES)
cp $(BOOTSTRAP) $(SHARED_LIBS_FOLDER)
cd $(SHARED_LIBS_FOLDER); pwd; zip -r ../$(LAYER_BUILD_PATH)/$(LAYER_ZIP) bootstrap lib
cp_layer_to_sls_build_local: create_build_directory
if [ ! -d "./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER)" ]; then mkdir -p ./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER); fi
cp -R ./$(SHARED_LIBS_FOLDER)/. ./$(SERVERLESS_BUILD)/$(SERVERLESS_LAYER)