Hi
I’m a beginner with Docker and Gitlab CI/CD and i’m trying to deploy an Elixir app with Docker and Gitlab ci/cd but i’m facing some issues.
I tried several solutions and read lot of doc and threads but i’m stucked
It’s probably a problem with my Dockerfile, i tested one Dockerfile that works in Gitlab for build stage and not for deploy stage, and another Dockerfile that works for deploy stage but not for build one.
Below the Dockerfile which works for build stage :
FROM debian:buster
RUN apt-get update && apt-get install -y \
locales \
curl \
make \
p7zip \
wget \
musl \
build-essential \
ca-certificates \
gcc \
libtool-bin \
libsm6 \
inotify-tools \
zip \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -rf /var/lib/apt/lists/*
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb \
&& dpkg -i erlang-solutions_2.0_all.deb \
&& apt-get update && apt-get install -y \
esl-erlang \
elixir \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& elixir -v
RUN mix local.hex --force \
&& mix local.rebar --force
WORKDIR /app
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
and then the one that works for deploy but build failed (the error is that mix is command not found :
ARG ELIXIR_VERSION=1.13.2
ARG OTP_VERSION=24.3.2
ARG DEBIAN_VERSION=bullseye-20210902-slim
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
FROM ${BUILDER_IMAGE} as builder
RUN apt-get update && apt-get install -y \
locales \
curl \
make \
p7zip \
wget \
musl \
build-essential \
ca-certificates \
gcc \
libtool-bin \
libsm6 \
inotify-tools \
zip \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -rf /var/lib/apt/lists/*
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb \
&& dpkg -i erlang-solutions_2.0_all.deb \
&& apt-get update && apt-get install -y \
esl-erlang \
elixir \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& elixir -v
RUN mix local.hex --force \
&& mix local.rebar --force
WORKDIR /app
ENV MIX_ENV="prod"
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile
COPY priv priv
COPY lib lib
COPY assets assets
RUN mix assets.deploy
RUN mix compile
COPY config/runtime.exs config/
COPY rel rel
RUN mix release
FROM ${RUNNER_IMAGE}
RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -f /var/lib/apt/lists/*_*
RUN apt-get update && apt-get install -y \
locales \
curl \
make \
p7zip \
wget \
musl \
build-essential \
ca-certificates \
gcc \
libtool-bin \
libsm6 \
inotify-tools \
zip \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -rf /var/lib/apt/lists/*
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
WORKDIR "/app"
RUN chown nobody /app
# set runner ENV
ENV MIX_ENV="prod"
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/ze_cats_dev ./
USER nobody
CMD ["/app/bin/server"]
# # Appended by flyctl
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
My gitlab-ci.yml
stages:
- build
- test
- deploy
test:
stage: test
before_script:
- apt-get update -qq && apt-get install -y curl
- mix local.rebar --force
- mix deps.get --only test
script:
- mix test
app_image:
image: docker
services:
- docker:dind
only:
- not_run
variables:
MIX_ENV: "prod"
stage: build
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker build --no-cache -f Dockerfile -t <my-private-gitlab-registry-container>:latest .
- docker push <my-private-gitlab-registry-container>:latest
elixir:
stage: build
image:<my-private-gitlab-registry-container>:latest
cache:
key: ${CI_COMMIT_REF_SLUG}__app
paths:
- _build/
- deps/
artifacts:
paths:
- _build/prod/rel
script:
- make qa
- make build-prod
deploy application:
image: docker:latest
stage: deploy
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
before_script:
- apk add curl
- curl -L https://fly.io/install.sh | sh
script:
- /root/.fly/bin/fly auth login
- /root/.fly/bin/flyctl deploy --local-only
I use a Makefile
qa:
MIX_ENV=test mix local.rebar --force
MIX_ENV=test mix deps.get
build-prod:
rm -Rf _build/prod/rel
MIX_ENV=prod mix local.rebar --force
MIX_ENV=prod mix deps.get --only prod
MIX_ENV=prod mix compile
MIX_ENV=prod mix assets.deploy
MIX_ENV=prod mix release --force
Anyone has an idea of how i can solve my problem ?