Hi guys ,
I have Bitbucket pipeline with 3 steps. In the 1st step the pipeline build dockerimage with php 8.2 on Alpine 3.20 and save it. In the 2nd step docker load the custom image, volume and then I need to run composer install and some tests.
My code is below:
steps:
- step: &build
name: Docker Build
runs-on:
- self.hosted
- linux.arm64
- apps
script:
- DOCKER_BUILDKIT=1 docker build -f Dockerfile -t url/to/our/image/repo .
- docker save --output tmp-image.docker url/to/our/image/repo
artifacts:
- tmp-image.docker
services:
- docker
- step: &test
name: Composer Tests
runs-on:
- self.hosted
- linux.arm64
- apps
script:
- *setEnv
- docker load --input ./tmp-image.docker
- docker images
- docker run -v ${BITBUCKET_CLONE_DIR}:/appfolder
url/to/out/image/repo composer install && ./vendor/bin/phpunit
services:
- docker
This is my Dockerfile:
FROM url/to/our/image/repo:8.2.20-fpm-alpine as base
ARG APP_ENV=dev
ENV COMPOSER_ALLOW_SUPERUSER=1
WORKDIR /appfolder
ENV PATH="$PATH:/usr/bin/php"
RUN sed -i "s|listen = 9000|listen = /var/run/php/fpm.sock\nlisten.mode = 0666|" /usr/local/etc/php-fpm.d/zz-docker.conf \
&& mkdir -p /var/run/php/
COPY --from=composer/composer /usr/bin/composer /usr/local/bin/composer
RUN mkdir -p -m 0600 /root/.ssh \
&& ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts \
&& rm -rf /appfolder && mkdir /appfolder
COPY . /appfolder
RUN --mount=type=ssh,id=key set -xe \
&& if [ "$APP_ENV" = "prod" ]; then export ARGS="--no-dev"; fi \
&& composer install --prefer-dist --no-scripts --no-progress --no-interaction $ARGS \
&& composer dump-autoload --classmap-authoritative \
&& rm -rf /root/.ssh/ \
&& php -d memory_limit=256M
Some more information:
/appfolder # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/php
If I run the tests on my local machine:
If I run the tests on my local machine:
/appfolder # vendor/bin/php
php-cs-fixer php-parse phpstan phpstan.phar phpunit
/app # vendor/bin/php
php-cs-fixer php-parse phpstan phpstan.phar phpunit
/app # vendor/bin/phpstan
Note: Using configuration file /appfolder/phpstan.dist.neon.
6/6 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
Below is the error from step 2 in the pipeline from the second command from the test:
/usr/bin/env: ‘php’: No such file or directory
I already tried with the following paths for the tests "./vendor/bin/phpunit", "vendor/bin/phpunit", "php vendor/bin/phpunit", "php ./vendor/bin/phpunit", "/usr/bin/php vendor/bin/phpunit".
What I'm doing wrong?
Regards,