rrmartins

rrmartins

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?

Showing Posts 1 to 2

LostKobrakai

LostKobrakai

The postgres container setup is using postgres as it’s name (and therefore hostname), not invoices_control_db.

rrmartins

rrmartins OP

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
— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews