Cant connect to container in CI - docker-compose

I cant connect to my postgres container in ci what i am missing containers in ci is build my connection in postges should be like this "Server=localhost;Port=5432;User Id=root;Password=root;Database=employee_expenses_db;" i use this connection when i test in my local machine it works fine with my containers on my local pc but it not works in Ci and containers in ci is build but connection in those containers are not found
in CI it must connect to my containers that runs in and then my integration test should pass
ci.yml file
name: CI
on:
push:
branches: [master]
pull_request:
release:
types: [published]
env:
NUGET_PACKAGES: /opt/github/cache/${{ github.repository }}
DOTNET_VERSION: 6.0.x
jobs:
build:
name: Build
runs-on: [self-hosted, linux]
steps:
- uses: actions/checkout#v2
- uses: actions/setup-dotnet#v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Build
run: dotnet build
test:
name: Test
runs-on: [self-hosted, linux]
needs: build
steps:
- uses: actions/checkout#v2
- uses: actions/setup-dotnet#v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Run tests
run: |
docker-compose -f ./test/dockerCompose.yml build
docker-compose -f ./test/dockerCompose.yml up -d
dotnet test --configuration ${DOTNET_CONFIGURATION=Release} ./test/EmployeeExpensesApi.Tests
dockerCompose.yml
services:
rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq
hostname: "rabbitmq"
labels:
NAME: "rabbitmq"
ports:
- '4369:4369'
- '5551:5551'
- '5552:5552'
- '5672:5672'
- '25672:25672'
- '15672:15672'
networks:
- test-network
postgres:
image: postgres
container_name: postgres
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: employee_expenses_db
PGUSER: "root"
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- "5432:5432"
restart: unless-stopped
healthcheck:
test: [ "CMD-SHELL", "pg_isready -d employee_expenses_db" ]
interval: 5s
timeout: 5s
retries: 5
networks:
- test-network
liquibase:
container_name: liquibase
build: ./liquibase
depends_on:
postgres:
condition: service_healthy
networks:
- test-network
networks:
test-network:
driver: bridge

Related

material-ui-docs site won't run Error: Cannot find module 'babel-plugin-macros'

no issues section available at GitHub material-ui-docs :(, so I try to ask here.
BTW seems weird to install outside container :/
when tried to install, got error:
error - ./pages/_app.js
mui-docs | Error: Cannot find module 'babel-plugin-macros'
mui-docs | Require stack:
mui-docs | - /home/node/material-ui-docs/node_modules/next/dist/compiled/babel/bundle.js
mui-docs | - /home/node/material-ui-docs/node_modules/next/dist/compiled/babel/code-frame.js
mui-docs | - /home/node/material-ui-docs/node_modules/next/dist/build/webpack/plugins/wellknown-errors-plugin/parseScss.js
here is docker-compose.yml
version: "3.5"
services:
svcMuiDocs:
image: "node:17-slim"
restart: always
container_name: "mui-docs"
#user: "node"
working_dir: /home/node/material-ui-docs
environment:
- NODE_ENV=production
volumes:
- "./:/home/node/material-ui-docs:rw"
ports:
- "8012:8012"
entrypoint: ["/bin/sh","-c"]
command:
- |
yarn && yarn docs:dev --port=8012
networks:
- default
networks:
default:
external:
name: svcBackend
site won't start
can anybody help please ?
AS.
well, just blind shooting... replaced few words in docker-compose.yml to:
version: "3.5"
services:
svcMuiDocs:
image: "node:17-slim"
restart: always
container_name: "mui-docs"
#user: "node"
working_dir: /home/node/material-ui-docs
environment:
- NODE_ENV=development
volumes:
- "./:/home/node/material-ui-docs:rw"
ports:
- "8012:8012"
entrypoint: ["/bin/sh","-c"]
command:
- |
yarn --ignore-platform && yarn docs:dev --port=8012
networks:
- default
networks:
default:
external:
name: svcBackend
NODE_ENV=development
added --ignore-platform to yarn
and viola it works :)
AS.

stuck on "starting your workflow run" on Github Actions

I wanted to test "github action" feature but it is not starting and its is stuck.It just says "Starting your workflow run..."
Is there something wrong in my build.yml file
This is my build.yml file:
name: CI
on:
pull_request:
branches:
- master
workflow_dispatch:
env:
POSTGRESQL_VERSION: 13.1
POSTGRESQL_DB: students_info
POSTGRESQL_USER: postgres
POSTGRESQL_PASSWORD: password
JAVA_VERSION: 1.15
jobs:
build:
runs-on: ubuntu-16.04
services:
postgres:
image: postgres:13.1
env:
POSTGRES_DB: ${{ env.POSTGRESQL_DB }}
POSTGRES_USER: ${{ env.POSTGRESQL_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRESQL_PASSWORD }}
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v1.4.3
with:
java-version: ${{ env.JAVA_VERSION }}
- name: Maven Clean Package
run: |
./mvnw --no-transfer-progress clean package -P build-frontend
PS:I have tried with ubuntu-latest as well
There is currently a problem with GitHub Actions:
https://www.githubstatus.com/incidents/zbpwygxwb3gw

