Giter Site home page Giter Site logo

mix_docker's Introduction

mix docker

🚨🚨 This project is now obsolete and abandoned! 🚨🚨

With docker multi-stage builds you can simply use:

# Dockerfile
FROM elixir:1.6.5-alpine as build

# install build dependencies
RUN apk add --update git

# prepare build dir
RUN mkdir /app
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ENV MIX_ENV=prod

# install mix dependencies
COPY mix.exs mix.lock ./
COPY config ./
COPY deps ./
RUN mix deps.compile

# build release
COPY . .
RUN mix release --no-tar --verbose

# prepare release image
FROM alpine:3.6
RUN apk add --update bash openssl

RUN mkdir /app && chown -R nobody: /app
WORKDIR /app
USER nobody

COPY --from=build /app/_build/prod/rel/myapp ./

ENV REPLACE_OS_VARS=true
ENV HTTP_PORT=4000 BEAM_PORT=14000 ERL_EPMD_PORT=24000
EXPOSE $HTTP_PORT $BEAM_PORT $ERL_EPMD_PORT

ENTRYPOINT ["/app/bin/myapp"]

and standard docker build.

OLD README CONTENT

Build Status

Put your Elixir app inside minimal Docker image. Based on alpine linux and distillery releases.

Installation

  1. Add mix_docker to your list of dependencies in mix.exs:
def deps do
  [{:mix_docker, "~> 0.5.0"}]
end
  1. Configure Docker image name
# config/config.exs
config :mix_docker, image: "recruitee/hello"
  1. Run mix docker.init to init distillery release configuration

  2. Run mix docker.build & mix docker.release to build the image. See Usage for more.

Guides

Usage

Build a release

Run mix docker.build to build a release inside docker container

Create minimal run container

Run mix docker.release to put the release inside minimal docker image

Publish to docker registry

Run mix docker.publish to push newly created image to docker registry

All three in one pass

Run mix docker.shipit

Customize default Dockerfiles

Run mix docker.customize

FAQ

How to configure my app?

Using ENV variables. The provided Docker images contain REPLACE_OS_VARS=true, so you can use "${VAR_NAME}" syntax in config/prod.exs like this:

config :hello, Hello.Endpoint,
  server: true,
  url: [host: "${DOMAIN}"]

config :hello, Hello.Mailer,
  adapter: Bamboo.MailgunAdapter,
  api_key: "${MAILGUN_API_KEY}"

How to configure the image tag?

By default, the image tag uses the following format: {mix-version}.{git-count}-{git-sha} You can provide your own tag template in config/prod.exs like this:

# config/config.exs
config :mix_docker,
  tag: "dev_{mix-version}_{git-sha}"

Additionally, you can pass the tag as an argument to mix docker.publish and mix docker.shipit:

mix docker.publish --tag "{mix-version}-{git-branch}"

See below for a list of possible variables

Variable Description
{mix-version} Current project version from mix.exs
{rel-version} Default distillery release version
{git-sha} Git commit SHA (10 characters)
{git-shaN} Git commit SHA (N characters)
{git-count} Git commit count
{git-branch} Git branch

What version of Erlang/Elixir is installed by default?

The default dockerfiles are based on bitwalker/alpine-erlang and elixir installed from apk repository

The following table summarizes the default versions:

mix_docker version alpine erlang elixir
up to 0.3.2 3.4 18.3 elixir@edge at the time of build
0.4.0 3.5 19.2 elixir@edge=1.4.1-r0
0.4.1 3.5 19.2 elixir@edge=1.4.2-r0

Please note that you can use any version you want by customizing your dockerfiles. See mix docker.customize for reference.

How to attach to running app using remote_console?

The easiest way is to docker exec into running container and run the following command, where CID is the app container IO and hello is the name of your app.

docker exec -it CID /opt/app/bin/hello remote_console

How to install additional packages into build/release image?

