From 323ea0dad90251ecc09e13482ef33924eb5a5a2a Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 17 Apr 2019 17:13:20 +0200 Subject: [PATCH 1/6] Use alpine in elixir docker file --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e071ba52..18a2c18a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM elixir:1.7 +FROM bitwalker/alpine-elixir:latest -RUN apt-get update && apt-get install -y build-essential inotify-tools postgresql-client +RUN apk add inotify-tools postgresql-client yarn RUN mix local.hex --force && mix local.rebar --force @@ -8,4 +8,4 @@ COPY docker/entrypoint.sh /bin/entrypoint WORKDIR /app -EXPOSE 4000 4001 4002 \ No newline at end of file +EXPOSE 4000 4001 4002 From 54576a4d9b642d99adfc129facf04c751ff41a55 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 17 Apr 2019 17:14:44 +0200 Subject: [PATCH 2/6] Add volume on postgres docker --- docker-compose.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a80eef7f..b454a709 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ version: '3' services: - postgres: container_name: mobilizon_db restart: unless-stopped @@ -9,6 +8,9 @@ services: environment: POSTGRES_PASSWORD: postgres POSTGRES_DB: mobilizon_dev + volumes: + - pgdata:/var/lib/postgresql/data + front: container_name: mobilizon_front @@ -43,3 +45,6 @@ services: MOBILIZON_DATABASE_DBNAME: mobilizon_dev MOBILIZON_DATABASE_HOST: postgres entrypoint: entrypoint +volumes: + pgdata: + .: From 990bfac44c830751fb3e615e91fb5100325431b6 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 17 Apr 2019 17:15:36 +0200 Subject: [PATCH 3/6] Add phx.migrate_serve command that runs ecto commands and launch server --- mix.exs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 6ba7bbe9..bb8e8a82 100644 --- a/mix.exs +++ b/mix.exs @@ -7,7 +7,7 @@ defmodule Mobilizon.Mixfile do [ app: :mobilizon, version: @version, - elixir: "~> 1.4", + elixir: "~> 1.8", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix, :gettext] ++ Mix.compilers(), start_permanent: Mix.env() == :prod, @@ -116,7 +116,8 @@ defmodule Mobilizon.Mixfile do [ "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], "ecto.reset": ["ecto.drop", "ecto.setup"], - test: ["ecto.create --quiet", "ecto.migrate", "test"] + test: ["ecto.create --quiet", "ecto.migrate", "test"], + "phx.migrate_serve": ["ecto.create --quiet", "ecto.migrate", "phx.server"] ] end From 040266a65602411222f98ea27bdd3c7242fa0a70 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 17 Apr 2019 17:16:21 +0200 Subject: [PATCH 4/6] Don't use entrypoints in docker --- docker-compose.yml | 11 +++++------ docker/entrypoint.sh | 22 ---------------------- js/Dockerfile | 5 +++-- js/docker/entrypoint.sh | 5 ----- 4 files changed, 8 insertions(+), 35 deletions(-) delete mode 100755 docker/entrypoint.sh delete mode 100755 js/docker/entrypoint.sh diff --git a/docker-compose.yml b/docker-compose.yml index b454a709..82fed99d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,10 +17,10 @@ services: restart: unless-stopped build: ./js volumes: - - './js:/app/js' + - '.:/app' ports: - "8888:8080" - entrypoint: entrypoint + command: yarn run dev api: container_name: mobilizon_api @@ -32,10 +32,9 @@ services: - "4000:4001" depends_on: - postgres + - front environment: - # Environment: Prod when ready - MIX_ENV: dev - # Instance + MIX_ENV: "dev" MOBILIZON_INSTANCE_NAME: My Mobilizon Instance MOBILIZON_INSTANCE_HOST: mobilizon.me MOBILIZON_INSTANCE_EMAIL: noreply@mobilizon.me @@ -44,7 +43,7 @@ services: MOBILIZON_DATABASE_USERNAME: postgres MOBILIZON_DATABASE_DBNAME: mobilizon_dev MOBILIZON_DATABASE_HOST: postgres - entrypoint: entrypoint + command: "mix phx.migrate_serve" volumes: pgdata: .: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100755 index 4c395578..00000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -mix deps.get - -# Wait for Postgres to become available. -until PGPASSWORD=$MOBILIZON_DATABASE_PASSWORD psql -h $MOBILIZON_DATABASE_HOST -U $MOBILIZON_DATABASE_USERNAME -c '\q' 2>/dev/null; do - >&2 echo "Postgres is unavailable - sleeping" - sleep 1 -done - -echo "\nPostgres is available: continuing with database setup..." - -# Potentially Set up the database -mix ecto.create -mix ecto.migrate - -echo "\nTesting the installation..." -# "Proove" that install was successful by running the tests -mix test - -echo "\n Launching Phoenix web server..." -iex -S mix phx.server \ No newline at end of file diff --git a/js/Dockerfile b/js/Dockerfile index 55c74ede..d9db3df2 100644 --- a/js/Dockerfile +++ b/js/Dockerfile @@ -2,8 +2,9 @@ FROM node:10 LABEL maintainer="tcit" -COPY docker/entrypoint.sh /bin/entrypoint +RUN yarn install +RUN yarn upgrade node-sass WORKDIR /app/js -EXPOSE 8080 \ No newline at end of file +EXPOSE 8080 diff --git a/js/docker/entrypoint.sh b/js/docker/entrypoint.sh deleted file mode 100755 index 24be99c1..00000000 --- a/js/docker/entrypoint.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -yan install -yarn rebuild node-sass -yarn run dev From 43b23c46ed623ea08d5b2138eac507b415ed3e6e Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 17 Apr 2019 17:17:27 +0200 Subject: [PATCH 5/6] Add make test command --- Makefile | 7 +++++++ docker-compose.test.yml | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 docker-compose.test.yml diff --git a/Makefile b/Makefile index 20eff2aa..7e329f25 100644 --- a/Makefile +++ b/Makefile @@ -10,5 +10,12 @@ stop: @bash docker/message.sh "stopping MobiliZon" docker-compose down @bash docker/message.sh "stopped" +test: stop + @bash docker/message.sh "Building front" + docker-compose -f docker-compose.yml -f docker-compose.test.yml run front yarn run build + @bash docker/message.sh "Front built" + @bash docker/message.sh "Running tests" + docker-compose -f docker-compose.yml -f docker-compose.test.yml run api mix test + @bash docker/message.sh "Tests runned" target: init diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 00000000..89f7a114 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,18 @@ +version: '3' + +services: + postgres: + restart: "no" + environment: + POSTGRES_DB: mobilizon_test + front: + restart: "no" + api: + restart: "no" + environment: + MIX_ENV: "test" + MOBILIZON_DATABASE_DBNAME: mobilizon_test + command: "mix test" +volumes: + pgdata: + .: From 9904030a81f86eaca1ef493637af5d52426dda8e Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 17 Apr 2019 17:17:35 +0200 Subject: [PATCH 6/6] Add .dockerignore --- .dockerignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..5d13bb1c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +_build +CONTRIBUTING.md +deps +docker-compose.yml +Dockerfile +.elixir_ls +.formatter.exs +.git +.gitignore +.gitlab +.gitlab-ci.yml +.graphqlconfig.yaml +LICENSE +Makefile +README.md +SECURITY.md +ssh_match_hostname +support +.js/package-lock.json