From 7e8f962db56d83acbb1989d6887cf8a7f97926f0 Mon Sep 17 00:00:00 2001 From: Kovah Date: Sun, 30 Oct 2022 14:50:35 +0100 Subject: [PATCH 01/10] Optimize Pixelfed Dockerfile, add Github Actions build --- .github/workflows/build-docker.yml | 37 ++++++++++++++++++++++++++++++ contrib/docker/Dockerfile.apache | 23 ++++++++----------- 2 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/build-docker.yml diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 000000000..9413a4e7f --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,37 @@ +--- +name: Build Docker image + +on: + push: + branches: + - dev + +jobs: + build_regular_docker: + + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ./contrib/docker/Dockerfile.apache + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: kovah/pixelfed-docker:latest diff --git a/contrib/docker/Dockerfile.apache b/contrib/docker/Dockerfile.apache index 206c86d10..c4d5c305b 100644 --- a/contrib/docker/Dockerfile.apache +++ b/contrib/docker/Dockerfile.apache @@ -1,20 +1,17 @@ -FROM php:7.4-apache-bullseye +FROM php:8.0-apache + +ENV COMPOSER_MEMORY_LIMIT=-1 +ARG DEBIAN_FRONTEND=noninteractive +WORKDIR /var/www/ # Use the default production configuration COPY contrib/docker/php.production.ini "$PHP_INI_DIR/php.ini" -# Install Composer -ENV COMPOSER_VERSION=2.1.14 \ - COMPOSER_HOME=/var/www/.composer \ - COMPOSER_MEMORY_LIMIT=-1 \ - PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" -ARG DEBIAN_FRONTEND=noninteractive -WORKDIR /var/www/ -RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer \ - && curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \ - && php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }" \ - && php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer --version=${COMPOSER_VERSION} && rm -rf /tmp/composer-setup.php \ - && apt-get update \ +# Get Composer binary +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Install package dependencies +RUN apt-get update \ && apt-get upgrade -y \ # && apt-get install -y --no-install-recommends apt-utils \ && apt-get install -y --no-install-recommends \ From 0ecb3ed960c66f30d83008db4b2d3fa5b79028e8 Mon Sep 17 00:00:00 2001 From: Kovah Date: Sun, 30 Oct 2022 16:34:54 +0100 Subject: [PATCH 02/10] Optimize build process, add Horizon publishing --- .github/workflows/build-docker.yml | 2 ++ contrib/docker/Dockerfile.apache | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 9413a4e7f..e7f96f001 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -35,3 +35,5 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: kovah/pixelfed-docker:latest + cache-from: type=registry,ref=user/app:latest + cache-to: type=inline diff --git a/contrib/docker/Dockerfile.apache b/contrib/docker/Dockerfile.apache index c4d5c305b..c0e8ca036 100644 --- a/contrib/docker/Dockerfile.apache +++ b/contrib/docker/Dockerfile.apache @@ -4,9 +4,6 @@ ENV COMPOSER_MEMORY_LIMIT=-1 ARG DEBIAN_FRONTEND=noninteractive WORKDIR /var/www/ -# Use the default production configuration -COPY contrib/docker/php.production.ini "$PHP_INI_DIR/php.ini" - # Get Composer binary COPY --from=composer:latest /usr/bin/composer /usr/bin/composer @@ -86,12 +83,18 @@ RUN apt-get update \ && rm -rf /var/cache/apt \ && rm -rf /var/lib/apt/lists/ +# Use the default production configuration +COPY contrib/docker/php.production.ini "$PHP_INI_DIR/php.ini" + COPY . /var/www/ # for detail why storage is copied this way, pls refer to https://github.com/pixelfed/pixelfed/pull/2137#discussion_r434468862 RUN cp -r storage storage.skel \ && composer install --prefer-dist --no-interaction --no-ansi --optimize-autoloader \ && rm -rf html && ln -s public html \ && chown -R www-data:www-data /var/www + +RUN php artisan horizon:publish + VOLUME /var/www/storage /var/www/bootstrap CMD ["/var/www/contrib/docker/start.apache.sh"] From cebb463654208e17801d5683c6c93fa130b8c62f Mon Sep 17 00:00:00 2001 From: Mehdi Benadel Date: Sat, 24 Dec 2022 16:22:15 +0100 Subject: [PATCH 03/10] Making this action workflow more versatile --- .github/workflows/build-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index e7f96f001..f88ba240c 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -34,6 +34,6 @@ jobs: file: ./contrib/docker/Dockerfile.apache platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: kovah/pixelfed-docker:latest + tags: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed:latest cache-from: type=registry,ref=user/app:latest cache-to: type=inline From b1ff44ca2f75c088a11576fb03b5bad2fbed4d5c Mon Sep 17 00:00:00 2001 From: Mehdi Benadel Date: Sat, 24 Dec 2022 16:32:28 +0100 Subject: [PATCH 04/10] update docker-compose --- docker-compose.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5b342f19e..6fca2eeb3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,10 +14,7 @@ services: ## App and Worker app: # Comment to use dockerhub image - build: - context: . - dockerfile: contrib/docker/Dockerfile.apache - image: pixelfed + image: pixelfed/pixelfed:latest restart: unless-stopped env_file: - .env.docker @@ -35,10 +32,7 @@ services: - redis worker: - build: - context: . - dockerfile: contrib/docker/Dockerfile.apache - image: pixelfed + image: pixelfed/pixelfed:latest restart: unless-stopped env_file: - .env.docker From 5541af4f4b7b958a12c69a54a6033e0546e7e172 Mon Sep 17 00:00:00 2001 From: Mehdi Benadel Date: Sat, 24 Dec 2022 16:44:58 +0100 Subject: [PATCH 05/10] Updating workflow --- .github/workflows/build-docker.yml | 52 +++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index f88ba240c..ad99a8aad 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -2,38 +2,68 @@ name: Build Docker image on: + workflow_dispatch: push: branches: - dev + tags: + - '*' + pull_request: + paths: + - .github/workflows/build-docker.yml + - contrib/docker/Dockerfile.apache +permissions: + contents: read jobs: - build_regular_docker: + build-docker: runs-on: ubuntu-latest steps: - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v3 + + - name: Docker Lint + uses: hadolint/hadolint-action@v3.0.0 + with: + dockerfile: contrib/docker/Dockerfile.apache + failure-threshold: error - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} + if: github.event_name != 'pull_request' + + - name: Fetch tags + uses: docker/metadata-action@v4 + id: meta + with: + images: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed + flavor: | + latest=auto + tags: | + type=edge,branch=dev + type=pep440,pattern={{raw}} + type=pep440,pattern=v{{major}}.{{minor}} + type=ref,event=pr - name: Build and push Docker image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: context: . - file: ./contrib/docker/Dockerfile.apache + file: contrib/docker/Dockerfile.apache platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: true - tags: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed:latest - cache-from: type=registry,ref=user/app:latest - cache-to: type=inline + builder: ${{ steps.buildx.outputs.name }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max From 9ad4141d3423171e674592a390061efb88543bfd Mon Sep 17 00:00:00 2001 From: Mehdi Benadel Date: Sat, 24 Dec 2022 16:48:05 +0100 Subject: [PATCH 06/10] Updating dependencies --- contrib/docker/Dockerfile.apache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/docker/Dockerfile.apache b/contrib/docker/Dockerfile.apache index c0e8ca036..5ace812e9 100644 --- a/contrib/docker/Dockerfile.apache +++ b/contrib/docker/Dockerfile.apache @@ -1,11 +1,11 @@ -FROM php:8.0-apache +FROM php:8.1-apache ENV COMPOSER_MEMORY_LIMIT=-1 ARG DEBIAN_FRONTEND=noninteractive WORKDIR /var/www/ # Get Composer binary -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +COPY --from=composer:2.4.4 /usr/bin/composer /usr/bin/composer # Install package dependencies RUN apt-get update \ From 3ec81f9e320363a7365b7d66b0a7e980262e6a0a Mon Sep 17 00:00:00 2001 From: Mehdi Benadel Date: Sat, 7 Jan 2023 22:49:22 +0100 Subject: [PATCH 07/10] Updating Dockerfile according to #3737, #3740, #3850 and #4065 --- contrib/docker/Dockerfile.apache | 6 +- contrib/docker/Dockerfile.fpm | 106 +++++++++++++++---------------- 2 files changed, 54 insertions(+), 58 deletions(-) diff --git a/contrib/docker/Dockerfile.apache b/contrib/docker/Dockerfile.apache index 5ace812e9..9c33aee17 100644 --- a/contrib/docker/Dockerfile.apache +++ b/contrib/docker/Dockerfile.apache @@ -1,4 +1,4 @@ -FROM php:8.1-apache +FROM php:8.1-apache-bullseye ENV COMPOSER_MEMORY_LIMIT=-1 ARG DEBIAN_FRONTEND=noninteractive @@ -18,8 +18,8 @@ RUN apt-get update \ git \ gosu \ zip \ - unzip \ - libzip-dev \ + unzip \ + libzip-dev \ libcurl4-openssl-dev \ ## Image Optimization optipng \ diff --git a/contrib/docker/Dockerfile.fpm b/contrib/docker/Dockerfile.fpm index 4d15f14b8..0b8e5c113 100644 --- a/contrib/docker/Dockerfile.fpm +++ b/contrib/docker/Dockerfile.fpm @@ -1,29 +1,25 @@ -FROM php:7.4-fpm-buster +FROM php:8.1-fpm-bullseye -# Use the default production configuration -COPY contrib/docker/php.production.ini "$PHP_INI_DIR/php.ini" +ENV COMPOSER_MEMORY_LIMIT=-1 +ARG DEBIAN_FRONTEND=noninteractive +WORKDIR /var/www/ -# Install Composer -ENV COMPOSER_VERSION 1.9.2 -ENV COMPOSER_HOME /var/www/.composer -RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer \ - && curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \ - && php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }" \ - && php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer --version=${COMPOSER_VERSION} && rm -rf /tmp/composer-setup.php +# Get Composer binary +COPY --from=composer:2.4.4 /usr/bin/composer /usr/bin/composer -# Update OS Packages -RUN apt-get update - -# Install OS Packages -RUN apt-get install -y --no-install-recommends apt-utils -RUN apt-get install -y --no-install-recommends \ +# Install package dependencies +RUN apt-get update \ + && apt-get upgrade -y \ +# && apt-get install -y --no-install-recommends apt-utils \ + && apt-get install -y --no-install-recommends \ ## Standard - locales locales-all \ + locales \ + locales-all \ git \ gosu \ zip \ - unzip \ - libzip-dev \ + unzip \ + libzip-dev \ libcurl4-openssl-dev \ ## Image Optimization optipng \ @@ -33,62 +29,62 @@ RUN apt-get install -y --no-install-recommends \ ## Image Processing libjpeg62-turbo-dev \ libpng-dev \ + libmagickwand-dev \ # Required for GD libxpm4 \ libxpm-dev \ libwebp6 \ libwebp-dev \ ## Video Processing - ffmpeg - -# Update Local data -RUN sed -i '/en_US/s/^#//g' /etc/locale.gen && locale-gen && update-locale - + ffmpeg \ +## Database +# libpq-dev \ +# libsqlite3-dev \ + mariadb-client \ +# Locales Update + && sed -i '/en_US/s/^#//g' /etc/locale.gen \ + && locale-gen \ + && update-locale \ # Install PHP extensions -RUN docker-php-source extract - + && docker-php-source extract \ #PHP Imagemagick extensions -RUN apt-get install -y --no-install-recommends libmagickwand-dev -RUN pecl install imagick -RUN docker-php-ext-enable imagick - + && pecl install imagick \ + && docker-php-ext-enable imagick \ # PHP GD extensions -RUN docker-php-ext-configure gd \ + && docker-php-ext-configure gd \ --with-freetype \ --with-jpeg \ --with-webp \ - --with-xpm -RUN docker-php-ext-install -j$(nproc) gd - + --with-xpm \ + && docker-php-ext-install -j$(nproc) gd \ #PHP Redis extensions -RUN pecl install redis -RUN docker-php-ext-enable redis - + && pecl install redis \ + && docker-php-ext-enable redis \ #PHP Database extensions -RUN apt-get install -y --no-install-recommends libpq-dev libsqlite3-dev -RUN docker-php-ext-install pdo_mysql pdo_pgsql pdo_sqlite - + && docker-php-ext-install pdo_mysql \ +#pdo_pgsql pdo_sqlite \ #PHP extensions (dependencies) -RUN docker-php-ext-configure intl -RUN docker-php-ext-install -j$(nproc) intl bcmath zip pcntl exif curl - + && docker-php-ext-configure intl \ + && docker-php-ext-install -j$(nproc) intl bcmath zip pcntl exif curl \ #Cleanup -RUN docker-php-source delete -RUN apt-get autoremove --purge -y -RUN rm -rf /var/cache/apt -RUN rm -rf /var/lib/apt/lists/* + && docker-php-source delete \ + && apt-get autoremove --purge -y \ + && apt-get clean \ + && rm -rf /var/cache/apt \ + && rm -rf /var/lib/apt/lists/ -ENV PATH="~/.composer/vendor/bin:./vendor/bin:${PATH}" +# Use the default production configuration +COPY contrib/docker/php.production.ini "$PHP_INI_DIR/php.ini" COPY . /var/www/ -WORKDIR /var/www/ +# for detail why storage is copied this way, pls refer to https://github.com/pixelfed/pixelfed/pull/2137#discussion_r434468862 +RUN cp -r storage storage.skel \ + && composer install --prefer-dist --no-interaction --no-ansi --optimize-autoloader \ + && rm -rf html && ln -s public html \ + && chown -R www-data:www-data /var/www -RUN cp -r storage storage.skel -RUN composer global require hirak/prestissimo --no-interaction --no-suggest --prefer-dist -RUN composer install --prefer-dist --no-interaction --no-ansi --optimize-autoloader -RUN composer global remove hirak/prestissimo -RUN rm -rf html && ln -s public html +RUN php artisan horizon:publish VOLUME /var/www/storage /var/www/bootstrap - + CMD ["/var/www/contrib/docker/start.fpm.sh"] From 48bbb6bb763fcf48cd56392ab07a18a1e5b25343 Mon Sep 17 00:00:00 2001 From: Mehdi Benadel Date: Sat, 7 Jan 2023 22:58:48 +0100 Subject: [PATCH 08/10] Adding fpm docker --- .github/workflows/build-docker.yml | 57 ++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index ad99a8aad..0898a6ef1 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -12,12 +12,12 @@ on: paths: - .github/workflows/build-docker.yml - contrib/docker/Dockerfile.apache + - contrib/docker/Dockerfile.fpm permissions: contents: read jobs: - build-docker: - + build-docker-apache: runs-on: ubuntu-latest steps: @@ -50,6 +50,7 @@ jobs: images: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed flavor: | latest=auto + suffix=apache tags: | type=edge,branch=dev type=pep440,pattern={{raw}} @@ -67,3 +68,55 @@ jobs: tags: ${{ steps.meta.outputs.tags }} cache-from: type=gha cache-to: type=gha,mode=max + + build-docker-fpm: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Docker Lint + uses: hadolint/hadolint-action@v3.0.0 + with: + dockerfile: contrib/docker/Dockerfile.fpm + failure-threshold: error + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + if: github.event_name != 'pull_request' + + - name: Fetch tags + uses: docker/metadata-action@v4 + id: meta + with: + images: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed + flavor: | + latest=auto + suffix=fpm + tags: | + type=edge,branch=dev + type=pep440,pattern={{raw}} + type=pep440,pattern=v{{major}}.{{minor}} + type=ref,event=pr + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + file: contrib/docker/Dockerfile.fpm + platforms: linux/amd64,linux/arm64,linux/arm/v7 + builder: ${{ steps.buildx.outputs.name }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max From e0f9697c4fd946766ca124ce7f4aacf862bfdad5 Mon Sep 17 00:00:00 2001 From: Mehdi Benadel Date: Sat, 7 Jan 2023 23:57:36 +0100 Subject: [PATCH 09/10] fix image tags --- .github/workflows/build-docker.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 0898a6ef1..54692e52b 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -50,7 +50,7 @@ jobs: images: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed flavor: | latest=auto - suffix=apache + suffix=-apache tags: | type=edge,branch=dev type=pep440,pattern={{raw}} @@ -101,8 +101,7 @@ jobs: with: images: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed flavor: | - latest=auto - suffix=fpm + suffix=-fpm tags: | type=edge,branch=dev type=pep440,pattern={{raw}} From 5c761dd2fb0693a9418fae9f5d5b7ec579d57db1 Mon Sep 17 00:00:00 2001 From: Mehdi Benadel Date: Sun, 8 Jan 2023 08:01:06 +0100 Subject: [PATCH 10/10] Stop building for armv7 --- .github/workflows/build-docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 54692e52b..f4cca19ea 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -62,7 +62,7 @@ jobs: with: context: . file: contrib/docker/Dockerfile.apache - platforms: linux/amd64,linux/arm64,linux/arm/v7 + platforms: linux/amd64,linux/arm64 builder: ${{ steps.buildx.outputs.name }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} @@ -113,7 +113,7 @@ jobs: with: context: . file: contrib/docker/Dockerfile.fpm - platforms: linux/amd64,linux/arm64,linux/arm/v7 + platforms: linux/amd64,linux/arm64 builder: ${{ steps.buildx.outputs.name }} push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }}