Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to access Postgres service from docker image #48

Open
orkenstein opened this issue Jun 22, 2023 · 1 comment
Open

Trying to access Postgres service from docker image #48

orkenstein opened this issue Jun 22, 2023 · 1 comment

Comments

@orkenstein
Copy link

I'm trying to connect to Postgres db from within my Docker image to run tests:

  test_backend:
    runs-on:
      group: ubuntu-large
    needs: build_backend

    # Service containers to run with `container-job`
    services:
      # Label used to access the service container
      postgres:
        # Docker Hub image
        image: postgres
        # Provide the password for postgres
        env:
          POSTGRES_PASSWORD: postgres
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Maps tcp port 5432 on service container to the host
          - 5432:5432

    steps:
    - name: Run tests in container
      uses: addnab/docker-run-action@v3
      with:
        image: backend-py:${{github.sha}}
        run: ./manage.py test --noinput
        options: --env-file .github/workflows/env.test

There is a script, that tries to connect to Postgres running as a service. However I can't figure out, how to set the correct network/host value. I've tried to set in env.test:

DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${INPUT_DOCKER_NETWORK}:5432/${POSTGRES_DB}

Which gives me error:

django.db.utils.OperationalError: could not translate host name "${input_docker_network}" to address: Name or service not known

How should I specify the host name to successfully connect to Postgres GitHub service?

@lorenzoaiello
Copy link

If you haven't figured it out, or for others who come across this, the hostname here would just be postgres, no other fancy docker networking necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants