diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..b1906d43b5b4e6503de54aec08a8121cbd9aec8a --- /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 0000000000000000000000000000000000000000..dff9d69b0ebc343d81b6ef4e8e5767358426cf81 --- /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 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/* + +# 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 to 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 6f847022a94ce544b7e07843b887ebb281ca2bb5..4c1c69c2078000860daea243500ba0555720087b 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