Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define host mappings in GitHub Actions?

Now I am using GitHub Actions to build my project. On my local machine, I define the local host address mapping in /etc/hosts like this:

11.19.178.213 postgres.dolphin.com

and in my database config like this:

spring.datasource.druid.post.master.jdbc-url = jdbc:postgresql://postgres.dolphin.com:5432/dolphin

On my production server I could edit the mapping to locate a different IP address of my database. But now I am running unit tests in GitHub Actions. How do I edit the host mapping to make the database mapping to container of GitHub Actions? I defined the container in GitHub Actions like this:

jobs:
  build:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:13.2
        env:
          POSTGRES_PASSWORD: postgrespassword
          POSTGRES_DB: dolphin
          POSTGRES_USER: postgres
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

What should I do to handle the host mapping? I have already searched the docs, but I have found nothing about this problem?

like image 224
Dolphin Avatar asked Nov 19 '25 21:11

Dolphin


1 Answers

do it like this:

- name: Add hosts to /etc/hosts
  run: |
      sudo echo "127.0.0.1 postgres.dolphin.com" | sudo tee -a /etc/hosts
like image 167
Dolphin Avatar answered Nov 22 '25 15:11

Dolphin