2
votes

So I currently have a setup wherein I deploy my dockerized Phoenix application to run tests on a self hosted Drone server. Currently the issue arises that no matter what Dockerfile I use(currently alpine-elixir-phoenix or a base elixir image with the following) which installs hex/rebar like below:

# Install Hex+Rebar
    RUN mix local.hex --force && \
    mix local.rebar --force

I receive the error upon booting in Drone,

Could not find Hex, which is needed to build dependency :phoenix

I have found that by using an older version of alpine-elixir-phoenix:2.0 this issue does not come up which leads me to believe it may be something to do with hex/elixir having updated since then? Additionally if I run the commands to install hex and rebar within the container in Drone once it is instantiated there is no issue. I ran a whoami on the instantiated Drone container and the user is root if that makes a difference. Additionally if I run the container locally and run mix hex.info, it correctly states that hex is installed, however the issue is that on the Drone instantiated container this fails.

Example .drone.yml:

pipeline:
    backend_test:
    image: bitwalker/alpine-elixir-phoenix
        commands:
            - cd api
            - apk update
            - apk add postgresql-client
            - MIX_ENV=test mix local.hex --force
            - MIX_ENV=test mix local.rebar --force
            - MIX_ENV=test mix deps.get
            - MIX_ENV=test mix ecto.create
            - MIX_ENV=test mix ecto.migrate
            - mix test

Example Docker File used(bitwalker/alpine-elixir-phoenix) - https://github.com/bitwalker/alpine-elixir-phoenix/blob/master/Dockerfile

where the same installation of local.hex and local.rebar occurs in the Dockerfile on lines 29 && 30. However upon instantiation of the container it is not found and therefore must be run again in the CMDs.

Furthermore I encountered this problem again but with make and g++ not installing on alpine. I may be doing something incorrect but I cannot see where.

testbuild_env Dockerfile

FROM bitwalker/alpine-erlang:19.2.1b
ENV HOME=/opt/app/ TERM=xterm

# Install Elixir and basic build dependencies
RUN \
echo "@edge http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk update && \
apk --no-cache --update add \
  git make g++ curl \
  elixir@edge=1.4.2-r0 && \
rm -rf /var/cache/apk/*

# Install Hex+Rebar
RUN mix local.hex --force && \
mix local.rebar --force

ENV DOCKER_BUCKET test.docker.com
ENV DOCKER_VERSION 17.05.0-ce-rc1
ENV DOCKER_SHA256 4561742c2174c01ffd0679621b66d29f8a504240d79aa714f6c58348979d02c6

RUN set -x \
&& curl -fSL "https://${DOCKER_BUCKET}/builds/Linux/x86_64/docker-${DOCKER_VERSION}.tgz" -o docker.tgz \
&& echo "${DOCKER_SHA256} *docker.tgz" | sha256sum -c - \
&& tar -xzvf docker.tgz \
&& mv docker/* /usr/local/bin/ \
&& rmdir docker \
&& rm docker.tgz \
&& docker -v

COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["sh"]

with the following .drone.yml

build:
    image: test_buildenv
    commands:
      - cd api
      - apk add make
      - apk add g++
      - MIX_ENV=test mix local.hex --force
      - MIX_ENV=test mix local.rebar --force
      - docker login --username USERNAME --password PASSWORD
      - mix docker.build # creates a release file after running a dockerfile.build image
      - mix docker.release # creates a minimalist image to run the release file that was just created
      - mix docker.publish # pushes newly created image to dokcerh
    volumes:
       - /var/run/docker.sock:/var/run/docker.sock
1
I recommend providing the minimum yaml and dockerfile required to fully reproduce the issue. I also recommend reading readme.drone.io/usage/getting-started/#commands to explain how drone works. The user could definitely matter if Hex needs to be in the user PATH. Installing for user A doesn't necessarily mean it is available to user B. But this is just generic advice, since I do not know how hex / rebar install things.Brad Rydzewski
Hey Brad thanks for the great work. So I ended up encountering the same issue with missing make and g++ even though it was included within the dockerfile itself(and installed when the image was made as seen through the logs) however upon instantiation where make/g++ were needed the application failed out. Adding the apk add make and apk add g++ lines makes the application compile fine...but I'm curious now for both make/g++ and hex...why installation within the dockerfile isn't enough?Faolain

1 Answers

0
votes

The problem is that Drone builds its own isolated working environment as an extra layer on top of your docker image, so the ENV settings in your Dockerfile are not available. You need to independently tell Drone the environment info so it knows where hex is installed.

I managed to get this working by setting MIX_HOME in the .drone.yml file:

Dockerfile:

FROM bitwalker/alpine-elixir:1.8.1
RUN mix local.hex --force

.drone.yml:

pipeline:
  build:
    image: # built image of the above Dockerfile
    environment:
      MIX_HOME: /opt/app/.mix
    commands:
      - mix deps.get