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’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it.
I’m very interested in Elixir,...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
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
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Background
Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New