Docker connection refused between containers

I'm using Postgres, Redis and Node.js (adding dependencies with yarn), and trying to integrate it all with a docker-compose.yml file.
I have the following docker-compose.yml:
version: '3'
services:
postgres:
image: postgres:latest
restart: unless-stopped
environment:
- POSTGRES_DB=mybase
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypass
redis:
image: redis:latest
restart: unless-stopped
migrate:
build: .
entrypoint: node_modules/.bin/sequelize db:migrate --config src/config/database.js --migrations-path src/database/migrations/
volumes:
- ./:/app
- /app/node_modules
depends_on:
- postgres
wavetech-be:
build:
dockerfile: Dockerfile
context: .
restart: on-failure
volumes:
- /app/node_modules
- ./:/app
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- DB_HOST=postgres
- DB_USER=myuser
- DB_PASS=mypass
- DB_PORT=5432
- DB_NAME=mybase
depends_on:
- redis
- migrate
And the following Dockerfile:
FROM node:alpine
WORKDIR "/app"
COPY ./package.json ./
RUN apk add yarn
RUN yarn
COPY . .
CMD [ "yarn", "dev" ]
However, when I docker-compose up, I keep getting connection problems with both databases:
migrate_1 |
migrate_1 | ERROR: connect ECONNREFUSED 127.0.0.1:5432
migrate_1 |
...
wavetech-be_1 | (node:85) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
The answer has two parts:
First, as pointed out by #jonrsharpe, the description of the migrate service was lacking the environment variables. So, as it is with the volumes, each service needs its own environment variables configured.
migrate:
build: .
entrypoint: node_modules/.bin/sequelize db:migrate --config src/config/database.js --migrations-path src/database/migrations/
volumes:
- ./:/app
- /app/node_modules
environment:
- DB_HOST=postgres
- DB_USER=myuser
- DB_PASS=mypass
- DB_PORT=5432
- DB_NAME=mybase
- APP_PORT=3000
depends_on:
- postgres
Second, I am using Bull to manage my Redis server. I was importing a config and passing it directly to Redis, so:
import redisConfig from '../../config/redis';
...
init() {
this.queues = Object.values(jobs).map(job => ({
bull: new BullQueue(job.key, redisConfig),
name: job.key,
handle: job.handle,
}));
}
And it turns out that Bull was trying to just use the default Redis configuration. When I passed the environment variables directly into the Bull config, it worked properly:
init() {
this.queues = Object.values(jobs).map(job => ({
bull: new BullQueue(job.key, {
redis: {
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
},
}),
name: job.key,
handle: job.handle,
}));
}

DB connection error Error: connect ECONNREFUSED 127.0.0.1:5432?

Running a docker container with postgres and npm produces this error, while running them separetly
(npm and docker) doesn't. What seems to be the error here?
My docker-compose.yml:
version: "3.5"
services:
db:
image: postgres:12.1
ports:
- 5432:5432
environment:
- FLYWAY_URL=jdbc:postgresql://db:5432/
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypass
- POSTGRES_DB=mydb
volumes:
- ./db/data:/var/lib/postgresql/data
migrate:
image: boxfuse/flyway
entrypoint: ["sh", "-c", "/flyway/wait-for.sh db:5432 -- flyway migrate"]
depends_on:
- db
volumes:
- ./common/migrations/:/flyway/sql:rw
- ./common/scripts/wait-for.sh:/flyway/wait-for.sh:rw
environment:
# - FLYWAY_LOCATIONS=classpath:/common/migrations/
- FLYWAY_PASSWORD=mypass
- FLYWAY_USER=myuser
- FLYWAY_URL=jdbc:postgresql://db:5432/mydb?user=myuser&password=mypass
- FLYWAY_CONNECT_RETRIES=30
networks:
default:
name: mydb-local
services:
example-service:
build: .
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- 3000:3000
- 9229:9229
command: npm start
Thing I have checked:
postgresql.conf & pg_hba.conf accepts connections.
DB credentials are correct.
Db is running

How to connect to Postgres in GitHub Actions

