-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedocker.tmpl
93 lines (77 loc) · 3.61 KB
/
edocker.tmpl
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
# APP_NAME is the name of the app. Unfortunately erlang.mk currently requires the top folder
# name to be the same as the APP_NAME. Therefore you can either specify the app name as an
# argument to the make command or the script will try to figure it out by looking into any
# ebin/*.app or src/*.app.src it might find
APP_NAME ?= $(shell cat ebin/*.app src/*.app.src 2>/dev/null | sed -n 's/\s*{\s*application\s*,[ \t\n]*\([^ ^\t^\n][^,]*\),.*\s*/\1/p' | head -1)
APP_NAME ?= $(shell basename `pwd`)
# This is the version tag of the resulting docker image
TAG ?= 1.0
# The docker binary you have in your system, if you require "sudo docker"
# then do "DOCKER=sudo docker"
DOCKER ?= docker
# The erlang version you want to build your release in. The number should match
# an existing public tag for the erlang docker image
ERLANG_VERSION ?= 26
# A list of binaries that will be copied from the erlang docker image to the /bin folder
# of the release image. So if you require "ffmpeg" and "bash" binary for instance, you should
# list that here as BINARIES_TO_INCLUDE = ffmpeg bash
BINARIES_TO_INCLUDE ?=
# If you want to add some apt repositories (PPAs) to install before building (and perhaps
# add binaries from to the BINARIES_TO_INCLUDE above) you should list them here and then
# add the specific package you want installed to the EXTRA_PACKAGES below
EXTRA_PPAS ?=
# If you want to add a line to the /etc/apt/soruces.list before building
# you can add that line here and add the specific package you want installed to the
# EXTRA_PACKAGES below
SOURCES_LIST_APPEND ?=
# If you want to install some extra package to perhaps add a binary from that package
# to BINARIES_TO_INCLUDE, you can add that package name to the EXTRA_PACKAGES list
EXTRA_PACKAGES ?=
# rule to extract the build scripts and the source code for the resulting edocker_erlexec.c
# this is extracting a tar file that is generated from tarring up the .ed folder in the git
# repository
ed_helper_files:
@ echo TAR_BLOB | base64 -d | tar xzf -
define make_builder
$(DOCKER) build -t "builder_${APP_NAME}:${TAG}" . -f - <<EOF
FROM erlang:$(ERLANG_VERSION)
WORKDIR /$(APP_NAME)
RUN apt-get update && apt-get -y --force-yes install software-properties-common
RUN for r in ${EXTRA_PPAS}; do add-apt-repository -y $r; done
RUN if [ ! -z "${SOURCES_LIST_APPEND}" ]; then printf "${SOURCES_LIST_APPEND}" >> /etc/apt/sources.list; fi
RUN apt-get update && apt-get -y --force-yes install ${EXTRA_PACKAGES} erlang-dev
COPY . .
RUN make RELX_TAR=0
RUN make extract
RUN .ed/bin/mkimage ${BINARIES_TO_INCLUDE}
EOF
endef
export make_builder
define make_release_image
${DOCKER} build -t ${REL_NAME}:${TAG} . -f - <<EOF
FROM scratch
MAINTAINER Stefan Hellkvist <hellkvist@gmail.com>
ENV BOOT /releases/${REL_VSN}/start
ENV BINDIR /erts-${ERTS_VSN}/bin
ENV CONFIG /releases/${REL_VSN}/sys.config
ENV ARGS_FILE /releases/${REL_VSN}/vm.args
ENV EDOCKER_COOKIE edocker_default_cookie
ENV EDOCKER_NAME edocker_default_name
ENV EDOCKER_HOST 127.0.0.1
ENV ERL_INETRC /etc/erl_inetrc
ENV TZ=GMT
ENTRYPOINT exec ${BINDIR}/edocker_erlexec
COPY --from="builder_${APP_NAME}:${TAG}" /${APP_NAME}/_rel/${REL_NAME}/ /
EOF
endef
export make_release_image
extract: ed_helper_files
ebuilder:
@ eval "$$make_builder"
erelease_image: ebuilder
$(eval REL_NAME := $(shell ${DOCKER} run --rm "builder_${APP_NAME}:${TAG}" .ed/bin/release_name))
$(eval REL_VSN := $(shell ${DOCKER} run --rm "builder_${APP_NAME}:${TAG}" .ed/bin/release_version))
$(eval ERTS_VSN := $(shell ${DOCKER} run --rm "builder_${APP_NAME}:${TAG}" .ed/bin/system_version))
$(eval BINDIR := /erts-${ERTS_VSN}/bin)
@ eval "$$make_release_image"
docker_image: erelease_image