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

Pipeline for deploying to docker hub with pip caches

Alexandros Davies May 31, 2019

Hi There,

I'm using Pipelines to build Docker images and deploy them to Docker Hub. The Docker images contain python scripts, with dependencies held in requirements.txt - I imagine a standard configuration for users.

My pipelines file looks like this:

# bitbucket-pipelines.yml

image
: atlassian/default-image:2
pipelines:
default:
- step:
services:
- docker script: # Modify the commands below to build your repository. # Set $DOCKER_HUB_USERNAME and $DOCKER_HUB_PASSWORD as environment variables in repository settings
- export IMAGE_NAME=blah/blah:latest
- docker build -t $IMAGE_NAME .
- docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
- docker push $IMAGE_NAME


 And my Dockerfile looks like this:

# Dockerfile

FROM
python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . /usr/src/app
CMD ["python", "main.py"]

I'd like to cache the requirements used by pip but I'm facing permissions errors when trying to access ~/.caches/pip. Has anyone had this working that can share the modifications they made?

 

Thanks!

1 answer

0 votes
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 11, 2019

Hello,

Are you trying to use the default Pip cache provided by Pipelines? You need to add that to your bitbucket-pipelines.yml:

# bitbucket-pipelines.yml

image
: atlassian/default-image:2
pipelines:
default:
- step:
caches: # Add this!
- pip
services:
- docker script: # Modify the commands below to build your repository. # Set $DOCKER_HUB_USERNAME and $DOCKER_HUB_PASSWORD as environment variables in repository settings
- export IMAGE_NAME=blah/blah:latest
- docker build -t $IMAGE_NAME .
- docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD
- docker push $IMAGE_NAME

What was the exact error message you were getting? Did it provide more details?

Thanks,

Phil

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events