I make a short-cut for my ci.yml
jobs:
test:
runs-on: ubuntu-latest
services:
dynamodb:
image: amazon/dynamodb-local
ports:
- 8000:8000
my-private-server:
image: ghcr.io/myPrivateImage
env:
DYNAMODB_ENDPOINT: http://localhost:8000
ports:
- 80:80
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm ci
- run: npm test
env:
DYNAMODB_ENDPOINT: http://localhost:8000
MY_PRIVATE_SERVICE_ENDPOINT: http://localhost:80
I have a private-server-container with EXPOSE 80
, and I want to make it connected with local-dynamodb. My test is about loading some sample data into local-dynamodb first, and then my private-server will read these data from the local-dynamodb and return a value. But I always get the Error about " request to http://localhost/value?myQuery failed, reason: connect ECONNREFUSED 127.0.0.1:80"
I think the problem maybe comes from the server container communication. But I am not sure. I would appreciate it if anyone could help.
CodePudding user response:
All right, after I try something else, I finally fix this problem. The solution is by running the job in the container. Here is https://docs.github.com/en/actions/using-containerized-services/about-service-containers.
Here is code update.
jobs:
test:
runs-on: ubuntu-latest
container: node:16-bullseye
services:
dynamodb:
image: amazon/dynamodb-local
my-private-server:
image: ghcr.io/myPrivateImage
env:
DYNAMODB_ENDPOINT: http://dynamodb:8000
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm ci
- run: npm test
env:
DYNAMODB_ENDPOINT: http://dynamodb:8000
MY_PRIVATE_SERVICE_ENDPOINT: http://my-private-server:80