-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
57 lines (47 loc) · 1.53 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
DEPLOY_PACKAGES := HelloWorldAPI
DOCKER_IMAGE := swift-lambda-builder
DOCKER_IMAGE_INFO := .build/${DOCKER_IMAGE}.json
SWIFT_RELEASE_OPTS := -c release
#SWIFT_RELEASE_OPTS := -c release -Xswiftc -static-stdlib -Xswiftc -lDispatchStubs
SAM_CONFIG := samconfig.toml
.PHONY: all
all: bootstrap deploy
.PHONY: clean
clean:
swift package clean
.PHONY: bootstrap
bootstrap: ${DOCKER_IMAGE_INFO}
.PHONY: package_all
package_all: $(DEPLOY_PACKAGES:%=.build/lambda/%.zip)
@echo $<
.PHONY: deploy
deploy: #package_all
sam build
[ -f ${SAM_CONFIG} ] && (sam deploy || echo "Failed") || sam deploy --guided
${DOCKER_IMAGE_INFO}:
docker inspect ${DOCKER_IMAGE} > /dev/null 2>&1 || docker build -t ${DOCKER_IMAGE} .
mkdir -p `dirname ${DOCKER_IMAGE_INFO}`
docker inspect ${DOCKER_IMAGE} > ${DOCKER_IMAGE_INFO}
.build/lambda/%.zip: .build/release/%
@echo == package $(notdir $<)
docker run \
--rm \
--volume "$(shell pwd)/:/src" \
--workdir "/src/" \
${DOCKER_IMAGE} \
scripts/package.sh $(notdir $<)
# TODO: check dependencies
.build/release/%:
@echo == build $(notdir $@)
docker run \
--rm \
--volume "$(shell pwd)/:/src" \
--workdir "/src/" \
${DOCKER_IMAGE} \
swift build --product $(notdir $@) ${SWIFT_RELEASE_OPTS}
# for sam build, example: sam build HelloWorldAPIFunction
# TODO: dependency does not work, package_all first
#build-%: .build/lambda/$(patsubst build-%Function,%.zip,$@)
build-%: package_all
test -d "${ARTIFACTS_DIR}" || exit 1
unzip .build/lambda/$(patsubst build-%Function,%.zip,$@) -d ${ARTIFACTS_DIR}/