Skip to content

Commit 060f4d3

Browse files
committed
script to build using lambda2 base
1 parent 529cd06 commit 060f4d3

File tree

3 files changed

+99
-19
lines changed

3 files changed

+99
-19
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2+
cache
3+
result
24
build

Diff for: Makefile

+34-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
1-
DEPLOYMENT_BUCKET_NAME := desole-packaging
2-
DEPLOYMENT_KEY := $(shell echo pandoc-$$RANDOM.zip)
3-
STACK_NAME := pandoc-lambda-layer
1+
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
42

5-
clean:
6-
rm -rf build
3+
DOCKER_IMAGE ?= lambci/lambda-base-2:build
4+
TARGET ?=/opt/
75

8-
build/bin/pandoc: vendor/pandoc.gz
9-
mkdir -p build/bin
10-
cp vendor/pandoc.gz build/bin
11-
gzip -d build/bin/pandoc.gz
6+
MOUNTS = -v $(PROJECT_ROOT):/var/task \
7+
-v $(PROJECT_ROOT)result:$(TARGET) \
8+
-v $(PROJECT_ROOT)cache:/usr/local
129

13-
build/layer.zip: build/bin/pandoc
14-
cd build && zip -r layer.zip bin
10+
DOCKER = docker run -it --rm -w=/var/task/build
11+
build result cache:
12+
mkdir $@
1513

16-
# cloudformation has no support for packaging layers yet, so need to do this manually
17-
#
18-
build/output.yml: build/layer.zip cloudformation/template.yml
19-
aws s3 cp build/layer.zip s3://$(DEPLOYMENT_BUCKET_NAME)/$(DEPLOYMENT_KEY)
20-
sed "s:DEPLOYMENT_BUCKET_NAME:$(DEPLOYMENT_BUCKET_NAME):;s:DEPLOYMENT_KEY:$(DEPLOYMENT_KEY):" cloudformation/template.yml > build/output.yml
14+
clean:
15+
rm -rf build result cache
2116

22-
deploy: build/output.yml
23-
aws cloudformation deploy --template-file build/output.yml --stack-name $(STACK_NAME)
24-
aws cloudformation describe-stacks --stack-name $(STACK_NAME) --query Stacks[].Outputs[].OutputValue --output text
17+
test:
18+
$(DOCKER) $(MOUNTS) --entrypoint /opt/bin/pandoc -t $(DOCKER_IMAGE) -v
2519

20+
bash:
21+
$(DOCKER) $(MOUNTS) --entrypoint /bin/bash -t $(DOCKER_IMAGE)
22+
23+
all: build result cache
24+
$(DOCKER) $(MOUNTS) --entrypoint /usr/bin/make -t $(DOCKER_IMAGE) TARGET_DIR=$(TARGET) -f ../Makefile_ImageMagick $@
25+
26+
27+
STACK_NAME ?= pandoc-layer
28+
29+
result/bin/pandoc: all
30+
31+
build/output.yaml: template.yaml result/bin/pandoc
32+
aws cloudformation package --template $< --s3-bucket $(DEPLOYMENT_BUCKET) --output-template-file $@
33+
34+
deploy: build/output.yaml
35+
aws cloudformation deploy --template $< --stack-name $(STACK_NAME)
36+
aws cloudformation describe-stacks --stack-name $(STACK_NAME) --query Stacks[].Outputs --output table
37+
38+
deploy-example: deploy
39+
cd example && \
40+
make deploy DEPLOYMENT_BUCKET=$(DEPLOYMENT_BUCKET) IMAGE_MAGICK_STACK_NAME=$(STACK_NAME)

Diff for: Makefile_Pandoc

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
GHC_VERSION ?= 8.4.4
2+
CABAL_VERSION ?= 2.2.0.0
3+
EPEL_VERSION ?= latest-7
4+
5+
TARGET_DIR ?= /opt/
6+
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
7+
CACHE_DIR=$(PROJECT_ROOT)build/cache
8+
9+
.ONESHELL:
10+
11+
### step 1: install GHC
12+
# GHC is self-referential, so we need some version of GHC to install the latest version;
13+
# so first install the older one that comes with EPEL on RPM, then update to the latest
14+
15+
GHC_SOURCE=ghc-$(GHC_VERSION)-x86_64-centos70-linux.tar.xz
16+
17+
/etc/yum.repos.d/epel.repo:
18+
curl -LO https://dl.fedoraproject.org/pub/epel/epel-release-$(EPEL_VERSION).noarch.rpm
19+
rpm -i epel-release-$(EPEL_VERSION).noarch.rpm
20+
21+
/usr/bin/ghc: /etc/yum.repos.d/epel.repo
22+
yum install ghc -y
23+
24+
$(GHC_SOURCE):
25+
curl -LO https://downloads.haskell.org/~ghc/$(GHC_VERSION)/$(GHC_SOURCE)
26+
27+
28+
/usr/local/bin/ghc: $(GHC_SOURCE) /usr/bin/ghc
29+
tar xf $(GHC_SOURCE)
30+
rm $(GHC_SOURCE)
31+
cd ghc*
32+
./configure --prefix=/usr/local
33+
make install
34+
35+
36+
### step 2: set up a cabal sandbox
37+
38+
CABAL_SOURCE=cabal-install-$(CABAL_VERSION)-x86_64-unknown-linux.tar.gz
39+
40+
$(CABAL_SOURCE):
41+
curl -LO https://www.haskell.org/cabal/release/cabal-install-$(CABAL_VERSION)/$(CABAL_SOURCE)
42+
43+
/usr/local/bin/cabal: $(CABAL_SOURCE) /usr/local/bin/ghc
44+
tar xf $(CABAL_SOURCE)
45+
mv cabal /usr/local/bin
46+
47+
/root/.cabal/packages/hackage.haskell.org: /usr/local/bin/cabal
48+
cabal update
49+
50+
cabal.sandbox.config: /root/.cabal/packages/hackage.haskell.org
51+
cabal sandbox init --sandbox .
52+
53+
### step 3: compile pandoc
54+
55+
56+
bin/pandoc: cabal.sandbox.config
57+
cabal install --disable-documentation pandoc -fembed_data_files
58+
59+
$(TARGET_DIR)bin/pandoc: bin/pandoc
60+
mkdir -p $(TARGET_DIR)bin
61+
cp bin/pandoc $(TARGET_DIR)bin
62+
63+
all: $(TARGET_DIR)bin/pandoc

0 commit comments

Comments
 (0)