I have a two stages build using Docker, in the second stage of build I have something like this:
ARG COMPOSER_VERSION=2.5
ARG PHP_VERSION=7.4-apache
FROM --platform=${TARGETPLATFORM} php:${PHP_VERSION} AS composer
COPY --from=composer:2.5 /usr/bin/composer /usr/local/bin/composer
RUN apt-get -yq update && \
apt-get -yqq install ssh git zlib1g-dev libzip-dev zip unzip && \
docker-php-ext-install zip && \
mkdir -p -m 0600 /root/.ssh && \
ssh-keyscan eae-git.eng.utah.edu >> /root/.ssh/known_hosts
COPY ./html .
ARG CACHE_BUST_COMPOSER
RUN COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-scripts --no-progress --no-interaction --no-dev -vvv --ignore-platform-req=ext-bcmath --ignore-platform-req=ext-gd --ignore-platform-req=ext-zip --ignore-platform-req=ext-ldap --ignore-platform-req=ext-exif --ignore-platform-req=ext-imagick --ignore-platform-req=ext-mongodb
FROM --platform=${TARGETPLATFORM} php:${PHP_VERSION} AS build
COPY --from=composer:2.5 /usr/bin/composer /usr/local/bin/composer
RUN apt-get update && \
mkdir -p /var/run/slapd && \
DEBIAN_FRONTEND=noninteractive apt-get install -yqq -f --no-install-recommends \
git \
supervisor \
vim \
slapd \
ldap-utils \
ldapscripts \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libwebp-dev \
libgmp-dev \
libldb-dev \
libldap2-dev \
libxml2-dev \
imagemagick \
libmagickwand-dev \
libzip-dev \
libmongoc-dev \
libbson-dev \
libicu-dev \
libcap2-bin \
zlib1g-dev \
ghostscript \
&& docker-php-ext-configure bcmath \
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
&& docker-php-ext-configure gmp \
&& docker-php-ext-configure intl \
&& docker-php-ext-configure ldap \
&& docker-php-ext-configure pdo_mysql \
&& docker-php-ext-configure exif \
&& docker-php-ext-configure xmlrpc \
&& docker-php-ext-install -j$(nproc) bcmath gd gmp intl ldap pdo_mysql exif xmlrpc zip \
&& pecl install imagick mongodb \
&& docker-php-ext-enable imagick mongodb \
&& apt-get purge --auto-remove -y $PHPIZE_DEPS \
&& apt-get clean autoclean \
&& apt-get autoremove --yes \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /usr/src \
&& a2enmod vhost_alias \
&& a2enmod rewrite headers \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/apache2
COPY --from=composer --chown=www-data /var/www/html /var/www/html
WORKDIR /var/www/html
RUN php artisan storage:link \
&& php artisan vendor:publish --all --no-interaction \
&& chown -R www-data:www-data /var/www \
&& chown -R www-data:www-data /var/log/apache2 \
&& find /var/www/html -type f -exec chmod 664 {} \; \
&& find /var/www/html -type d -exec chmod 775 {} \;
COPY ./build/docker/apache /etc/apache2/
ARG ENV
RUN if [ "$ENV" = "DEV" ] ; then \
mv /etc/apache2/dev.conf /etc/apache2/sites-available/000-default.conf ; \
rm /etc/apache2/prod.conf ; \
else \
mv /etc/apache2/prod.conf /etc/apache2/sites-available/000-default.conf ; \
rm /etc/apache2/dev.conf ; \
fi
ADD ./build/docker/supervisord.conf /etc/supervisor/supervisord.conf
ADD ./build/docker/php.ini-production "$PHP_INI_DIR/php.ini"
USER www-data
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
Using GitLab CI to run the Kaniko:
Build a New Image:
stage: build
image:
name: gcr.io/kaniko-project/executor:v1.18.0-debug
entrypoint: [""]
script:
- CACHE_BUST_COMPOSER=$(date +%s)
- /kaniko/executor
--cache=true
--cache-repo="${CI_REGISTRY_IMAGE}/cache"
--snapshot-mode=redo
--use-new-run
--skip-unused-stages
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/build/docker/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}${DIR}:${LATEST_VERSION}"
--build-arg EAE_GITLAB_TOKEN=${EAE_GITLAB_TOKEN}
--build-arg CACHE_BUST_COMPOSER=${CACHE_BUST_COMPOSER}
--build-arg ENV=PROD
When I'm using Docker on my local machine it caches this layer no problem but when I run the same build using Kaniko it always says it cannot find the cache layer for this one.
A little bit of more context, the first layer is composer install layer and it always going to be invalidated as it is required for our build and also cache repo for Kaniko is working just fine, it finds some layers and use them but not all of them.
Does any have any idea what I'm missing here? this layer is big one and takes a lot of time to build.