From 79a4817a6181b2ea3ca4191aa9b30677c3bc89b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20Barr=C3=A8re?= Date: Fri, 9 Apr 2021 09:55:35 +0200 Subject: [PATCH 1/6] Switch base image (see #23) The hexpm images allow to specify the OTP version independently of the Elixir version, hence providing a better control on update pace. --- transport-site/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transport-site/Dockerfile b/transport-site/Dockerfile index beb4a61..cb6cb39 100644 --- a/transport-site/Dockerfile +++ b/transport-site/Dockerfile @@ -1,5 +1,5 @@ -# see https://hub.docker.com/_/elixir -FROM elixir:1.11.3-alpine +# see https://hub.docker.com/r/hexpm/elixir +FROM hexpm/elixir:1.10.4-erlang-23.2.7.2-alpine-3.13.3 RUN apk add nodejs-npm curl yarn bash build-base wget libtool git From e3e6f651cbdffa98750d4eb5ce5a6d7973cdbbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20Barr=C3=A8re?= Date: Fri, 9 Apr 2021 09:57:16 +0200 Subject: [PATCH 2/6] Install node/yarn in a separate step This is a first move toward freezing node version later, with a multistage build. --- transport-site/Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/transport-site/Dockerfile b/transport-site/Dockerfile index cb6cb39..00280da 100644 --- a/transport-site/Dockerfile +++ b/transport-site/Dockerfile @@ -1,7 +1,11 @@ # see https://hub.docker.com/r/hexpm/elixir FROM hexpm/elixir:1.10.4-erlang-23.2.7.2-alpine-3.13.3 -RUN apk add nodejs-npm curl yarn bash build-base wget libtool git +RUN apk add curl bash build-base wget libtool git + +# To be removed in favor of multistage build with deterministic version numbers, +# e.g. https://dev.to/quatermain/comment/njf7 +RUN apk add nodejs-npm yarn # Install app dependencies RUN mix local.hex --force From da9de3b17e289b5a8f58ef22ac6c124fe0820078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20Barr=C3=A8re?= Date: Fri, 9 Apr 2021 09:58:25 +0200 Subject: [PATCH 3/6] Install libiconv from package rather than from source This is less cumbersome and also faster. --- transport-site/Dockerfile | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/transport-site/Dockerfile b/transport-site/Dockerfile index 00280da..f9ec378 100644 --- a/transport-site/Dockerfile +++ b/transport-site/Dockerfile @@ -1,7 +1,7 @@ # see https://hub.docker.com/r/hexpm/elixir FROM hexpm/elixir:1.10.4-erlang-23.2.7.2-alpine-3.13.3 -RUN apk add curl bash build-base wget libtool git +RUN apk add curl bash build-base wget libtool git gnu-libiconv # To be removed in favor of multistage build with deterministic version numbers, # e.g. https://dev.to/quatermain/comment/njf7 @@ -10,12 +10,3 @@ RUN apk add nodejs-npm yarn # Install app dependencies RUN mix local.hex --force RUN mix local.rebar --force - -# NOTE: development at https://git.savannah.gnu.org/gitweb/?p=libiconv.git -# and publication at https://ftp.gnu.org/pub/gnu/libiconv -RUN wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz -RUN tar -xf libiconv-1.16.tar.gz -RUN cd libiconv-1.16 && ./configure --prefix= && make && make install -RUN libtool --finish /lib -RUN rm libiconv-1.16.tar.gz -RUN rm -r libiconv-1.16 From 94aed5415670677802fbc1d01db77faba4e68c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20Barr=C3=A8re?= Date: Fri, 9 Apr 2021 09:58:48 +0200 Subject: [PATCH 4/6] Add todo --- transport-site/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/transport-site/Dockerfile b/transport-site/Dockerfile index f9ec378..9505d2d 100644 --- a/transport-site/Dockerfile +++ b/transport-site/Dockerfile @@ -1,6 +1,8 @@ # see https://hub.docker.com/r/hexpm/elixir FROM hexpm/elixir:1.10.4-erlang-23.2.7.2-alpine-3.13.3 +# TODO: iconv could probably be removed later +# https://github.com/etalab/transport-site/issues/1591 RUN apk add curl bash build-base wget libtool git gnu-libiconv # To be removed in favor of multistage build with deterministic version numbers, From 34de8f16bb721385b06ad1a23f0d5233d3ab95bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20Barr=C3=A8re?= Date: Fri, 9 Apr 2021 16:50:42 +0200 Subject: [PATCH 5/6] Add a Ruby task to easily generate our image name --- Rakefile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Rakefile diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..6265732 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +task :get_image_version do + version = IO.read("transport-site/Dockerfile")[/FROM (hexpm\/elixir.*)/, 1] + version = version.gsub('hexpm/elixir:','elixir-') + fail "Unexpected FROM format, script must be verified" unless version =~ /\Aelixir\-[^\-]+\-erlang\-[^\-]+\-alpine\-[^\-]+\z/ + puts version +end From 63688e32fc7ae3fe884ccd965253340b6fb6a9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibaut=20Barr=C3=A8re?= Date: Fri, 9 Apr 2021 16:50:51 +0200 Subject: [PATCH 6/6] Update README.md --- README.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6ecb0c8..563b226 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,18 @@ # transport-ops Scripts and config files for provision and deploy transport and required services +## Image naming convention + +In the past images were named "betagouv/transport:x.y.z". + +Now we name them after the Elixir, Erlang and Alpine versions actually used (like the base `hexpm` image it uses). + +* Base name: `hexpm/elixir:1.10.4-erlang-23.2.7.2-alpine-3.13.3` +* Replace `hexpm/elixir:` by `betagouv/transport:elixir-` +* Target name: `betagouv/transport:elixir-1.10.4-erlang-23.2.7.2-alpine-3.13.3` + +You can use `rake get_image_name` to build the expected target name out of the `Dockerfile` in automated fashion. + ## Production configuration and deployment The production requires the following services: @@ -35,21 +47,23 @@ As a work-around for [#17](https://github.com/etalab/transport-ops/issues/17): * Build the image locally with the correct tag, and **without cache** to make sure no left-over impact the build: ``` -docker build . --no-cache -t betagouv/transport:X.Y.Z +IMAGE_VERSION=$(rake get_image_version) +IMAGE_NAME=betagouv/transport:$IMAGE_VERSION +docker build transport-site --no-cache -t $IMAGE_VERSION ``` * Carefully verify the versions (this will be translated into a testing script later): ``` -docker run -it --rm betagouv/transport:X.Y.Z /bin/bash -c 'node --version' -docker run -it --rm betagouv/transport:X.Y.Z /bin/bash -c 'elixir --version' -docker run -it --rm betagouv/transport:X.Y.Z /bin/bash -c "erl -noshell -eval 'erlang:display(erlang:system_info(system_version))' -eval 'init:stop()'" +docker run -it --rm $IMAGE_NAME /bin/bash -c 'node --version' +docker run -it --rm $IMAGE_NAME /bin/bash -c 'elixir --version' +docker run -it --rm $IMAGE_NAME /bin/bash -c "erl -noshell -eval 'erlang:display(erlang:system_info(system_version))' -eval 'init:stop()'" ``` * Read the [docker push documentation](https://docs.docker.com/engine/reference/commandline/push/) * List the local images with `docker image ls` -* Filter with `docker image ls | grep "betagouv/transport" | grep "X.Y.Z"` -* Push with `docker image push betagouv/transport:X.Y.Z` +* Filter with `docker image ls | grep "betagouv/transport" | grep $IMAGE_VERSION` +* Push with `docker image push $IMAGE_NAME` * TODO: handle `latest` (but it is currently unused) ## Useful tricks when upgrading