-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #956 from shinnokdisengir/feature/split-docker
Setup build for dev and prod
- Loading branch information
Showing
14 changed files
with
224 additions
and
494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.