Git Product home page Git Product logo

Comments (9)

arthurkushman avatar arthurkushman commented on May 27, 2024

Screen Shot 2019-09-13 at 12 24 22

from example-services.

arthurkushman avatar arthurkushman commented on May 27, 2024

Basically I just need a PostgreSQL up and running on 127.0.0.1 postgres/postgres on port 5432 to connect from Go code.

from example-services.

sarahabd avatar sarahabd commented on May 27, 2024

@arthurkushman do you have set working-directory: ./postgres on your action?

from example-services.

arthurkushman avatar arthurkushman commented on May 27, 2024

I'm totally unfamiliar with GitHub Actions, so I don't know where to apply working-directory: ./postgres does this should be set in the same file - postgres-service.yml? Do you have an example?

from example-services.

arthurkushman avatar arthurkushman commented on May 27, 2024

Yes it is set like this:

jobs:
  container-job:
    runs-on: ubuntu-latest

    # runs all of the steps inside the specified continer rather than on the VM host.
    # Because of this the network configuration changes from host based network to a container network.
    container:
      image:  node:10.16-jessie

    services:
      postgres:
        image: postgres:10.8
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        ports:
          - 5432:5432
        # needed because the postgres container does not provide a healthcheck
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - uses: actions/checkout@v1
      - run: npm ci
        working-directory: ./postgres
      - run: node client.js
        working-directory: ./postgres
        env:
          # use postgres for the host here because we have specified a container for the job.
          # If we were running the job on the VM this would be localhost
          POSTGRES_HOST: postgres
          POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}

from example-services.

sarahabd avatar sarahabd commented on May 27, 2024

No problem @arthurkushman, the working-directory is necessary when you want to run your job on a specific folder of your project. For the postgres example, on the repo they use the folder postgres of the repo to run the job that's why, but if it's not needed for you, just remove the line.

jobs:
 vm-job:
    runs-on: ubuntu-latest

    # here is your service 
    services:
      postgres:
        image: postgres:10.8
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        ports:
          - 5432:5432
        # needed because the postgres container does not provide a healthcheck
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    # here is your action linked to your code
    # here it init go and run hello go
      steps:
      - uses: actions/checkout@master
      - uses: actions/setup-go@v1
         with:
           go-version: '1.9.3' # The Go version to download (if necessary) and use.
      - run: go run hello.go
        env:
         # you can use the both key for your connection or set directly localhost for host and 5432 for the port on your code
          POSTGRES_HOST: localhost
          POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # it's dynamic here but it will be 5432

Hope it will help !

from example-services.

arthurkushman avatar arthurkushman commented on May 27, 2024

After removing working-directory from anywhere got the error:
Screen Shot 2019-09-13 at 13 42 07

Yaml config:

name: Postgres Service Example

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  container-job:
    runs-on: ubuntu-latest

    # runs all of the steps inside the specified continer rather than on the VM host.
    # Because of this the network configuration changes from host based network to a container network.
    container:
      image:  node:10.16-jessie

    services:
      postgres:
        image: postgres:10.8
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        ports:
          - 5432:5432
        # needed because the postgres container does not provide a healthcheck
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - uses: actions/checkout@v1
      - run: npm ci
      - run: node client.js
        env:
          # use postgres for the host here because we have specified a container for the job.
          # If we were running the job on the VM this would be localhost
          POSTGRES_HOST: postgres
          POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}

  # Runs all steps on the VM
  # The service containers will use host port binding instead of container networking so you access them via localhost rather than the service name
  vm-job:
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:10.8
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        ports:
          # will assign a random free host port
          - 5432/tcp
        # needed because the postgres container does not provide a healthcheck
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - uses: actions/checkout@v1
      - run: npm ci
      - run: node client.js
        env:
          # use localhost for the host here because we have specified a container for the job.
          # If we were running the job on the VM this would be postgres
          POSTGRES_HOST: localhost
          POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port

What I need is just run PostgreSQL on 127.0.0.1:5432 to be able to connect from Go program, if there is no need for npm I can remove those blocks for ex.

from example-services.

sarahabd avatar sarahabd commented on May 27, 2024

What I need is just run PostgreSQL on 127.0.0.1:5432 to be able to connect from Go program

@arthurkushman I give you the full example for you in my previous post, you can copy paste all.

It's was an example for use npm ci but i don't think it's needed for you, so you can remove yes.

from example-services.

arthurkushman avatar arthurkushman commented on May 27, 2024

Oh, good - finally PostgreSQL up and running.
What I did is just remove npm checker and then got issues related to non created shcemes:

--- FAIL: TestSelectAndLimit (0.01s)
15
    builder_test.go:28: 
16
        	Error Trace:	builder_test.go:28
17
        	Error:      	Received unexpected error:
18
        	            	pq: relation "test" does not exist
19
        	Test:       	TestSelectAndLimit
20
--- FAIL: TestInsert (0.01s)
21
    builder_test.go:45: 
22
        	Error Trace:	builder_test.go:45
23
        	Error:      	Received unexpected error:
24
        	            	pq: relation "test" does not exist
25
        	Test:       	TestInsert

And that's great - nothing to worry about, thx a lot for your help, good luck with your projects.

from example-services.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.