sql >> Databasteknik >  >> RDS >> PostgreSQL

GitHub Actions:Hur man ansluter till Postgres i GithHub Actions

Jag har en lite annorlunda inställning men det här var den mest relevanta frågan när jag stötte på samma fel så ville skriva här ifall det kan hjälpa. De två sakerna som var avgörande för mig var:1) Ställ in DB_HOST=localhost 2) Ställ in --network="host" argument när du startar docker-behållaren med din rails-app

name: Master Build

on: [push]

env:
  registry: my_registry_name
  # Not sure these are actually being passed down to rails, set them as the default in database.yml
  DB_HOST: localhost
  DB_USERNAME: postgres
  DB_PASSWORD: postgres

jobs:
  my_image_test:
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:latest
        env:
          POSTGRES_DB: postgres        
          POSTGRES_PASSWORD: postgres
          POSTGRES_USER: postgres
        ports:
          - 5432:5432
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - name: Check out repository
        uses: actions/[email protected]
      - name: Build my_image docker image
        uses: whoan/[email protected]
        with:
          username: "${{secrets.aws_ecr_access_key_id}}"
          password: "${{secrets.aws_ecr_secret_access_key}}"
          registry: "${{env.registry}}"
          image_name: my_image
          context: my_image
      - name: Lint rubocop
        working-directory: ./my_image
        run: docker run $registry/my_image bundle exec rubocop
      - name: Run rails tests
        working-directory: ./my_image
        run: docker run --network="host" $registry/my_image bash -c "RAILS_ENV=test rails db:create && RAILS_ENV=test rails db:migrate && rails test"


  1. Hur skickar man en sträng med ' ' (tidsstämpel) i förberedd sats?

  2. php,postgresql,mysql

  3. FEL 1049 (42000):Okänd databas

  4. Infoga ckeditor html-kod i databasen