I am currently building a docker image on top of php8.0-fpm where I am adding composer, sentry-cli etc… and then using this image in future jobs to test and deploy my application. However, in the latest version of Laravel Vapor, it is recommended that you dockerize your application before deploying it. The issue is that the php8.0-fpm that I am using doesn’t have docker installed. I will add both my Dockerfile and gitlab-ci script below for further context.
I would appreciate any help possible! Thank you.
gitlab-ci.yml
stages:
- build
- test
- deploy
cache:
paths:
- vendor/
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
build:
image: docker:latest
stage: build
services:
- docker:dind
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:latest .
- docker push $CI_REGISTRY_IMAGE:latest
test:
image: $CI_REGISTRY_IMAGE:latest
stage: test
services:
- docker:dind
artifacts:
paths:
- vendor/
script:
- composer install
- touch database/database.sqlite
- php artisan key:generate --env=testing
- php artisan migrate --env=testing
- php artisan passport:install --env=testing
- php artisan db:seed --env=testing
- php artisan geoip:update --env=testing
- php artisan test --env=testing
deploy_development:
image: $CI_REGISTRY_IMAGE:latest
stage: deploy
services:
- docker:dind
artifacts:
paths:
- vendor/
environment:
name: development
url: https://dev.xxx.io
script:
- VERSION=$(sentry-cli releases propose-version)
- sentry-cli releases new -p api $VERSION
- sentry-cli releases set-commits --auto $VERSION
- composer install
- php vendor/bin/vapor deploy development --commit="$CI_COMMIT_SHA"
only:
- development
deploy_staging:
image: $CI_REGISTRY_IMAGE:latest
stage: deploy
services:
- docker:dind
artifacts:
paths:
- vendor/
environment:
name: staging
url: https://stage.xxx.io
script:
- VERSION=$(sentry-cli releases propose-version)
- sentry-cli releases new -p api $VERSION
- sentry-cli releases set-commits --auto $VERSION
- composer install
- php vendor/bin/vapor deploy staging --commit="$CI_COMMIT_SHA"
only:
- master
deploy_production:
image: $CI_REGISTRY_IMAGE:latest
stage: deploy
services:
- docker:dind
artifacts:
paths:
- vendor/
when: manual
environment:
name: production
url: https://xxx.io
script:
- VERSION=$(sentry-cli releases propose-version)
- sentry-cli releases new -p api $VERSION
- sentry-cli releases set-commits --auto $VERSION
- sentry-cli releases finalize "$VERSION"
- composer install
- php vendor/bin/vapor deploy production --commit="$CI_COMMIT_SHA"
only:
- master
Dockerfile
FROM php:8.0-fpm as builder
# Require composer dependency manager
COPY --from=composer /usr/bin/composer /usr/bin/composer
# Require install-php-extensions script (https://github.com/mlocati/docker-php-extension-installer)
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
# Update apt repository
RUN apt-get update -y
# Install requirements
RUN apt-get install -y libgmp-dev re2c libmhash-dev libmcrypt-dev file libzip-dev zlib1g-dev libicu-dev g++
RUN ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/local/include/
RUN docker-php-ext-configure gmp
RUN docker-php-ext-configure intl
# Install php extensions
RUN docker-php-ext-install gmp intl zip pdo
# Install php extensions (via 3rd party script)
RUN install-php-extensions http
# Install Sentry-CLI
RUN curl -sL https://sentry.io/get-cli/ | bash