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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Curl over custom AWS definitions.service Edited

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

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 .

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

@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

Sorry, I saw the answer above. Thanks for sharing

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, @Galyna Zholtkevych 

 

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

Like Galyna Zholtkevych likes this

@Galyna Zholtkevych 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.

@Garry Dias so you did succeed to make it?

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
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,320 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you