Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build only fedora based packages #14

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 57 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,21 @@ These Dockerfiles are used to build docker images we use for various
[Elixir](https://hub.docker.com/r/avvo/elixir/tags/) and
[Erlang](https://hub.docker.com/r/avvo/erlang/tags/) containers at Avvo.

## Development
These scripts are only to build erlang and elixir images based on Fedora.
For alpine/ubuntu/debian, please consider [images built by Bob](https://github.com/hexpm/bob#docker-images).

1. Clone this repo
2. Edit the Dockerfile you want to update
3. Keep the primary version number of the image in sync with the Elixir version.
So tag '1.6.2' should be Elixir version 1.6.2. Any changes to the Dockerfile
that are not Elixir version related should increase the letter version.
4. Build and push an image with a version tag

Calling `push.sh` with no argument will use the directory name as the tag. For
example, the following command will push an `erlang` image with the tags
`20.2.4` and `latest` to Dockerhub:

```
cd erlang/20.2.4
../../push.sh
```
## Build an image

If an argument is passed to `push.sh`, it will be used as a suffix appended with
a `-` to the current directory name. For example, the following command will
push an `elixir` image with the tags `1.6.2-b` and `latest` to Dockerhub:
1. Clone this repo
2. Run `./push.sh` providing `ELIXIR_VERSION`, `ERLANG_VERSION` and `OS_VERSION` as argiments.

For example:
```bash
./push.sh --elixir=1.11.2 --erlang=23.1.2 --os-version=32
```
cd elixir/1.6.2
../../push.sh b
```
will build and push to 2 images:
- `avvo/eralng:23.1.2-fedora-32`
- `avvo/elixir:1.11.2-erlang-23.1.2-fedora-32`

#### Notes

Expand All @@ -38,6 +27,52 @@ cd elixir/1.6.2
namespace.
2. Test out your changes on a tag before committing and pushing to latest.

## Multistage Docker Build for Production

Lower final image size by using multistage docker build and fedora image.

```Dockerfile
FROM avvo/elixir:1.11.2-erlang-23.1.2-fedora-32 as build

# install build dependencies
RUN dnf -y update && dnf -y install \
make automake gcc gcc-c++ kernel-devel \
git

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

WORKDIR /srv

COPY . .

ENV MIX_ENV=prod

RUN mix do deps.get --only prod, deps.compile
RUN mix do compile, release

FROM fedora:32

ENV LANG=C.UTF-8

RUN set -xe \
&& dnf -y update \
&& dnf -y install \
ncurses-libs \
openssl \
&& dnf -y clean all \
&& rm -rf /var/cache/yum

EXPOSE 4000

WORKDIR /srv/app_name

COPY --from=build ./srv/_build/prod/rel/app_name .

CMD ["bin/app_name", "start"]
```

## License

MIT Licence. Do what you want, this is just configuration, nothing special.
17 changes: 17 additions & 0 deletions build-elixir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -euox pipefail

elixir=$1
erlang=$2
os_version=$3
os=fedora

tag=${elixir}-erlang-${erlang}-${os}-${os_version}
erlang_major=$(echo "${erlang}" | awk 'match($0, /^[0-9][0-9]/) { print substr( $0, RSTART, RLENGTH )}')

dockerfile="elixir-${os}.dockerfile"

docker build -t avvo/elixir:${tag} --build-arg ELIXIR=${elixir} --build-arg ERLANG=${erlang} --build-arg ERLANG_MAJOR=${erlang_major} --build-arg OS_VERSION=${os_version} -f ${dockerfile} ./

echo ${tag}
15 changes: 15 additions & 0 deletions build-erlang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -euox pipefail

erlang=$1
os_version=$2
os=fedora

tag=${erlang}-${os}-${os_version}

dockerfile="erlang-${os}.dockerfile"

docker build -t avvo/erlang:${tag} --build-arg ERLANG=${erlang} --build-arg OS_VERSION=${os_version} -f ${dockerfile} ./

echo ${tag}
49 changes: 0 additions & 49 deletions elixir-circleci/Dockerfile

This file was deleted.

25 changes: 25 additions & 0 deletions elixir-fedora.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Adapted from:
# https://github.com/hexpm/bob/blob/b0d1aacf386d90ae2a4897ad769b6b074a33b5ae/priv/scripts/docker/elixir-alpine.dockerfile

ARG ARCH
ARG OS_VERSION
ARG ERLANG

FROM fedora:${OS_VERSION} AS build

RUN dnf -y update && dnf -y install \
wget \
ca-certificates \
unzip \
make

ARG ELIXIR
ARG ERLANG_MAJOR

RUN wget -q -O elixir.zip "https://repo.hex.pm/builds/elixir/v${ELIXIR}-otp-${ERLANG_MAJOR}.zip" && unzip -d /ELIXIR elixir.zip
WORKDIR /ELIXIR
RUN make -o compile DESTDIR=/ELIXIR_LOCAL install

FROM avvo/erlang:${ERLANG}-fedora-${OS_VERSION} AS final

COPY --from=build /ELIXIR_LOCAL/usr/local /usr/local
16 changes: 0 additions & 16 deletions elixir-release-ubuntu/18.04/Dockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions elixir-release-ubuntu/xenial/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions elixir-release/3.6/Dockerfile

This file was deleted.

48 changes: 0 additions & 48 deletions elixir/1.6.0/Dockerfile

This file was deleted.

48 changes: 0 additions & 48 deletions elixir/1.6.1/Dockerfile

This file was deleted.

Loading