Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Curl over custom AWS definitions.service

Garry Dias May 9, 2020

Hi, I'd like to know how to curl a defined service in difinitions.services section from my step.

This is my bitbucket-pipelines.yml:

image: cypress/base:10
pipelines:
default:
- step: &run
name: Run
image: mongo
script:
- curl http://my-service/my-path
services:
- my-service
branches:
'**':
- step: *run

definitions
:
services:
my-service:
image:
name: 098765431234.dkr.ecr.us-east-1.amazonaws.com/my-service:latest
aws:
access-key: $AWS_ACCESS_KEY_ID
secret-key: $AWS_SECRET_ACCESS_KEY
mongo:
image: mongo

 

That's the error I'm facing:

<1s+ curl http://my-service/my-path  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: my-service

 

I'm assuming the request could be performed to service definition name my-service instead of host name or IP, folowing docker-compose principles. 

 

Please, appreciate any help

 

Thanx

2 answers

1 accepted

0 votes
Answer accepted
Halyna Berezovska
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 15, 2020

Hello @Garry Dias , thanks for using pipelines.

I suspect, definitions cannot work this way, I could not find example without the image mentioning. Definitions documentation .

But if I got your point, the feature you want, is described here https://community.atlassian.com/t5/Bitbucket-questions/Is-it-possible-to-use-the-add-host-option-in-pipeline-docker/qaq-p/1156756 .

Garry Dias May 27, 2020

I tried his solution but I hadn't success. 

I'm trying to change the strategy and perform a docker run in my scripts block. But even so I'm facing connection refused issues when trying a curl.

Already tried:

  • docker run --add-host
  • use eth0 local dynamic ip 
  • and the solution in your suggested link

 

At this point, I just want fire an http request over a container started from pipelines script on 8080 port

Halyna Berezovska
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 29, 2020

@Garry Dias could you please share a part of pipeline and more logs if you have? did you expose the appropriate port ? without this it would not be accessible.

Cheers, Galyna

Halyna Berezovska
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 29, 2020

Sorry, I saw the answer above. Thanks for sharing

Garry Dias May 29, 2020

Actually, after my post I noticed a randomly failing curl after a lot of pipelines run. Even using 9090 port.

I ran this yml I've shared dozens of times and surprisingly sometimes 8080 requests works and 9090 did not.

I suspected the container hadn't started the server yet.

So I inserted a 

- sleep 10

between docker run and curl. Then, after dozens of pipelines execution, 100% of these executions were successful.

So, the REAL cause was the container port availability delay. 

Everything's fine now.

 

Thanx one more time, @Halyna Berezovska 

 

note: I kept as Accepted Answer because there's no support to accept replies

Like Halyna Berezovska likes this
2 votes
Garry Dias May 28, 2020

@Halyna Berezovska I've found the issue.

It seems that not only the port described at Caveats and limitations section here is actually restricted but also 8080.

As we can see, the 1st and 5th requests in bitbucket-pipelines.yml file bellow are similar, except by its ports. The 5th is the one that have worked:


# This is a sample build configuration for Docker.
# Check our guides at https://confluence.atlassian.com/x/O1toN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: atlassian/default-image:2

pipelines:
default:
- parallel:
- step:
services:
- docker
script:
- docker run -d -p 8080:80 strm/helloworld-http
- curl -vvv http://localhost:8080
- step:
services:
- docker
script:
- docker run -d -p 8080:80 strm/helloworld-http
- curl -vvv http://127.0.0.1:8080
- step:
services:
- docker
script:
- sh -c 'echo 8.8.8.8 myserver >> /etc/hosts'
- docker run -d -p 8080:80 strm/helloworld-http
- curl -vvv http://myserver:8080
- step:
services:
- docker
script:
- sh -c 'echo 8.8.8.8 myserver >> /etc/hosts'
- docker run -d -p 8080:80 strm/helloworld-http
- curl -vvv myserver:8080

# This is the one that properly works. I suppose 8080 is a restricted port
- step:
services:
- docker
script:
- docker run -d -p 9090:80 strm/helloworld-http
- curl -vvv http://localhost:9090


- step:
services:
- docker
script:
- docker run --name myserver -d -p 8080:80 strm/helloworld-http
- curl -vvv http://myserver:8080
- step:
services:
- docker
script:
- sh -c 'echo 8.8.8.8 myserver >> /etc/hosts'
- docker run --add-host myserver:8.8.8.8 -d -p 8080:80 strm/helloworld-http
- curl -vvv http://myserver:8080



This pipelines file was extracted from blank project with only bitbucket-pipelines.yml file inside.

Halyna Berezovska
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 29, 2020

@Garry Dias so you did succeed to make it?

Halyna Berezovska
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 29, 2020

Yes, 8080 is the port that is often used. Perhaps that is why you cannot use again

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events