I am trying GitHub Actions for CI with a Ruby on Rails application.
My setup is with VM, not running the Ruby build in a container.
This is my workflow yml. It runs all the way without errors until the step "Setup Database".
name: Rails CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:10.10
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: db_test
ports:
- 5432/tcp
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:latest
ports:
- 6379/tcp
steps:
- uses: actions/checkout#v1
- name: Set up ruby 2.5
uses: actions/setup-ruby#v1
with:
ruby-version: 2.5.5
- name: Set up node 8.14
uses: actions/setup-node#v1
with:
node-version: '8.14'
- name: Setup system dependencies
run: sudo apt-get install libpq-dev
- name: Setup App Dependencies
run: |
gem install bundler -v 1.17.3 --no-document
bundle install --jobs 4 --retry 3
npm install
npm install -g yarn
- name: Run rubocop
run: bundle exec rubocop
- name: Run brakeman
run: bundle exec brakeman
- name: Setup Database
env:
RAILS_ENV: test
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
run: |
cp config/database.yml.ci config/database.yml
bundle exec rails db:create
bundle exec rails db:schema:load
- name: Run rspec
env:
RAILS_ENV: test
REDIS_HOST: redis
REDIS_PORT: ${{ job.services.redis.ports[6379] }}
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
run: bundle exec rspec --tag ~type:system
I am able to install ruby, node, the images, Postgres as a service, etc, and run Rubocop and Brakeman. But when I try to set up the DB before running Rspec it says it cannot connect to the DB.
As far as I've been able to ascertain, the host is localhost when running the VM configuration as opposed to a container configuration.
This is the database.yml.ci that the "Setup Database" step copies to the database.yml to be used by Rails.
test:
adapter: postgresql
encoding: unicode
database: db_test
pool: 5
username: <%= ENV['POSTGRES_USER'] %>
password: <%= ENV['POSTGRES_PASSWORD'] %>
host: <%= ENV['POSTGRES_HOST'] %>
I expected Postgres to be correctly set up and bundle exec rails db:create to create the database. However, it throws the following error:
rails aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I've tried all sorts of different configurations, but unfortunately, Actions is sort of knew and there doesn't seem to be a lot of material available online.
Any ideas on how to fix this?
===========================
EDIT:
So I was able to sort this out through trial and error. I ended up using a docker image with a ruby and node container. This is the working configuration:
on:
push:
branches:
- master
pull_request:
branches:
- master
- development
- release
jobs:
build:
runs-on: ubuntu-latest
container:
image: timbru31/ruby-node:latest
services:
postgres:
image: postgres:11
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ci_db_test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
chrome:
image: selenium/standalone-chrome:latest
ports:
- 4444:4444
steps:
- uses: actions/checkout#v1
- name: Setup app dependencies
run: |
gem install bundler -v 1.17.3 --no-document
bundle install --jobs 4 --retry 3
npm install
npm install -g yarn
- name: Run rubocop
run: bundle exec rubocop
- name: Run brakeman
run: bundle exec brakeman
- name: Setup database
env:
RAILS_ENV: test
POSTGRES_HOST: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ci_db_test
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
run: |
cp config/database.yml.ci config/database.yml
bundle exec rails db:create
bundle exec rails db:schema:load
- name: Run rspec
env:
RAILS_ENV: test
POSTGRES_HOST: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ci_db_test
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
SELENIUM_URL: 'http://chrome:4444/wd/hub'
run: bundle exec rspec
And the CI DB configuration database.yml.ci
default: &default
adapter: postgresql
encoding: unicode
username: <%= ENV['POSTGRES_USER'] %>
password: <%= ENV['POSTGRES_PASSWORD'] %>
host: <%= ENV['POSTGRES_HOST'] %>
pool: 5
database: <%= ENV['POSTGRES_DB'] %>
test:
<<: *default
I have a slightly different setup but this was the most relevant question when I encountered the same error so wanted to post here in case it can help. The two things that were critical for me were:
1) Set the DB_HOST=localhost
2) Set the --network="host" argument when you start the docker container with your 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/checkout#v2
- name: Build my_image docker image
uses: whoan/docker-build-with-cache-action#v5
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"
Your problem appears to be that Postgres is not exposed on port 5432. Try to replace the port number with ${{ job.services.postgres.ports[5432] }}.
There are examples here: https://github.com/actions/example-services/blob/master/.github/workflows/postgres-service.yml
I had this challenge when trying to set up GitHub actions for a Rails Application.
Here's what worked for me:
name: Ruby
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version:
- '2.7.2'
node-version:
- '12.22'
database-name:
- my-app
database-password:
- postgres
database-user:
- postgres
database-host:
- 127.0.0.1
database-port:
- 5432
services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: ${{ matrix.database-name }}
POSTGRES_USER: ${{ matrix.database-user }}
POSTGRES_PASSWORD: ${{ matrix.database-password }}
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 Git Repository
uses: actions/checkout#v2
- name: Set up Ruby, Bundler and Rails
uses: ruby/setup-ruby#v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Set up Node
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: Install packages
run: |
yarn install --check-files
- name: Setup test database
env:
RAILS_ENV: test
DATABASE_NAME_TEST: ${{ matrix.database-name }}
DATABASE_USER: ${{ matrix.database-user }}
DATABASE_PASSWORD: ${{ matrix.database-password }}
DATABASE_HOST: ${{ matrix.database-host }}
DATABASE_PORT: ${{ matrix.database-port }}
POSTGRES_DB: ${{ matrix.database-name }}
run: |
bundle exec rails db:migrate
bundle exec rails db:seed
Note:
Replace my-app with the name of your app.
You can leave the database-password and database-user as postgres
That's all.
I hope this helps