First, run mix docker.customize to copy Dockerfile.build and Dockerfile.release into your project directory. Now you can add whatever you like using standard Dockerfile commands. Feel free to add some more apk packages or run some custom commands. TIP: To keep the build process efficient check whether a given package is required only for compilation (build) or runtime (release) or both.

How to move the Dockerfiles?

You can specify where to find the two Dockerfiles in the config.

# config/config.exs
config :mix_docker,
  dockerfile_build: "path/to/Dockerfile.build",
  dockerfile_release: "path/to/Dockerfile.release"

The path is relative to the project root, and the files must be located inside the root.

How to configure an Umbrella app?

The default build Dockerfile does not handle the installation of umbrella app deps, so you will need to modify it to match the structure of your project.

Run mix docker.customize and then edit Dockerfile.build to copy across each of your umbrella's applications.

COPY mix.exs mix.lock ./

RUN mkdir -p apps/my_first_app/config
COPY apps/my_first_app/mix.exs apps/my_first_app/
COPY apps/my_first_app/config/* apps/my_first_app/config/

RUN mkdir -p apps/my_second_app/config
COPY apps/my_second_app/mix.exs apps/my_second_app/
COPY apps/my_second_app/config/* apps/my_second_app/config/

# etc.

How to configure a Phoenix app?

To run a Phoenix app you'll need to install additional packages into the build image: run mix docker.customize.

Modify the apk --no-cache --update add command in the Dockerfile.build as follows (add nodejs and python):

# 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++ \
      nodejs python \
      elixir@edge && \
    rm -rf /var/cache/apk/*

Install nodejs dependencies and cache them by adding the following lines before the COPY command:

# Cache node deps
COPY package.json ./
RUN npm install

Build and digest static assets by adding the following lines after the COPY command:

RUN ./node_modules/brunch/bin/brunch b -p && \
    mix phoenix.digest

Add the following directories to .dockerignore:

node_modules
priv/static

Remove config/prod.secret.exs file and remove a reference to it from config/prod.exs. Configure your app's secrets directly in config/prod.exs using the environment variables.

Make sure to add server: true to your app's Endpoint config.

Build the images and run the release image normally.

Check out this post for detailed walkthrough of the Phoenix app configuration.

mix_docker's People

Contributors

aeons avatar alex-kovshovik avatar crowdhailer avatar cstar avatar lpil avatar pragmaticivan avatar smoku avatar teamon avatar tlvenn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mix_docker's Issues

Module missing after build

First off, this is awesome. Everything has worked pretty smoothly up until now.

I'm using mix_docker to build a phoenix app, with absinthe & absinthe_plug. When I run my app with iex -S mix phoenix.server, it runs fine. However, When I make a request on my app build with mix_docker, it gives me an error missing Absinthe.Plug:

** (exit) an exception was raised:
    ** (UndefinedFunctionError) function Absinthe.Plug.call/2 is undefined (module Absinthe.Plug is not available)

Any suggestions on how to debug? I tried adding it to my list of applications, but that didn't seem to help at all.

Config for different Dockerfile for release doesnt work

In my config, I add the path for my release just like in
https://github.com/Recruitee/mix_docker#how-to-move-the-dockerfiles

config :mix_docker,
  image: "path/to/image",
  tag: "{app}_{mix-version}_{git-sha}",
  dockerfile_release: "release/Dockerfile.release"

And when I try to do mix docker.release it just run the default Dockerfile.release not the costume written by me.

I tried differents ways to write the path, like ./path, /path, etc. Different names for the Dockerfile and it still doesn't work.

Any ideas?

Allow deps folder to be copied over to improve build time

Right now, the deps folder is in the .dockerignore and therefore not being copied over to the build image which means that all deps are retrieved from scratch.

I don't see any reason to prevent them from being copied over as it will speed up the build time significantly if this step (fetching deps) can be bypassed because the deps folder in the docker image has been warmed already.

For example, in my CI server, I run mix deps.get && mix test as a step before running mix docker.shipit. By removing the deps folder from .dockerignore, i cut the build time in half.

Allow to pass version as argument

Thanks for this little gem @teamon and your always useful blog posts !

In a continuous delivery environment, it's useful / needed to be able to provide the release identifier which does not often match the version you would find in the mix file. For example, many companies, will use the git commit id of the head of the version being built and use that as the docker tag to push to their registry.

mix docker.publish is broken on master

When i try to use mix docker.publish, i get the following error:

01:17:34.922 [debug] $ docker push repo/myproject:2a475ece8a
"docker push" requires exactly 1 argument(s).
See 'docker push --help'.

I configured my tag using:

config :mix_docker,
  image: "repo/myproject",
  tag: "{git-sha}"

Passing the args to docker push seems to create an invisible character or something that Docker does not like. Also if args is really needed for docker push, the proper syntax is:
docker push [OPTIONS] NAME[:TAG]

Right now, the code append the options after the NAME[:TAG]:

defp docker(:push, image, args) do
    system! "docker", ["push", image, args]
  end

mix docker.release causes a missing environment error in gitlab ci

#Dockerfile.release 
FROM bitwalker/alpine-elixir:latest

# install gcc make
RUN set -x\
 && apk add --no-cache\
  gcc\
  make\
  musl-dev

EXPOSE 8000
ENV PORT=8000 MIX_ENV=prod REPLACE_OS_VARS=true SHELL=/bin/bash
WORKDIR /app
COPY ./myapp.tar.gz ./
RUN tar xfz myapp.tar.gz
ENTRYPOINT ["bin/myapp"]
$ mix docker.release
** (MatchError) no match of right hand side value: {:error, :missing_environment}
    lib/mix_docker.ex:193: MixDocker.release_version/0
    lib/mix_docker.ex:29: MixDocker.release/1
    (mix) lib/mix/task.ex:301: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:75: Mix.CLI.run_task/2
    (elixir) lib/code.ex:376: Code.require_file/2

mix docker.build works but not release.
also it works in my own computer just not in ci

Fails to compile :guardian dependency

I'm experiencing this issue when trying to build an image by running mix docker.build. It says that it's not possible to compile the :guardian dependency because it fails, I'm sure I configured Guardian according to the docs. As I said before this is happening after running mix docker.build to build a docker image.

This is the error I'm getting:

== Compilation error on file lib/guardian.ex ==
** (RuntimeError) Guardian is not configured
    lib/guardian.ex:26: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

could not compile dependency :guardian, "mix compile" failed. You can recompile this dependency with "mix deps
.compile guardian", update it with "mix deps.update guardian" or clean it with "mix deps.clean guardian"
The command '/bin/sh -c mix do deps.get, deps.compile' returned a non-zero code: 1
** (MatchError) no match of right hand side value: {%IO.Stream{device: :standard_io, line_or_bytes: :line, raw
: false}, 1}
    lib/mix_docker.ex:153: MixDocker.system!/2
    lib/mix_docker.ex:123: MixDocker.with_dockerfile/2
    lib/mix_docker.ex:18: MixDocker.build/1
    (mix) lib/mix/task.ex:300: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2

Does anyone has experienced this problem with guardian?

Any help would be greatly appreciated,

Thanks!

How to run the migrations

I followed the steps from Kovshovik, and got the docker build and release working. I was also able to run the production image and got the following message:

23:48:06.934 [info] Running Hello.Endpoint with Cowboy using http://localhost:8080

However following directions at the distillery for running migrations, how (and from which directory, since /opt/app does not exist as I checked) do i run this command:
bin/hello migrate

Provide SSH key securely to the docker build

Right now unless I am missing something, there is no easy or safe way to provide an ssh key to the docker build so that dependencies that are pulled with ssh would be resolved properly.

Reading on http://blog.cloud66.com/using-ssh-private-keys-securely-in-docker-build and how Habitus is solving this elegantly, I believe their solution is best and should be relatively simple to implement.

The idea is to open a web server on the docker network to expose the ssh key or any other secrets that the Dockerfile could fetch and once used, delete it, all in one transaction, leaving no trace behind whatsoever.

RUN wget -O ~/.ssh/id_rsa http://192.168.99.1:8080/secrets/file/id_rsa && mix do deps.get, deps.compile && rm ~/.ssh/id_rsa

We should also add github as an known host automatically:

# Adding github to known hosts
RUN mkdir ~/.ssh && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

What do you think @teamon ?

Error caused by Alpine repository conficts "ERROR: unsatisfiable constraints"

Thanks for this amazing library.

I'm including PR to this issue

I've noticed that the Dockerfile.build points to Alpine edge repo. The pages versions there were changed and this caused error below

Sending build context to Docker daemon  20.43MB
Step 1/12 : FROM bitwalker/alpine-erlang:19.3.4
19.3.4: Pulling from bitwalker/alpine-erlang
43d680a959df: Pulling fs layer
f9ea58018904: Pulling fs layer
8787bc84edab: Pulling fs layer
43d680a959df: Verifying Checksum
43d680a959df: Download complete
43d680a959df: Pull complete
f9ea58018904: Pull complete
8787bc84edab: Verifying Checksum
8787bc84edab: Download complete
8787bc84edab: Pull complete
Digest: sha256:6ebee1ec696ceaa6ee0ca037d4c6d84b29d68e2f6554ef30fb281e38076df7fc
Status: Downloaded newer image for bitwalker/alpine-erlang:19.3.4
 ---> 0b1b039ea6f4
Step 2/12 : ENV HOME /opt/app/ TERM xterm
 ---> Running in 33bd66402555
 ---> 19c4059a1814
Removing intermediate container 33bd66402555
Step 3/12 : RUN echo "@edge http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories &&     apk --update upgrade musl &&     apk --no-cache add       git make g++       elixir@edge=1.4.4-r0 &&     rm -rf /var/cache/apk/*
 ---> Running in a44019b174a5
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
(1/2) Upgrading musl (1.1.16-r10 -> 1.1.16-r13)
(2/2) Upgrading musl-utils (1.1.16-r10 -> 1.1.16-r13)
Executing busybox-1.26.2-r5.trigger
OK: 34 MiB in 25 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  elixir-1.4.2-r0:
    breaks: world[elixir=1.4.4-r0]
The command '/bin/sh -c echo "@edge http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories &&     apk --update upgrade musl &&     apk --no-cache add       git make g++       elixir@edge=1.4.4-r0 &&     rm -rf /var/cache/apk/*' returned a non-zero code: 1
** (MatchError) no match of right hand side value: {%IO.Stream{device: :standard_io, line_or_bytes: :line, raw: false}, 1}
    lib/mix_docker.ex:180: MixDocker.system!/2
    lib/mix_docker.ex:150: MixDocker.with_dockerfile/2
    lib/mix_docker.ex:20: MixDocker.build/1
    (mix) lib/mix/task.ex:300: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2

Important fragment

ERROR: unsatisfiable constraints:
  elixir-1.4.2-r0:
    breaks: world[elixir=1.4.4-r0]

I solved it changing Dockerfile.build to latests stable Alpine repo which is now version 3.6.

And I've changed Elixir version to 1.4.2.

Also when packaging app, make sure to set up Elixir version the mix.exs

  def project do
    [...
     elixir: "~> 1.4.2",
     ...]
  end

Ecto Migration missing from release package

I've been trying to run ecto migrations using Distillery migrate custom command described here without any luck. It always resulted in Ecto telling me all migrations has already been run.

After further investigation, looking into the tarball created by mix docker.build I cannot find anywhere my application ecto migrations.

When I run the mix release --env=prod directly on my local machine, a symbolic link is created to make ecto migrations accessible:

> pwd
/Users/gottfrois/Code/notifications/_build/prod/lib/notifications
> ls -l
total 8
drwxr-xr-x  21 gottfrois  staff   714  6 déc 18:22 consolidated
drwxr-xr-x  43 gottfrois  staff  1462  6 déc 18:22 ebin
lrwxr-xr-x   1 gottfrois  staff    16 30 nov 14:33 priv -> ../../../../priv

Whereas when packaging a release using mix docker.build it does not:

> mix docker.build
Sending build context to Docker daemon  18.94MB
...
==> Release successfully built!
...
> tar -xvzf ./notifications.tar.gz
...
> cd lib/notifications-0.0.1
> ls -l
total 0
drwxr-xr-x  21 gottfrois  staff   714  6 déc 18:35 consolidated
drwxr-xr-x  43 gottfrois  staff  1462  6 déc 18:35 ebin

I tried to find my migrations anywhere in the package without luck:

> find . -name "*migration*"
./lib/phoenix-1.3.0/priv/templates/phoenix.gen.model/migration.exs
./lib/phoenix-1.3.0/priv/templates/phx.gen.schema/migration.exs

Here are my dockerfiles:

FROM elixir:1.5

ENV DEBIAN_FRONTEND=noninteactive
ENV MIX_ENV=prod
ENV REPLACE_OS_VARS=true
ENV HOME=/opt/app/ TERM=xterm

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

# Install deps
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    make \
    curl \
    git \
    && apt-get clean

WORKDIR /opt/app

# Cache elixir deps
COPY mix.exs mix.lock ./
RUN mix deps.get
COPY config ./config
RUN mix deps.compile
COPY . .
RUN mix release --env=prod
FROM elixir:1.5

ENV DEBIAN_FRONTEND=noninteactive
ENV MIX_ENV=prod
ENV REPLACE_OS_VARS=true
ENV PORT 80
ENV SHELL=/bin/bash

EXPOSE 80

WORKDIR /home/app

COPY ./notifications.tar.gz ./
RUN tar xfz notifications.tar.gz

ENTRYPOINT ["bin/notifications"]

Did I miss something in the dockerfiles somehow?

Thx!

Umbrella App mix docker.build failed

Following error displayed when running mix docker.build. I am not sure if this is related to #15 where app and version needs to specified, the referenced distillery's issue, bitwalker/distillery#201

** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
(elixir) lib/io.ex:445: IO.chardata_to_string(nil)
(elixir) lib/path.ex:475: Path.do_join/3
(elixir) lib/path.ex:470: Path.join/2
(elixir) lib/path.ex:450: Path.join/1
(distillery) lib/mix/lib/releases/archiver.ex:31: Mix.Releases.Archiver.make_tar/1
(distillery) lib/mix/lib/releases/archiver.ex:17: Mix.Releases.Archiver.archive/1
(distillery) lib/distillery/tasks/release.ex:113: Mix.Tasks.Release.run/1
(mix) lib/mix/task.ex:294: Mix.Task.run_task/3

The command '/bin/sh -c mix release --env=prod --verbose' returned a non-zero code: 1
** (MatchError) no match of right hand side value: {%IO.Stream{device: :standard_io, line_or_bytes: :line, raw: false}, 1}
lib/mix_docker.ex:153: MixDocker.system!/2
lib/mix_docker.ex:123: MixDocker.with_dockerfile/2
lib/mix_docker.ex:18: MixDocker.build/1
(mix) lib/mix/task.ex:294: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2

Umbrella App mix docker.build and mix docker.release each sub-app using separate Dockerfile.build.sub_app<N> and Dockerfile.release.sub_app<N>

I have a top level umbrella_app with 2 sub-apps: sub_app1 and sub_app2.
I would like to carry out mix docker.build and mix docker.release for each sub-app separately, each using a different Dockerfile.build.sub_app1, Dockerfile.build.sub_app2 and Dockerfile.release.sub_app1 and Dockerfile.release.sub_app2.

In each of the Dockerfile.build.sub_app1 and Dockerfile.build.sub_app2, I would like to invoke a different mix release --profile=<sub_app>:prod

How could this be achieved? Is this a correct practice?

I managed to do so by creating custom Dockerfile.build for each sub-app within which I invoke mix release --profile=<sub_app>:prod by editing my umbrella project config/config.exs config section as such:

# config :mix_docker,
#   image: "app/sub_app1",
#   dockerfile_build: "./Dockerfile.build.sub_app1",
#   dockerfile_release: "./Dockerfile.release.sub_app1"

config :mix_docker,
  image: "app/sub_app2",
  dockerfile_build: "./Dockerfile.build.sub_app2",
  dockerfile_release: "./Dockerfile.release.sub_app2"

I then manually edit and toggle on/off each section as I trigger mix docker.build for each case.

==> Writing tarball to _build/prod/rel/sub_app1/releases/<version>/sub_app1.tar.gz
==> Updating tarball
==> Tarball updated!
==> Release successfully built!
    You can run it in one of the following ways:
      Interactive: _build/prod/rel/sub_app1/bin/sub_app1 console
      Foreground: _build/prod/rel/sub_app1/bin/sub_app1 foreground
      Daemon: _build/prod/rel/sub_app1/bin/sub_app1 start
 ---> a2da9353baed
Removing intermediate container 35a7361860a6
Successfully built a2da9353baed
Docker image app/sub_app1:build has been successfully created

However, mix docker.release always fails as it expects my tarball to be created at /opt/app/_build/prod/rel/umbrella_app/releases//umbrella_app.tar.gz

16:17:45.630 [debug] $ docker create --name mix_docker-980782 app/sub_app1:build
b9f43d3a25a19f0ea43e0bd06de4a66f07171aadf8a2c551eef7c3841b6fe77d

16:17:45.719 [debug] $ docker cp mix_docker-980782:/opt/app/_build/prod/rel/umbrella_app/releases/<version>/umbrella_app.tar.gz umbrella_app.tar.gz
Error response from daemon: lstat /var/lib/docker/overlay/e129f7d73db871107dbd7b69832632150768a05098bc60bc5f479a18fec97307/merged/opt/app/_build/prod/rel/umbrella_app/releases/<version>/umbrella_app.tar.gz: no such file or directory
** (MatchError) no match of right hand side value: {%IO.Stream{device: :standard_io, line_or_bytes: :line, raw: false}, 1}
    (mix_docker) lib/mix_docker.ex:179: MixDocker.system!/2
    (mix_docker) lib/mix_docker.ex:36: anonymous fn/4 in MixDocker.release/1
    (mix_docker) lib/mix_docker.ex:33: MixDocker.release/1
    (mix) lib/mix/task.ex:294: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2

Where it should be doing instead in order to work correctly:

docker cp mix_docker-980782:/opt/app/_build/prod/rel/sub_app1/releases/<version>/sub_app1.tar.gz sub_app1.tar.gz

However, the current implementation defaults app bundle create using the umbrella_app being the app_name(). Where it should inspect and detect from the release profile info for the app name to use.

Is my understanding correct? Am I using the package correctly?

How can I set latest tag

I am using mix docker.publish to push my image to our private registry and it works well, the image is published somewhere like registry.example.com/app:0.0.1.47-376334006e.
Know I want to be able to set the latest tag on the latest push. Is there a way to do that here?

Remove release.tar.gz from root folder after running build.release

Right now when building the release image the #{app}.tar.gz is copied into the project's root
folder and stays there after the build is complete.

It would be better to remove it after the build or add a configuration parameter for the storage folder and make it tarballs by default.

SSL Error: certificate expired on builds...

Hi,

Trying to run mix docker.build and getting a bunch of SSL certificate expired errors when running mix deps.get from the docker build. mix deps.get works fine locally.

mix_docker version 0.4.2

RUN mix do deps.get, deps.compile

[error] SSL: :certify: ssl_handshake.erl:1511:Fatal error: certificate expired
{:failed_connect, [{:to_address, {'repo.hex.pm', 443}}, {:inet, [:inet], {:tls_alert, 'certificate expired'}}]}

Anyone else seeing these errors? Seems it just started happening of recent??

Thank you!

Nothing happens when running the release with the start command

Hi guys,

Nothing happens when running the release with the start command, but other commands such as console and foreground work as expected. When I create the release manually with MIX_ENV=prod mix do compile, release --env=prod and then run it locally with the start command, it works as expected, which means that I can start, restart, ping and stop the service with no problem whatsoever.

Has anyone experienced this issue?

Thanks!

push to private repository

Is it possible to use publish to push to a user/password protected private repo?

I tried to use docker login before docker.publish but it fails with no basic auth credentials

Allow dockerfiles to be in a folder

It would be nice if you could configure where to find the dockerfiles. Either just a dockerfile folder config or a path to each of the files.

Add mix_docker configuration to prepend "sudo" to docker commands

I am using docker on Linux with sudo (I don't want to add my user account to the docker group because it "grants privileges equivalent to the root user"), and I am using asdf on my user account to manage elixir versions. In order to use mix_docker right now I would need to set up asdf on my root account and then I would need to use sudo mix docker.build.

I would like to propose adding a use_docker_with_sudo configuration option which would prepend "sudo" to docker commands. This way I'd be able to run mix docker.build and only docker commands would be run as root.

What do you think?

(I understand this tool is "deprecated" so I guess I'm only asking to know if a contribution PR would be merged and if there would be a release anytime soon in the future)

Deploy to custom docker image registry

Hello,

I want to be able to deploy my tagged image to a custom registry I host myself. Changing the Tag nearly works for this i.e.:

config :mix_docker, 
  image: "myimage",
  tag: "myimagerepo.azurecr.io/{mix-version}.{git-count}-{git-sha}"

Obviously this prefixes the tagging as follows: myimage:myimagerepo.azurecr.io/{mix-version}.{git-count}-{git-sha} which doesn't work.

So my suggestion is that I will create a pull request that specifies the repository separately and creates a tag like:

myimagerepo.azurecr.io/myimage:{mix-version}.{git-count}-{git-sha}

The config option would be:

config :mix_docker, 
   repository_host: "myimagerepo.azurecr.io"

Thoughts?

Umbrella app

Any pointers to get this to work with umbrella apps

About node packages

Is better to install node packages when building docker?
and add node_modules folder into .dockerignore.

Running Release Fails after "set include_erts: false"

I followed the guide here at https://shovik.com/blog/8-deploying-phoenix-apps-with-docker and it was advised to not bundle the erts files, that is, set include_erts: false in the rel/config.exs. I was both able to run mix docker.build and mix docker.release but when it comes time to running the container it errors out stating

{"init terminating in do_boot",{load_failed,[file_io_server,heart,lists,error_handler,erl_eval,code_server,erl_lint,application_master,gen_server,kernel,file_server,application,filename,gen_event,gen,supervisor,code,ets,erl_parse,proc_lib,file,application_controller,error_logger]}}
init terminating in do_boot ()

Crash dump is being written to: erl_crash.dump...done

Shutting down..
Node is not running!

If I then instead set to include erts to true
set include_erts: true

then it is able to run the container/initiate the phoenix server. If it helps at all I'm running this on OSX without any other changes to the standard included Dockerfile build and release files.

Is it okay to use it in Production?

Hi @teamon, I'm big fan of your work (blog+tesla). Is it just a side project or is it fairly okay to use it in Production? Will this project be used/maintained for next some months ?

mix docker.release fails expanding tar.gz

Hi,

While running mix docker.release the command fails in the Dockerfile add myapp.tar.gz. Docker complains about a missing tar header hence causing the release to fail building the image.
I am running docker version 17.03.1-ce with mix_docker rev 0.4.2.

Thank you!

tarball no longer appears in project root after successful build

I did some tinkering with my Dockerfile.build to get some things to work on CI. Now I'm currently having the issue where the release tarball just never shows up, even when I reset to the previous version that was working. A dev ran this same thing on their machine and they are getting the release tarball.

When I run /bin/ls on the WORKDIR after the container builds(and it builds successfully) the tarball doesn't exist there like it used to, as it should.

Any ideas?

docker.build fails

Unsatisfiable constraints:

$ mix docker.build
warning: variable "deps" does not exist and is being expanded to "deps()", please use parentheses to remove the ambiguity or change the variable name
/home/mmartin/git/exmailer_worker/deps/dtt/mix.exs:10

11:47:45.853 [debug] $ docker build -f Dockerfile.build -t exmailer_worker:build .
Sending build context to Docker daemon 221.2 kB
Step 1/12 : FROM bitwalker/alpine-erlang:19.2.1b
19.2.1b: Pulling from bitwalker/alpine-erlang
0a8490d0dfd3: Pulling fs layer
68d9b106c1a1: Pulling fs layer
88a28439f8b3: Pulling fs layer
68d9b106c1a1: Download complete
0a8490d0dfd3: Verifying Checksum
0a8490d0dfd3: Download complete
0a8490d0dfd3: Pull complete
68d9b106c1a1: Pull complete
88a28439f8b3: Verifying Checksum
88a28439f8b3: Download complete
88a28439f8b3: Pull complete
Digest: sha256:8613d6b43bd6dba5eba50d49145e377cb52b63cf00c7b32bf8fa341566509b89
Status: Downloaded newer image for bitwalker/alpine-erlang:19.2.1b
---> b11046ea4327
Step 2/12 : ENV HOME /opt/app/ TERM xterm
---> Running in 3e7316d3c954
---> b03edb892662
Removing intermediate container 3e7316d3c954
Step 3/12 : RUN echo "@edge http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && apk update && apk --no-cache --update add git make g++ elixir@edge=1.4.2-r0 && rm -rf /var/cache/apk/*
---> Running in 70d5524d2645
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
v3.5.2-111-gb17579f3fe [http://dl-cdn.alpinelinux.org/alpine/v3.5/main]
v3.5.2-110-gd9e62397fb [http://dl-cdn.alpinelinux.org/alpine/v3.5/community]
v3.6.0-1200-gdc90c47f0c [http://dl-cdn.alpinelinux.org/alpine/edge/main]
v3.6.0-1198-g8662f54966 [http://nl.alpinelinux.org/alpine/edge/community]
OK: 16470 distinct packages available
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.5/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
elixir-1.3.4-r0:
breaks: world[elixir=1.4.2-r0]
The command '/bin/sh -c echo "@edge http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && apk update && apk --no-cache --update add git make g++ elixir@edge=1.4.2-r0 && rm -rf /var/cache/apk/*' returned a non-zero code: 1
** (MatchError) no match of right hand side value: {%IO.Stream{device: :standard_io, line_or_bytes: :line, raw: false}, 1}
lib/mix_docker.ex:179: MixDocker.system!/2
lib/mix_docker.ex:149: MixDocker.with_dockerfile/2
lib/mix_docker.ex:20: MixDocker.build/1
(mix) lib/mix/task.ex:294: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2

mix docker.build producing error when building.

19:28:33.570 [error] Loading of /opt/app/_build/prod/lib/cowboy/ebin/cowboy_websocket_handler.beam failed: :badfile


19:28:33.570 [error] beam/beam_load.c(1287): Error loading module cowboy_websocket_handler:
  mandatory chunk of type 'Atom' not found



warning: behaviour :cowboy_websocket_handler is undefined
  lib/phoenix/endpoint/cowboy_websocket.ex:1

warning: function :cowboy_req.compact/1 is undefined (module :cowboy_req is not available)
  lib/phoenix/endpoint/cowboy_websocket.ex:73

warning: function :ranch.get_port/1 is undefined (module :ranch is not available)
  lib/phoenix/endpoint/cowboy_handler.ex:114

I am trying to deploy a phoenix app to production.
Elixir - 1.4.5 and Phoenix v1.2.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.