Closed11

Modusの検証

sun_yryrsun_yryr

ちょうどあったlaravelのマルチステージビルドを移してみる

FROM php:8.1-fpm-bullseye as base

WORKDIR /var/www/html

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt update && \
    apt install -y git zip unzip libicu-dev libzip-dev

RUN docker-php-ext-install intl opcache pdo_mysql zip

# install composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER 1

COPY ./docker/8.1/php.ini /usr/local/etc/php/conf.d/php.ini
COPY ./docker/8.1/zzz-www.conf /usr/local/etc/php-fpm.d/zzz-www.conf

# crete a directory to put php-fpm socket file
RUN addgroup --system nginx && \
    adduser --system nginx && \
    adduser nginx nginx && \
    mkdir /var/run/php-fpm

# ------------------------------------------------
# ローカル用にxdebugやdev-dependenciesのインストールを行う
FROM base as local

RUN pecl install xdebug && \
    docker-php-ext-enable xdebug

COPY ./docker/8.1/php_xdebug.ini /usr/local/etc/php/conf.d/php_xdebug.ini

COPY composer.* .
RUN composer install --no-scripts

COPY . .

RUN chmod -R 0777 /var/www/html/storage/ /var/www/html/bootstrap/cache /var/www/html/resources/

# ------------------------------------------------
FROM base as prod

COPY composer.* .
RUN composer install --no-scripts --prefer-dist

COPY . .
COPY .env.example .env

RUN chmod -R 0777 /var/www/html/storage/ /var/www/html/bootstrap/cache /var/www/html/resources/

CMD [ "./docker/8.1/entrypoint.sh" ]
sun_yryrsun_yryr

あれ?

Modusfile

base :-
    (
        from("ubuntu"),
        run("touch modus")
    ).

terminal

$ modus build . base
Resolving 1 base images...
[+] Building 0.0s (3/3) FINISHED                                                                                                                                               
 => [internal] load build definition from modus_temp_nxBWSmYXqwMMZaZ                                                                                                      0.0s
 => => transferring dockerfile: 244B                                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                                           0.0s
 => ERROR resolve image config for ghcr.io/modus-continens/modus-buildkit-frontend:6e4cbde50a                                                                             0.5s
------
 > resolve image config for ghcr.io/modus-continens/modus-buildkit-frontend:6e4cbde50a:
------
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: failed to authorize: rpc error: code = Unknown desc = failed to fetch oauth token: unexpected status: 403 Forbidden
Cleaning up 0 temporary images and tags...
build error: Could not resolve ubuntu: docker build returned exit status: 1
Hidden comment
sun_yryrsun_yryr

メモ

  • tagに数字のみの場合解決できない?(composer:2 → だめ、composer:2.3 → OK)
  • copy("composer.*", ".") がだめ?(cache keyが見つからなかったみたいなエラー)
sun_yryrsun_yryr

logic expressionを組み合わせただけだとruleにならない
ruleの先頭にはimage expressionが必要

sun_yryrsun_yryr

上から順に処理されて、変更があった部分以降はcacheがヒットしないのはdockerと同じか

sun_yryrsun_yryr

並列ビルドはめっちゃ速く感じた
今回使ったお題だとどっちか片っぽでいいからDockerfileでいいか

このスクラップは2022/08/07にクローズされました