diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..8631419eb --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,119 @@ +defaults: &defaults + working_directory: ~/code-corps-api + docker: + - image: circleci/elixir:1.6-node-browsers + - image: circleci/postgres:9.4 + environment: + POSTGRES_USER: ubuntu + - image: circleci/ruby:2.3 + +jobs: + build: + <<: *defaults + steps: + - checkout + - restore_cache: + keys: + - v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }} + - v1-mix-cache-{{ .Branch }} + - v1-mix-cache + - restore_cache: + keys: + - v1-build-cache-{{ .Branch }} + - v1-build-cache + - run: + name: Install PostgreSQL Client (for pg_dump, happening as part of ecto.migrate) + command: sudo apt install postgresql-client + - run: mix local.hex --force + - run: mix local.rebar + - run: mix deps.get + - run: + name: Run test suite and maybe report coverage + command: | + if [ ${CIRCLE_PR_USERNAME} ]; then + MIX_ENV=test mix test; + else + MIX_ENV=test mix coveralls.circle --include acceptance:true; + fi + - save_cache: + key: v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }} + paths: "deps" + - save_cache: + key: v1-mix-cache-{{ .Branch }} + paths: "deps" + - save_cache: + key: v1-mix-cache + paths: "deps" + - save_cache: + key: v1-build-cache-{{ .Branch }} + paths: "_build" + - save_cache: + key: v1-build-cache + paths: "_build" + deploy-staging: + <<: *defaults + steps: + - checkout + - run: + name: Run Heroku setup script + command: bash .circleci/setup-heroku.sh + - add_ssh_keys: + fingerprints: + - "48:a0:87:54:ca:75:32:12:c6:9e:a2:77:a4:7a:08:a4" + - run: + name: Push to Remote Development + command: | + git push --force git@heroku.com:code-corps-remote-development.git HEAD:refs/heads/master + heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps-remote-development + heroku restart --app code-corps-remote-development + - run: + name: Push to Staging + command: | + git push --force git@heroku.com:code-corps-staging.git HEAD:refs/heads/master + heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps-staging + heroku restart --app code-corps-staging + - run: + name: Update API Docs + command: | + gem install apiaryio + apiary publish --api-name="codecorpsapidevelop" --path ./blueprint/api.apib + ./bin/deploy_docs.sh + deploy-production: + <<: *defaults + steps: + - checkout + - run: + name: Run Heroku setup script + command: bash .circleci/setup-heroku.sh + - add_ssh_keys: + fingerprints: + - "48:a0:87:54:ca:75:32:12:c6:9e:a2:77:a4:7a:08:a4" + - run: + name: Deploy Master to Heroku Production + command: | + git push --force git@heroku.com:code-corps.git HEAD:refs/heads/master + heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps + heroku restart --app code-corps + - run: + name: Update API Docs + command: | + gem install apiaryio + apiary publish --api-name="codecorpsapi" --path ./blueprint/api.apib + +workflows: + version: 2 + build-deploy: + jobs: + - build + - deploy-staging: + requires: + - build + filters: + branches: + only: develop + - deploy-production: + requires: + - build + filters: + branches: + only: master diff --git a/.circleci/setup-heroku.sh b/.circleci/setup-heroku.sh new file mode 100644 index 000000000..4e012e07e --- /dev/null +++ b/.circleci/setup-heroku.sh @@ -0,0 +1,16 @@ +#!/bin/bash +wget https://cli-assets.heroku.com/branches/stable/heroku-linux-amd64.tar.gz +sudo mkdir -p /usr/local/lib /usr/local/bin +sudo tar -xvzf heroku-linux-amd64.tar.gz -C /usr/local/lib +sudo ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku + +cat > ~/.netrc << EOF +machine api.heroku.com + login $HEROKU_LOGIN + password $HEROKU_API_KEY +EOF + +cat >> ~/.ssh/config << EOF +VerifyHostKeyDNS yes +StrictHostKeyChecking no +EOF diff --git a/bin/circle_pre_build.sh b/bin/circle_pre_build.sh deleted file mode 100755 index f69cb715c..000000000 --- a/bin/circle_pre_build.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash - -# Ensure exit codes other than 0 fail the build -set -e - -# Check for asdf -if ! asdf | grep version; then - # Install asdf into ~/.asdf if not previously installed - git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.1.0 -fi - -# Add plugins (Erlang and Elixir) for asdf - -# Check to see if asdf's Erlang plugin is installed -if ! asdf plugin-list | grep erlang; then - # Install the Erlang plugin - asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git -else - # Update the Erlang plugin - asdf plugin-update erlang -fi - -# Check to see if asdf's Elixir plugin is installed -if ! asdf plugin-list | grep elixir; then - # Install the Elixir plugin - asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git -else - # Update the Elixir plugin - asdf plugin-update elixir -fi - -# Extract versions from elixir_buildpack.config into variables -. elixir_buildpack.config - -# Write .tool-versions for asdf -echo "erlang $erlang_version" >> .tool-versions -echo "elixir $elixir_version" >> .tool-versions - -# Install erlang/elixir -echo "Installing Erlang..." -asdf install erlang $erlang_version - -echo "Installing Elixir..." -asdf install elixir $elixir_version - -# Get dependencies -yes | mix deps.get -yes | mix local.rebar - -# Exit successfully -exit 0 diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 024c8a436..000000000 --- a/circle.yml +++ /dev/null @@ -1,42 +0,0 @@ -machine: - environment: - PATH: "$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH" - -dependencies: - cache_directories: - - ~/.asdf - - deps - - _build - pre: - - ./bin/circle_pre_build.sh - - mix deps.compile - - mix compile --warnings-as-errors -test: - override: - - | - if [ ${CIRCLE_PR_USERNAME} ]; then - MIX_ENV=test mix test; - else - MIX_ENV=test mix coveralls.circle --include acceptance:true; - fi - post: - - mix inch.report - -deployment: - staging: - branch: develop - commands: - - git push git@heroku.com:code-corps-remote-development.git $CIRCLE_SHA1:master - - heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps-remote-development - - git push git@heroku.com:code-corps-staging.git $CIRCLE_SHA1:master - - heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps-staging - - gem install apiaryio - - apiary publish --api-name="codecorpsapidevelop" --path ./blueprint/api.apib - - ./bin/deploy_docs.sh - production: - branch: master - commands: - - git push git@heroku.com:code-corps.git $CIRCLE_SHA1:master - - heroku run "POOL_SIZE=2 mix ecto.migrate" --app code-corps - - gem install apiaryio - - apiary publish --api-name="codecorpsapi" --path ./blueprint/api.apib diff --git a/elixir_buildpack.config b/elixir_buildpack.config index 4867efbe4..faa97eb59 100644 --- a/elixir_buildpack.config +++ b/elixir_buildpack.config @@ -1,2 +1,2 @@ -erlang_version=20.1 -elixir_version=1.5.2 +erlang_version=20.2 +elixir_version=1.6.1 diff --git a/mix.exs b/mix.exs index 58fc055c5..9e89b16f3 100644 --- a/mix.exs +++ b/mix.exs @@ -10,7 +10,7 @@ defmodule CodeCorps.Mixfile do def project do [app: :code_corps, version: "0.0.1", - elixir: "~> 1.5.2", + elixir: "~> 1.6", elixirc_paths: elixirc_paths(Mix.env), compilers: [:phoenix, :gettext] ++ Mix.compilers, dialyzer: [ignore_warnings: "dialyzer.ignore-warnings", plt_add_apps: [:kernel, :stdlib], plt_add_deps: :transitive], diff --git a/mix.lock b/mix.lock index 9047047d8..04ee498cb 100644 --- a/mix.lock +++ b/mix.lock @@ -1,4 +1,5 @@ -%{"approximate_histogram": {:hex, :approximate_histogram, "0.1.1", "198eb36681e763ed4baab6ca0682acec4ef642f60ba272f251d3059052f4f378", [:mix], []}, +%{ + "approximate_histogram": {:hex, :approximate_histogram, "0.1.1", "198eb36681e763ed4baab6ca0682acec4ef642f60ba272f251d3059052f4f378", [:mix], []}, "bamboo": {:hex, :bamboo, "0.8.0", "573889a3efcb906bb9d25a1c4caa4ca22f479235e1b8cc3260d8b88dabeb4b14", [:mix], [{:hackney, "~> 1.6", [hex: :hackney, optional: false]}, {:plug, "~> 1.0", [hex: :plug, optional: false]}, {:poison, ">= 1.5.0", [hex: :poison, optional: false]}]}, "bamboo_postmark": {:hex, :bamboo_postmark, "0.4.1", "2ec8fad4d221944f5169ea4346e6e1aef3578282c352c9f7184306d872aa1c26", [:mix], [{:bamboo, "~> 0.5", [hex: :bamboo, optional: false]}, {:hackney, "~> 1.6", [hex: :hackney, optional: false]}, {:plug, "~> 1.0", [hex: :plug, optional: false]}, {:poison, ">= 1.5.0", [hex: :poison, optional: false]}]}, "base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [], []}, @@ -14,7 +15,7 @@ "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, optional: false]}]}, "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [], []}, "credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]}, - "db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]}, + "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], []}, "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], []}, "earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], []}, @@ -53,7 +54,7 @@ "plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [], []}, - "postgrex": {:hex, :postgrex, "0.13.3", "c277cfb2a9c5034d445a722494c13359e361d344ef6f25d604c2353185682bfc", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}, + "postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"}, "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], []}, "scout_apm": {:hex, :scout_apm, "0.3.3", "8679378b624b502d7f6e8a1b023b57f4c7ab717380291e2b40ccdb2923457194", [:mix], [{:approximate_histogram, "~>0.1.1", [hex: :approximate_histogram, optional: false]}, {:hackney, "~> 1.0", [hex: :hackney, optional: false]}, {:plug, "~>1.0", [hex: :plug, optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, optional: false]}]}, "scrivener": {:hex, :scrivener, "2.4.0", "c9431804b13ac6a5c4b01eb32188c1ff926898a2d684244d021706841f022e66", [:mix], []}, @@ -69,4 +70,5 @@ "tzdata": {:hex, :tzdata, "0.5.14", "56f05ea3dd87db946966ab3c7168c0b35025c7ee0e9b4fc130a04631f5611eb1", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], []}, "uri_query": {:hex, :uri_query, "0.1.2", "ae35b83b472f3568c2c159eee3f3ccf585375d8a94fb5382db1ea3589e75c3b4", [:mix], []}, - "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], []}} + "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], []}, +}