Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Pipelines, PHPUnit, Docker Compose and Laravel Edited

I'm trying to run PHPUnit tests on BitBucket Pipelines and I'm getting some issues with connecting to the database. I can run everything as normal by downloading the repo into a new directory, clearing docker images and pruning, and simply running everything Pipelines does.

I can't figure out why, if Pipelines is running a docker container, it can't connect to the database. It installs composer packages (which includes a key generation) but fails on the step for migrate:fresh.

I have this for docker-compose-bitbucket.yml

version: "3.7"
services:
app:
build:
args:
user: pcsAdmin
uid: 1000
context: ./
dockerfile: Dockerfile
image: pcs
container_name: pcs-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- pcs
db:
image: mysql:5.7
container_name: pcs-db
restart: unless-stopped
environment:
MYSQL_DATABASE: "${DB_DATABASE:-pcs}"
MYSQL_ROOT_PASSWORD: "${DB_PASSWORD:-root}"
MYSQL_PASSWORD: "${DB_PASSWORD:-root}"
MYSQL_USER: "${DB_USERNAME:-pcsAdmin}"
SERVICE_TAGS: dev
SERVICE_NAME: mysql
ports:
- 33306:3306
networks:
- pcs
nginx:
image: nginx:1.17-alpine
container_name: pcs-nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d
networks:
- pcs
networks:
pcs:
driver: bridge


In bitbucket-pipelines.yml

image: php:8-fpm
pipelines:
default:
- step:
image: docker/compose:latest
services:
- docker
caches:
- docker
script:
- docker-compose -f docker-compose-bitbucket.yml build
- docker-compose -f docker-compose-bitbucket.yml up -d
- docker-compose exec -T app mv .env.pipelines .env
- docker-compose exec -T app composer install
- docker-compose exec -T app php artisan migrate:fresh --seed
- docker-compose exec -T app ./vendor/bin/phpunit
- docker-compose down 

.env.pipelines

APP_ENV=local
APP_KEY=base64:LcfzQg8uGaNiyaoPmn1LOpciqIIHrTTBq/vUdOKt4FY=
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=pcs
DB_USERNAME=pcsAdmin
DB_PASSWORD=root 

 Dockerfile

FROM php:8-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
vim

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Install XDebug
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.mode=remote" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.mode=coverage,develop" >> /usr/local/etc/php/conf.d/xdebug.ini

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user

 

Screen Shot 2021-06-02 at 10.27.11 AM.png

1 answer

1 accepted

1 vote
Answer accepted

I stopped caching docker, and added a prune before any other command.

docker system prune -a -f

I also added a sleep 5 after the up command. Which seems to do the trick.

 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

330 views 2 10
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