Skip to content

Commit

Permalink
Merge pull request #956 from shinnokdisengir/feature/split-docker
Browse files Browse the repository at this point in the history
Setup build for dev and prod
  • Loading branch information
davidebriani authored Jul 18, 2024
2 parents 11e9bc6 + 87d67d4 commit 1a5ee19
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 494 deletions.
89 changes: 89 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as base

# install build dependencies
# --allow-releaseinfo-change allows to pull from 'oldstable'
RUN apt-get update --allow-releaseinfo-change -y && \
apt-get install -y \
build-essential \
git \
openssl \
ca-certificates \
inotify-tools && \
apt-get clean && \
rm -f /var/lib/apt/lists/*_*

# Install hex
RUN mix local.hex --force && \
mix local.rebar --force && \
mix hex.info

WORKDIR /src

FROM base as deps

ARG BUILD_ENV=prod

ENV MIX_ENV=${BUILD_ENV}

# Cache elixir deps
ADD mix.exs mix.lock ./
RUN mix do deps.get --only ${MIX_ENV}, deps.compile

FROM deps as builder

ENV MIX_ENV=${BUILD_ENV}

# Add all the rest
ADD . .
ENTRYPOINT [ "/bin/sh", "-c" ]
# ------------------------
# Only for production
FROM builder as release

ENV MIX_ENV=${BUILD_ENV}

COPY --from=builder /src .

WORKDIR /src
RUN mix do compile, release

RUN mkdir -p /rel && \
cp -r _build/$BUILD_ENV/rel /rel
# Check if entrypoint.sh exists,
# otherwise a default script is created
RUN if [ -f "./entrypoint.sh" ]; then \
cp ./entrypoint.sh /rel/entrypoint.sh; \
else \
echo '#!/bin/bash' >> /rel/entrypoint.sh; \
echo exec \$@ >> /rel/entrypoint.sh; \
fi; \
chmod +x /rel/entrypoint.sh

# Note: it is important to keep Debian versions in sync,
# or incompatibilities between libcrypto will happen
FROM debian:bookworm-slim

# Set the locale
ENV LANG C.UTF-8

# We need SSL
RUN apt-get -qq update -y && \
apt-get -qq install \
openssl \
ca-certificates \
&& apt-get clean \
&& rm -f /var/lib/apt/lists/*_*

WORKDIR /app

COPY --from=release --chown=nobody:nobody /rel/* .

# Symlink to the service, to make a single entry point
# for all the apps
RUN APP_NAME=$(ls | head -n 1) && \
ln -s ${APP_NAME}/bin/${APP_NAME} astarte-service

USER nobody

ENTRYPOINT [ "./entrypoint.sh" ]
CMD ["./astarte-service", "start"]
53 changes: 0 additions & 53 deletions apps/astarte_appengine_api/Dockerfile

This file was deleted.

53 changes: 0 additions & 53 deletions apps/astarte_data_updater_plant/Dockerfile

This file was deleted.

55 changes: 0 additions & 55 deletions apps/astarte_housekeeping/Dockerfile

This file was deleted.

8 changes: 4 additions & 4 deletions apps/astarte_housekeeping/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

./bin/astarte_housekeeping eval Elixir.Astarte.Housekeeping.ReleaseTasks.init_database || exit 1
./astarte-service eval Elixir.Astarte.Housekeeping.ReleaseTasks.init_database
./astarte-service eval Elixir.Astarte.Housekeeping.ReleaseTasks.migrate

./bin/astarte_housekeeping eval Elixir.Astarte.Housekeeping.ReleaseTasks.migrate || exit 1

exec ./bin/astarte_housekeeping $@
exec $@
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is part of Astarte.
#
# Copyright 2019 Ispirata Srl
# Copyright 2019-2024 SECO Mind Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,8 +53,6 @@ defmodule Astarte.Housekeeping.ReleaseTasks do

raise "init_database failed"
end

:ok = stop_services()
end

def migrate do
Expand Down Expand Up @@ -83,8 +81,6 @@ defmodule Astarte.Housekeeping.ReleaseTasks do

raise "migrate failed"
end

:ok = stop_services()
end

defp wait_connection_and_check_astarte_keyspace(retries \\ 60) do
Expand All @@ -109,7 +105,7 @@ defmodule Astarte.Housekeeping.ReleaseTasks do
Enum.each(@start_apps, &Application.ensure_all_started/1)

# Load astarte_data_access, without starting it. This makes the application env accessible.
:ok = Application.load(:astarte_data_access)
:ok = Application.ensure_loaded(:astarte_data_access)

_ = Logger.info("Starting Xandra connection to #{inspect(Config.xandra_nodes!())}")

Expand Down
53 changes: 0 additions & 53 deletions apps/astarte_housekeeping_api/Dockerfile

This file was deleted.

Loading

0 comments on commit 1a5ee19

Please sign in to comment.