diff --git a/.ebextensions/environment.config b/.ebextensions/environment.config new file mode 100644 index 00000000..c3671f16 --- /dev/null +++ b/.ebextensions/environment.config @@ -0,0 +1,15 @@ +option_settings: + - option_name: BASE_URL + value: tides.coloredcow.com + - option_name: DATABASE_USER + value: postgres + - option_name: DATABASE_PASSWORD + value: postgres + - option_name: POSTGRES_DB + value: tidesdb + - option_name: SECRET_KEY_BASE + value: qu7CXOpykb6wMdSJ6kYepIFxWevqByviwZZgOz03luuE4exd+vGSMG3WoThg1Vl7 + - option_name: DATABASE_HOST + value: tidesdb.czpgx5pis6ka.ap-south-1.rds.amazonaws.com + - option_name: DATABASE_DB + value: tidesdb \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3f4ddcfa..888292c0 100644 --- a/.gitignore +++ b/.gitignore @@ -27,5 +27,11 @@ project_tides-*.tar # this depending on your deployment strategy. /priv/static/ .env +# Elastic Beanstalk Files +.elasticbeanstalk/* +!.elasticbeanstalk/*.cfg.yml +!.elasticbeanstalk/*.global.yml +# .ebextensions/environment.config + config/dev.exs -.DS_Store \ No newline at end of file +.DS_Store diff --git a/Dockerfile b/Dockerfile index 84b14dc3..337ab078 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM elixir:1.9-alpine as build +FROM elixir:1.10-alpine as build MAINTAINER opensource@coloredcow.com RUN mkdir /app @@ -24,7 +24,7 @@ RUN mix compile RUN mix release # prepare release image -FROM alpine:3.9 AS app +FROM alpine:3.11 AS app # install runtime dependencies RUN apk add --update bash openssl postgresql-client diff --git a/Dockerrun.aws.json b/Dockerrun.aws.json new file mode 100644 index 00000000..02d1cf79 --- /dev/null +++ b/Dockerrun.aws.json @@ -0,0 +1,13 @@ +{ + "AWSEBDockerrunVersion": 1, + "Image": { + "Name": "023004991146.dkr.ecr.ap-south-1.amazonaws.com/tides:latest", + "Update": "true" + }, + "Ports": [ + { + "HostPort": "80", + "ContainerPort": "4000" + } + ] +} diff --git a/build_scripts/entrypoint.sh b/build_scripts/entrypoint.sh index bf940e4c..a096fd54 100755 --- a/build_scripts/entrypoint.sh +++ b/build_scripts/entrypoint.sh @@ -5,15 +5,15 @@ # starts the application. # assign a default for the database_user / role -DB_ROLE=${POSTGRES_ROLE:-postgres} -DB_HOST=${DATABASE_HOST:-db} +# DB_ROLE=${DATABASE_ROLE:-postgres} +# DB_HOST=${DATABASE_HOST:-localhost} -# wait until Postgres is ready -while ! pg_isready -q -h $DB_HOST -p 5432 -U $DB_ROLE -do - echo "$(date) - waiting for database to start" - sleep 2 -done +# # wait until Postgres is ready +# while ! pg_isready -q -h $DB_HOST -p 5432 -U $DB_ROLE +# do +# echo "$(date) - waiting for database to start" +# sleep 2 +# done bin="/app/bin/project_tides" eval "$bin eval \"ProjectTides.Release.migrate\"" diff --git a/buildspec.yml b/buildspec.yml new file mode 100644 index 00000000..a76e3519 --- /dev/null +++ b/buildspec.yml @@ -0,0 +1,31 @@ +# buildspec.yml +version: 0.2 + +phases: + + pre_build: + commands: + - echo Logging in to Amazon ECR. + - aws --version + - $(aws ecr get-login --no-include-email --region ap-south-1) + - REPOSITORY_URI=023004991146.dkr.ecr.ap-south-1.amazonaws.com/tides + - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) + - IMAGE_TAG=${COMMIT_HASH:=latest} + build: + commands: + - echo Build started on `date` + - docker build -t $REPOSITORY_URI:latest . + - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG + post_build: + commands: + - echo Build completed on `date` + - echo Pushing the Docker images... + - docker push $REPOSITORY_URI:latest + - docker push $REPOSITORY_URI:$IMAGE_TAG +# cache: +# paths: +# - '/**/*' - update as needed +artifacts: + files: + - '**/*' + name: project-tides-$(date +%Y-%m-%d) \ No newline at end of file diff --git a/config/releases.exs b/config/releases.exs index 20baaa3e..e265d0c6 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -10,6 +10,7 @@ db_database = System.get_env("DATABASE_DB") || "postgres" db_username = System.get_env("DATABASE_USER") || "postgres" db_password = System.get_env("DATABASE_PASSWORD") || "postgres" db_url = "ecto://#{db_username}:#{db_password}@#{db_host}/#{db_database}" + config :project_tides, ProjectTides.Repo, url: db_url, pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), @@ -21,6 +22,4 @@ secret_key_base = System.get_env("SECRET_KEY_BASE") || """ config :project_tides, ProjectTidesWeb.Endpoint, server: true, - http: [:inet6, port: 4000], - secret_key_base: secret_key_base, - url: [host: System.get_env("BASE_URL"), port: 80] \ No newline at end of file + http: [:inet6, port: 4000] \ No newline at end of file diff --git a/lib/project_tides_web/router.ex b/lib/project_tides_web/router.ex index ca373ae2..60e6766b 100644 --- a/lib/project_tides_web/router.ex +++ b/lib/project_tides_web/router.ex @@ -16,12 +16,12 @@ defmodule ProjectTidesWeb.Router do # If your application does not have an admins-only section yet, # you can use Plug.BasicAuth to set up some basic authentication # as long as you are also using SSL (which you should anyway). - if Mix.env() in [:dev, :test] do + # if Mix.env() in [:dev, :test] do import Phoenix.LiveDashboard.Router scope "/" do pipe_through [:fetch_session, :protect_from_forgery] live_dashboard "/dashboard", metrics: ProjectTidesWeb.Telemetry - end + # end end end diff --git a/test/project_tides_web/views/error_view_test.exs b/test/project_tides_web/views/error_view_test.exs index 5585dc14..4bdcde93 100644 --- a/test/project_tides_web/views/error_view_test.exs +++ b/test/project_tides_web/views/error_view_test.exs @@ -12,4 +12,5 @@ defmodule ProjectTidesWeb.ErrorViewTest do assert render(ProjectTidesWeb.ErrorView, "500.json", []) == %{errors: %{detail: "Internal Server Error"}} end + end