From 1603042086100b0d2170e838f67ad07ae27677ca Mon Sep 17 00:00:00 2001 From: Gabriele Ghio Date: Wed, 19 Jun 2024 15:56:15 +0200 Subject: [PATCH 1/3] unified Dockerfile All Dockerfiles in the project - apps - have been merged into one, as they were identical in 99% of their content. In addition, the new file configuration allows the `develop` section of `docker compose` to allow `watch`, with hotcode-reloading for those who need to develop - The common Dockerfile has been placed in the project root - All the Dockerfiles in the various _app_ have been removed - The `deps` and `builder` stages allow you to compile dependencies and have the code inside the container, without having built the release. This allows you to run `mix run --no-halt` or `mix phx.server` in the container - Prod only: the new containers also have a symlink with a common path `/app/astarte-service` pointing directly to the service. This allows the service to be started without knowing the name - Prod only: if the app project folder has `entrypoint.sh`, the commands in that file will be started instead the service itself. To run the service using the script, `entrypoint.sh` must have `exec "$@"` To build a container (default env is `prod`), you have to use the common `Dockerfile` in the app context: `docker build -f ../../Dockerfile .` To build in a different environment: `docker build --build-arg BUILD_ENV=dev -f ../../Dockerfile .` `docker build --build-arg BUILD_ENV=test -f ../../Dockerfile .` Signed-off-by: Gabriele Ghio --- Dockerfile | 89 ++++++++++++++++++++ apps/astarte_appengine_api/Dockerfile | 53 ------------ apps/astarte_data_updater_plant/Dockerfile | 53 ------------ apps/astarte_housekeeping/Dockerfile | 55 ------------ apps/astarte_housekeeping/entrypoint.sh | 8 +- apps/astarte_housekeeping_api/Dockerfile | 53 ------------ apps/astarte_pairing/Dockerfile | 53 ------------ apps/astarte_pairing_api/Dockerfile | 53 ------------ apps/astarte_realm_management/Dockerfile | 53 ------------ apps/astarte_realm_management_api/Dockerfile | 53 ------------ apps/astarte_trigger_engine/Dockerfile | 53 ------------ 11 files changed, 93 insertions(+), 483 deletions(-) create mode 100644 Dockerfile delete mode 100644 apps/astarte_appengine_api/Dockerfile delete mode 100644 apps/astarte_data_updater_plant/Dockerfile delete mode 100644 apps/astarte_housekeeping/Dockerfile delete mode 100644 apps/astarte_housekeeping_api/Dockerfile delete mode 100644 apps/astarte_pairing/Dockerfile delete mode 100644 apps/astarte_pairing_api/Dockerfile delete mode 100644 apps/astarte_realm_management/Dockerfile delete mode 100644 apps/astarte_realm_management_api/Dockerfile delete mode 100644 apps/astarte_trigger_engine/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..9ce337eee --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/apps/astarte_appengine_api/Dockerfile b/apps/astarte_appengine_api/Dockerfile deleted file mode 100644 index bd9770612..000000000 --- a/apps/astarte_appengine_api/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ - mix local.rebar --force && \ - mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_appengine_api . - -# Change to non-root user -USER nobody - -CMD ["./bin/astarte_appengine_api", "start"] diff --git a/apps/astarte_data_updater_plant/Dockerfile b/apps/astarte_data_updater_plant/Dockerfile deleted file mode 100644 index b51c1183b..000000000 --- a/apps/astarte_data_updater_plant/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ - mix local.rebar --force && \ - mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_data_updater_plant . - -# Change to non-root user -USER nobody - -CMD ["./bin/astarte_data_updater_plant", "start"] diff --git a/apps/astarte_housekeeping/Dockerfile b/apps/astarte_housekeeping/Dockerfile deleted file mode 100644 index 2fcb8f29c..000000000 --- a/apps/astarte_housekeeping/Dockerfile +++ /dev/null @@ -1,55 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ -mix local.rebar --force && \ -mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_housekeeping . -COPY --from=builder /app/entrypoint.sh . - -# Change to non-root user -USER nobody - -ENTRYPOINT ["/bin/bash", "entrypoint.sh"] -CMD ["start"] diff --git a/apps/astarte_housekeeping/entrypoint.sh b/apps/astarte_housekeeping/entrypoint.sh index fa51ba283..b0228049f 100755 --- a/apps/astarte_housekeeping/entrypoint.sh +++ b/apps/astarte_housekeeping/entrypoint.sh @@ -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 $@ diff --git a/apps/astarte_housekeeping_api/Dockerfile b/apps/astarte_housekeeping_api/Dockerfile deleted file mode 100644 index 2ff02a9fe..000000000 --- a/apps/astarte_housekeeping_api/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ -mix local.rebar --force && \ -mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_housekeeping_api . - -# Change to non-root user -USER nobody - -CMD ["./bin/astarte_housekeeping_api", "start"] diff --git a/apps/astarte_pairing/Dockerfile b/apps/astarte_pairing/Dockerfile deleted file mode 100644 index 470054730..000000000 --- a/apps/astarte_pairing/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ -mix local.rebar --force && \ -mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_pairing . - -# Change to non-root user -USER nobody - -CMD ["./bin/astarte_pairing", "start"] diff --git a/apps/astarte_pairing_api/Dockerfile b/apps/astarte_pairing_api/Dockerfile deleted file mode 100644 index ae7197bd9..000000000 --- a/apps/astarte_pairing_api/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ -mix local.rebar --force && \ -mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_pairing_api . - -# Change to non-root user -USER nobody - -CMD ["./bin/astarte_pairing_api", "start"] diff --git a/apps/astarte_realm_management/Dockerfile b/apps/astarte_realm_management/Dockerfile deleted file mode 100644 index 3d37d8bf1..000000000 --- a/apps/astarte_realm_management/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ -mix local.rebar --force && \ -mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_realm_management . - -# Change to non-root user -USER nobody - -CMD ["./bin/astarte_realm_management", "start"] diff --git a/apps/astarte_realm_management_api/Dockerfile b/apps/astarte_realm_management_api/Dockerfile deleted file mode 100644 index a99e3d67f..000000000 --- a/apps/astarte_realm_management_api/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ -mix local.rebar --force && \ -mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_realm_management_api . - -# Change to non-root user -USER nobody - -CMD ["./bin/astarte_realm_management_api", "start"] diff --git a/apps/astarte_trigger_engine/Dockerfile b/apps/astarte_trigger_engine/Dockerfile deleted file mode 100644 index d9742883c..000000000 --- a/apps/astarte_trigger_engine/Dockerfile +++ /dev/null @@ -1,53 +0,0 @@ -FROM hexpm/elixir:1.15.7-erlang-26.1-debian-bookworm-20230612-slim as builder - -# 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 \ - && apt-get clean && rm -f /var/lib/apt/lists/*_* - -WORKDIR /app - -# Install hex -RUN mix local.hex --force && \ -mix local.rebar --force && \ -mix hex.info - -# Pass --build-arg BUILD_ENV=dev to build a dev image -ARG BUILD_ENV=prod - -ENV MIX_ENV=$BUILD_ENV - -# Cache elixir deps -ADD mix.exs mix.lock ./ -RUN mix do deps.get, deps.compile - -# Add all the rest -ADD . . - -# Build and release -RUN mix do compile, release - -# Note: it is important to keep Debian versions in sync, or incompatibilities between libcrypto will happen -FROM debian:bookworm-slim - -WORKDIR /app - -RUN chown -R nobody /app - -RUN apt-get -qq update - -# Set the locale -ENV LANG C.UTF-8 - -# We need SSL -RUN apt-get -qq install openssl ca-certificates - -# We have to redefine this here since it goes out of scope for each build stage -ARG BUILD_ENV=prod - -COPY --from=builder /app/_build/$BUILD_ENV/rel/astarte_trigger_engine . - -# Change to non-root user -USER nobody - -CMD ["./bin/astarte_trigger_engine", "start"] From 591ce89fd516063fb8e706fd983e411d8df6b333 Mon Sep 17 00:00:00 2001 From: Gabriele Ghio Date: Wed, 19 Jun 2024 15:56:41 +0200 Subject: [PATCH 2/3] docker compose dev section `docker compose` is now capable of starting containers in dev mode, without creating the release. The previous `docker-compose.yml` file now points to the common `Dockerfile` located at the root of Astarte (see previous commit) A new `docker-compose.dev.yml` has been added, which, if started in cascade with the first, allows for the creation of a development environment for Astarte with the possibility of hot-reloading and rebuild, with each code change To start the dev mode functionality, according to the specifications (https://docs.docker.com/compose/multiple-compose-files/merge/) `docker compose -f docker-compose.yml -f docker-compose.dev.yml watch` Signed-off-by: Gabriele Ghio --- docker-compose.dev.yml | 117 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 18 +++++-- 2 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 docker-compose.dev.yml diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 000000000..90d1d3031 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,117 @@ +services: + astarte-housekeeping: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + # TODO run migration script + # set -e + # mix eval Elixir.Astarte.Housekeeping.ReleaseTasks.init_database + # mix eval Elixir.Astarte.Housekeeping.ReleaseTasks.migrate + mix run --no-halt + develop: + watch: + - path: apps/astarte_housekeeping/lib + action: rebuild + astarte-housekeeping-api: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + mix phx.server + develop: + watch: + - path: apps/astarte_housekeeping_api/lib + action: sync + target: /src/lib + astarte-realm-management: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + mix run --no-halt + develop: + watch: + - path: apps/astarte_realm_management/lib + action: rebuild + astarte-realm-management-api: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + mix phx.server + develop: + watch: + - path: apps/astarte_realm_management_api/lib + action: sync + target: /src/lib + astarte-pairing: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + mix run --no-halt + develop: + watch: + - path: apps/astarte_pairing/lib + action: rebuild + astarte-pairing-api: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + mix phx.server + develop: + watch: + - path: apps/astarte_pairing_api/lib + action: sync + target: /src/lib + astarte-appengine-api: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + mix phx.server + develop: + watch: + - path: apps/astarte_appengine_api/lib + action: sync + target: /src/lib + astarte-data-updater-plant: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + mix run --no-halt + develop: + watch: + - path: apps/astarte_data_updater_plant/lib + action: rebuild + astarte-trigger-engine: + build: + target: builder + args: + BUILD_ENV: dev + command: + - | + mix run --no-halt + develop: + watch: + - path: apps/astarte_trigger_engine/lib + action: rebuild diff --git a/docker-compose.yml b/docker-compose.yml index 8c29ee6d7..a2da8dbe4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,8 @@ -version: '3.8' services: astarte-housekeeping: image: astarte/astarte_housekeeping:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_housekeeping env_file: - ./compose.env @@ -14,6 +14,7 @@ services: astarte-housekeeping-api: image: astarte/astarte_housekeeping_api:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_housekeeping_api env_file: - ./compose.env @@ -41,6 +42,7 @@ services: astarte-realm-management: image: astarte/astarte_realm_management:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_realm_management env_file: - ./compose.env @@ -52,6 +54,7 @@ services: astarte-realm-management-api: image: astarte/astarte_realm_management_api:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_realm_management_api env_file: - ./compose.env @@ -73,6 +76,7 @@ services: astarte-pairing: image: astarte/astarte_pairing:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_pairing env_file: - ./compose.env @@ -86,6 +90,7 @@ services: astarte-pairing-api: image: astarte/astarte_pairing_api:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_pairing_api env_file: - ./compose.env @@ -107,16 +112,17 @@ services: astarte-appengine-api: image: astarte/astarte_appengine_api:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_appengine_api env_file: - ./compose.env environment: - APPENGINE_API_ROOMS_AMQP_CLIENT_HOST: "rabbitmq" + APPENGINE_API_ROOMS_AMQP_CLIENT_HOST: rabbitmq restart: on-failure depends_on: - - "rabbitmq" - - "scylla" - - "traefik" + - rabbitmq + - scylla + - traefik labels: - "traefik.enable=true" - "traefik.http.routers.astarte-appengine-api.rule=Host(`api.astarte.localhost`)" @@ -131,6 +137,7 @@ services: astarte-data-updater-plant: image: astarte/astarte_data_updater_plant:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_data_updater_plant env_file: - ./compose.env @@ -149,6 +156,7 @@ services: astarte-trigger-engine: image: astarte/astarte_trigger_engine:snapshot build: + dockerfile: ../../Dockerfile context: apps/astarte_trigger_engine env_file: - ./compose.env From 87d67d4992b942d5ebe9091245410f2179a0bb91 Mon Sep 17 00:00:00 2001 From: Gabriele Ghio Date: Fri, 5 Jul 2024 15:51:15 +0200 Subject: [PATCH 3/3] restored the import on astarte_housekeeping By replacing `Application.load(:astarte_data_access)` with `Application.ensure_loaded(:astarte_data_access)` it is now possible to start the import via ``` mix eval Elixir.Astarte.Housekeeping.ReleaseTasks.init_database mix eval Elixir.Astarte.Housekeeping.ReleaseTasks.migrate ``` Signed-off-by: Gabriele Ghio --- .../lib/astarte_housekeeping/release_tasks.ex | 8 ++------ docker-compose.dev.yml | 7 +++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/apps/astarte_housekeeping/lib/astarte_housekeeping/release_tasks.ex b/apps/astarte_housekeeping/lib/astarte_housekeeping/release_tasks.ex index e89b092bf..ff177c0a9 100644 --- a/apps/astarte_housekeeping/lib/astarte_housekeeping/release_tasks.ex +++ b/apps/astarte_housekeeping/lib/astarte_housekeeping/release_tasks.ex @@ -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. @@ -53,8 +53,6 @@ defmodule Astarte.Housekeeping.ReleaseTasks do raise "init_database failed" end - - :ok = stop_services() end def migrate do @@ -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 @@ -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!())}") diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 90d1d3031..15b3f3d50 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -6,10 +6,9 @@ services: BUILD_ENV: dev command: - | - # TODO run migration script - # set -e - # mix eval Elixir.Astarte.Housekeeping.ReleaseTasks.init_database - # mix eval Elixir.Astarte.Housekeeping.ReleaseTasks.migrate + set -e + mix eval Elixir.Astarte.Housekeeping.ReleaseTasks.init_database + mix eval Elixir.Astarte.Housekeeping.ReleaseTasks.migrate mix run --no-halt develop: watch: