Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local docker development environment #9

Closed
petercv opened this issue Jan 6, 2020 · 6 comments · Fixed by #25
Closed

Local docker development environment #9

petercv opened this issue Jan 6, 2020 · 6 comments · Fixed by #25

Comments

@petercv
Copy link
Contributor

petercv commented Jan 6, 2020

Do you also publish the layers in Docker Hub so they can be installed in your local development setup? Or do you recommend installing the extensions directly in the base development docker image by using a custom Dockerfile?

@petercv
Copy link
Contributor Author

petercv commented Jan 9, 2020

What I've done now is creating a local Dockerfile with the commands to to build the extension and then use the base image and copy the required files in there. But it could be easier if every extension layer is also made available as a Docker image on Docker Hub.

This is my Dockerfile:

# Build gmp extension
FROM bref/build-php-74 AS ext

# Fix library path
ENV LD_LIBRARY_PATH=/usr/lib:/usr/lib64:$LD_LIBRARY_PATH

# Install packages
RUN yum install -y gmp-devel

# Build PHP extension
WORKDIR /tmp/build/php/ext/gmp
RUN phpize && \
    ./configure \
        --build=x86_64-pc-linux-gnu \
        --prefix=${INSTALL_DIR} \
        --enable-option-checking=fatal

RUN make -j $(nproc) install
RUN cp /opt/bref/lib/php/extensions/no-debug-zts-*/gmp.so /tmp/gmp.so

# Base image
FROM bref/php-74-fpm-dev

# Copy things we installed to the final image
COPY --from=ext /usr/include/gmp-mparam-x86_64.h /opt/bref/include/gmp-mparam-x86_64.h
COPY --from=ext /usr/include/gmp-mparam.h /opt/bref/include/gmp-mparam.h
COPY --from=ext /usr/include/gmp-x86_64.h /opt/bref/include/gmp-x86_64.h
COPY --from=ext /usr/include/gmp.h /opt/bref/include/gmp.h
COPY --from=ext /usr/include/gmpxx.h /opt/bref/include/gmpxx.h

COPY --from=ext /usr/lib64/libgmp.so /opt/bref/lib64/libgmp.so
COPY --from=ext /usr/lib64/libgmpxx.so /opt/bref/lib64/libgmpxx.so

COPY --from=ext /tmp/gmp.so /opt/bref-extra/gmp.so

@Nyholm
Copy link
Collaborator

Nyholm commented Jan 26, 2020

Hey. No nothing is published on Docker hub.

I agree with you, I think we should. A while ago I added this PR to bref: brefphp/bref#519

It builds docker images, tags them and upload them to Dockerhub. I think we should do something similar here, right?

@mnapoli
Copy link
Member

mnapoli commented Jan 26, 2020

@Nyholm if you want to be able to publish in the Docker Hub "bref" account let me know, I can create permissions.

@deleugpn
Copy link
Member

deleugpn commented Mar 7, 2020

I'm currently looking for a way to deal with this as well. I want to run automation tests on CodeBuild using the image provided by Bref, but I also need to copy the GMP extension over there. It makes me miss Alpine (apk add php7-gmp), but Lambda does have a lower maintenance burden than containers.

@deleugpn
Copy link
Member

deleugpn commented Mar 7, 2020

One thing I just tried, but didn't go so well: shared volumes between containers.

The idea was to have 2 containers on a docker-compose (e.g. php-74 & ext-gmp-php74) both sharing a volume. I used this file to build the image locally and then tried to share the volume with the main container:

version: '3.7'

services:
  my-service:
    image: bref/php-74
    entrypoint: /usr/bin/tail
    command: ["-f", "/dev/null"]
    user: root
    container_name: environment_my_service
    volumes:
      - ./tests/setup/bref.ini:/opt/bref/etc/php/conf.d/bref.ini   # disable opcache 
      - ext-gmp-volume:/opt/bref/include
      - ext-gmp-volume:/opt/bref/lib64
      - ext-gmp-volume:/opt/bref-extra
    environment:
      - APP_ENV=testing
      - APP_SERVICES_CACHE=/tmp/imports/storage/cache/services.php
      - APP_PACKAGES_CACHE=/tmp/imports/storage/cache/packages.php
      - APP_ROUTES_CACHE=/tmp/imports/storage/cache/routes.php
    depends_on:
      - ext-gmp

  ext-gmp:
    image: bref/php74-ext-gmp:latest
    entrypoint: /usr/bin/tail
    command: ["-f", "/dev/null"]
    volumes:
      - ext-gmp-volume:/opt/bref/include
      - ext-gmp-volume:/opt/bref/lib64
      - ext-gmp-volume:/opt/bref-extra
    user: root

volumes:
  ext-gmp-volume:

The expectation was that by doing this, I'd be able to add the extension files from a side container into the main (my-service) container. The first thing that failed is that this volume format does not allow file-by-file pointer. It can only be an entire folder. When trying the entire folder, the ext-gmp declaration overrides the entire /opt/bref/lib64 folder from bref/php-74 image, which makes it lose other extensions. In an ideal world, we would have each "layer" building a dedicated folder (such as /opt/bref/extensions/gmp and EVERY file necessary would be there, but I don't have the required knowledge to even evaluate whether this is feasible at all.

@jjanvier
Copy link

jjanvier commented Apr 8, 2020

Same need for me 👍
I'd like to use the xdebug extension on my local dev environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants