-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Speed up Docker build and fix entrypoint permissions #894
base: main
Are you sure you want to change the base?
Changes from 3 commits
ac6739c
84c2bb5
c57a0fe
0c59e3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
# Pelican Production Dockerfile | ||
|
||
FROM node:20-alpine AS yarn | ||
#FROM --platform=$TARGETOS/$TARGETARCH node:20-alpine AS yarn | ||
|
||
WORKDIR /build | ||
|
||
COPY . ./ | ||
|
||
RUN yarn config set network-timeout 300000 \ | ||
&& yarn install --frozen-lockfile \ | ||
&& yarn run build:production | ||
|
||
FROM php:8.3-fpm-alpine | ||
# FROM --platform=$TARGETOS/$TARGETARCH php:8.3-fpm-alpine | ||
|
||
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer | ||
|
||
WORKDIR /var/www/html | ||
|
||
RUN touch .env | ||
|
||
# Install dependencies | ||
RUN apk update && apk add --no-cache \ | ||
libpng-dev libjpeg-turbo-dev freetype-dev libzip-dev icu-dev \ | ||
zip unzip curl \ | ||
caddy ca-certificates supervisor \ | ||
&& docker-php-ext-install bcmath gd intl zip opcache pcntl posix pdo_mysql | ||
|
||
# Copy the Caddyfile to the container | ||
COPY Caddyfile /etc/caddy/Caddyfile | ||
# Install dependencies with Composer | ||
COPY composer.json composer.lock ./ | ||
COPY app/helpers.php ./app/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely confuses me even more. Definitely don't want to reference this file anywhere in Docker. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These 3 files are the bare minimum required to run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the reason behind splitting the install and build up like this is just optimizing for build caching. By only copying the dependency lists first, those first layers only need to rerun when the dependencies change. Then the entire codebase is copied as late as possible to minimize needlessly rerunning. GitHub actions can also be configured to utilize caching (although I didn't do that in this PR), which, with these changes, should help speed up the builds a bit. Although this doesn't have as big of an impact anymore because of the Vite frontend rewrite. The majority of the build time is now taken up by |
||
|
||
# Copy the application code to the container | ||
COPY . . | ||
RUN composer install --no-dev --optimize-autoloader | ||
|
||
COPY --from=yarn /build/public/assets ./public/assets | ||
# Install dependencies with Composer | ||
COPY package.json yarn.lock ./ | ||
RUN apk add --no-cache yarn | ||
RUN yarn config set network-timeout 300000 \ | ||
&& yarn install --frozen-lockfile | ||
|
||
RUN touch .env | ||
# Copy the application code to the container | ||
COPY . . | ||
|
||
RUN composer install --no-dev --optimize-autoloader | ||
# Yarn build | ||
RUN yarn run build | ||
|
||
# Set file permissions | ||
RUN chmod -R 755 storage bootstrap/cache \ | ||
|
@@ -44,12 +41,15 @@ RUN chmod -R 755 storage bootstrap/cache \ | |
# Add scheduler to cron | ||
RUN echo "* * * * * php /var/www/html/artisan schedule:run >> /dev/null 2>&1" | crontab -u www-data - | ||
|
||
# Copy the Caddyfile to the container | ||
COPY Caddyfile /etc/caddy/Caddyfile | ||
|
||
## supervisord config and log dir | ||
RUN cp .github/docker/supervisord.conf /etc/supervisord.conf && \ | ||
mkdir /var/log/supervisord/ | ||
|
||
HEALTHCHECK --interval=5m --timeout=10s --start-period=5s --retries=3 \ | ||
CMD curl -f http://localhost/up || exit 1 | ||
CMD curl -f http://localhost/up || exit 1 | ||
|
||
EXPOSE 80 443 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ x-common: | |
services: | ||
panel: | ||
image: ghcr.io/pelican-dev/panel:latest | ||
build: | ||
dockerfile: ./Dockerfile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this assumed by default, does this change anything? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I just tested, and docker compose build or docker compose run --build will only build images with a build section specified. Although I realized |
||
restart: always | ||
networks: | ||
- default | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confused why this is necessary when we do the copy below?