A Dockerfile
for building an image
for your Laravel app Gitlab CI/CD pipelines.
Although folder structure is self-explanatory, description is as below:
.
├── Dockerfile
├── LICENSE
├── readme.md
├── scripts
│ ├── cleanup.sh # Removes build dependencies for lighter image size.
│ ├── install-node-yarn.sh # Install your global npm/yarn packages here.
│ ├── install-packages.sh # OS packages will be installed by this file.
│ └── install-php.sh # PHP extensions and installation.
└── tests
└── goss.yaml # See "testing" section
We created the Dockerfile
with image size in mind, only packages and PHP extensions which are absolutely necessary
are installed.
Service | Version | Argument |
---|---|---|
PHP | 8.2.0 | PHP_VERSION |
Composer | 2.2.5 | COMPOSER_VERSION |
Node | 21.0.0 | NODE_VERSION |
NPM | 10.2.0 | NPM_VERSION |
Yarn | latest | N/A |
reg | latest | N/A |
cfcli | latest | N/A |
local-php-security-checker | latest | N/A |
As you can see in the table above, some services have an argument in Dockerfile
for you to modify the installation
version.
To do so, you need to clone the repo and build the image yourself:
git clone https://github.com/laramatics/gitlab-ci.git
cd gitlab-ci
# Modify files...
docker build \
--build-arg NPM_VERSION=9.2.0 \
--build-arg PHP_VERSION=8.2.0 \
-t <image_name> .
If you want to add more extensions to the PHP installation, you will have to build your own image based on the one
already built or modify the Dockerfile
and scripts/*
to your liking
and build your own image from it.
See Docker PHP Extension Installer for available extensions, alternatively you can install them fom source.
FROM laramatics/gitlab-ci:latest
# Add your extentions here...
RUN docker-php-ext-install -j "$(nproc)" <package_name>
Sometimes you need a specific package for your pipeline; as described in the previous section, you can build your own
image from laramatics/gitlab-ci
or clone this repo and modify files to suit your needs.
git clone https://github.com/laramatics/gitlab-ci.git
cd gitlab-ci
# Modify files...
docker build -t <image_name> .
Tests are written using GOSS, to test your changes after modifying source files and building your own image, run:
GOSS_FILES_PATH=tests dgoss run -it <image_name>