rrmartins
Github Actions with Postgres
Hey guys,
I need a lot of help getting github actions up and running with my private postgres project. I get the following error on github actions:
Error: 22:36:19.848 [error] Postgrex.Protocol (#PID<0.457.0>) failed to connect: **
(DBConnection.ConnectionError) tcp connect (invoices_control_db:5432):
non-existing domain - :nxdomain
Here is my workflow file:
name: Elixir CI
on:
push:
branches: ['master']
pull_request:
branches: ['master']
env:
MIX_ENV: test
# NOTE: make sure these versions match in Containerfile and .tool-versions
ELIXIR_VERSION_SPEC: "1.15.1"
OTP_VERSION_SPEC: "26.0.2"
jobs:
compile:
name: Compile
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1.16
with:
elixir-version: ${{ env.ELIXIR_VERSION_SPEC }}
otp-version: ${{ env.OTP_VERSION_SPEC }}
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Compile
run: mix compile --warnings-as-errors
test:
name: Test
runs-on: ubuntu-22.04
services:
postgres:
image: postgres:latest
ports: ['5432:5432']
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
MIX_ENV: test
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1.16
with:
elixir-version: ${{ env.ELIXIR_VERSION_SPEC }}
otp-version: ${{ env.OTP_VERSION_SPEC }}
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Setup database
env:
DATABASE_URL: postgresql://postgres:postgres@invoices_control_db:${{job.services.postgres.ports[5432]}}/invoices_control_test
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_HOSTNAME: invoices_control_db
MIX_ENV: test
run:
mix ecto.drop
mix ecto.create
mix ecto.migrate
- name: Run tests
env:
DATABASE_URL: postgresql://postgres:postgres@invoices_control_db:${{job.services.postgres.ports[5432]}}/invoices_control_test
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_HOSTNAME: invoices_control_db
MIX_ENV: test
run:
mix ecto.drop
mix ecto.create
mix ecto.migrate
mix test
check-formatted:
name: Check Formatted
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1.16
with:
elixir-version: ${{ env.ELIXIR_VERSION_SPEC }}
otp-version: ${{ env.OTP_VERSION_SPEC }}
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Check formatted
run: mix format --check-formatted
credo:
name: Credo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1.16
with:
elixir-version: ${{ env.ELIXIR_VERSION_SPEC }}
otp-version: ${{ env.OTP_VERSION_SPEC }}
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Run credo
run: mix credo --strict
what do you think about this?
Marked As Solved
rrmartins
the final solution:
name: Elixir CI
on:
push:
branches: ['master']
pull_request:
branches: ['master']
env:
MIX_ENV: test
# NOTE: make sure these versions match in Containerfile and .tool-versions
ELIXIR_VERSION_SPEC: "1.15.1"
OTP_VERSION_SPEC: "26.0.2"
jobs:
compile:
name: Compile
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1.16
with:
elixir-version: ${{ env.ELIXIR_VERSION_SPEC }}
otp-version: ${{ env.OTP_VERSION_SPEC }}
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Compile
run: mix compile --warnings-as-errors
test:
name: Test
runs-on: ubuntu-22.04
services:
invoices_control_db_test:
image: postgres:latest
ports: ['5432:5432']
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: 'trust'
POSTGRES_DB: invoices_control_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
MIX_ENV: test
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1.16
with:
elixir-version: ${{ env.ELIXIR_VERSION_SPEC }}
otp-version: ${{ env.OTP_VERSION_SPEC }}
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Setup database
env:
MIX_ENV: test
PGHOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
run:
mix ecto.drop
mix ecto.create
mix ecto.migrate
- name: Run tests
env:
MIX_ENV: test
PGHOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
run:
mix test
check-formatted:
name: Check Formatted
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1.16
with:
elixir-version: ${{ env.ELIXIR_VERSION_SPEC }}
otp-version: ${{ env.OTP_VERSION_SPEC }}
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Check formatted
run: mix format --check-formatted
credo:
name: Credo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1.16
with:
elixir-version: ${{ env.ELIXIR_VERSION_SPEC }}
otp-version: ${{ env.OTP_VERSION_SPEC }}
- name: Install dependencies
run: mix deps.get
- name: Compile dependencies
run: mix deps.compile
- name: Run credo
run: mix credo --strict
7
Also Liked
LostKobrakai
The postgres container setup is using postgres as it’s name (and therefore hostname), not invoices_control_db.
1
Popular in Questions
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Other popular topics
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
What learn first? Rust or Elixir
Hi Elixir community!
I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









