From 2c11b445101811784d30dc4a27619c00676f500a Mon Sep 17 00:00:00 2001 From: Dincho Todorov Date: Mon, 1 Jun 2020 18:00:52 +0300 Subject: [PATCH 1/2] Add Dockerfile --- .dockerignore | 9 +++++++++ Dockerfile | 39 +++++++++++++++++++++++++++++++++++++++ Makefile | 3 +++ 3 files changed, 51 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..b1906d43b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +* +!rebar.config +!rebar.lock +!Makefile +!rebar3 +!sys.config +!vm.args +!apps +!.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a3beea154 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +FROM erlang:21.3.8.14 as builder + +# Add required files to download and compile only the dependencies +ADD rebar.config rebar.lock Makefile rebar3 /app/ +RUN cd /app && make prod-compile-deps + +# Add the whole project and compile it +ADD . /app +RUN cd /app && make prod-build + +# Put the app in second stage (runtime) container +FROM debian:stretch-slim + +# Install runtime dependancies +RUN apt-get update \ + && apt-get -y --no-install-recommends install libssl1.1 curl \ + && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Deploy application code from builder container +COPY --from=builder /app/_build/prod/rel/server /nynja-server + +WORKDIR /nynja-server + +# MQTT API +EXPOSE 1883 + +# MQTT WS +EXPOSE 8083 + +# REST API +EXPOSE 8888 + +# Dashboard +EXPOSE 18083 + +HEALTHCHECK --start-period=15s --timeout=3s CMD curl --fail http://nynja:nynjaTS@localhost:8888/health | grep '"accept_traffic":true' + +# The container has be run with FQDN hostname including dot in it. E.g. -h nynja.local +CMD ["bin/server", "foreground"] diff --git a/Makefile b/Makefile index 6f847022a..4c1c69c20 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,9 @@ local-build: @$(REBAR) as local release +prod-compile-deps: + @$(REBAR) as prod compile -d + prod-build: @$(REBAR) as prod release -- GitLab From d67970a26820c433da6896d45214793a41d22a15 Mon Sep 17 00:00:00 2001 From: Dincho Todorov Date: Mon, 1 Jun 2020 18:03:16 +0300 Subject: [PATCH 2/2] Fix typos --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a3beea154..dff9d69b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN cd /app && make prod-build # Put the app in second stage (runtime) container FROM debian:stretch-slim -# Install runtime dependancies +# Install runtime dependencies RUN apt-get update \ && apt-get -y --no-install-recommends install libssl1.1 curl \ && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* @@ -35,5 +35,5 @@ EXPOSE 18083 HEALTHCHECK --start-period=15s --timeout=3s CMD curl --fail http://nynja:nynjaTS@localhost:8888/health | grep '"accept_traffic":true' -# The container has be run with FQDN hostname including dot in it. E.g. -h nynja.local +# The container has to be run with FQDN hostname including dot in it. E.g. -h nynja.local CMD ["bin/server", "foreground"] -- GitLab