From 16aafdf01312ece303a8eb9a2ebfcd592f4c2301 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Sun, 8 Dec 2024 13:01:59 +0100 Subject: [PATCH 1/6] Moved Dockerfile to root, added source code and running composer --- bin/api-ws/Dockerfile => Dockerfile | 6 ++++++ docker-compose.yml | 2 +- edgebox-compose.yml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) rename bin/api-ws/Dockerfile => Dockerfile (90%) diff --git a/bin/api-ws/Dockerfile b/Dockerfile similarity index 90% rename from bin/api-ws/Dockerfile rename to Dockerfile index b963a11..ae876a4 100755 --- a/bin/api-ws/Dockerfile +++ b/Dockerfile @@ -53,5 +53,11 @@ RUN docker-php-ext-install \ # Layering Composer binary COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer +# Add Source Code +COPY ./src /var/www/html + +# Install Composer Dependencies +RUN composer install --no-dev --optimize-autoloader + # Cleanup RUN rm -rf /usr/src/* diff --git a/docker-compose.yml b/docker-compose.yml index 06aeb79..8fdaf07 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: "3" services: api-ws: build: - context: ./bin/api-ws + context: ./ restart: 'always' ports: - "${HOST_MACHINE_UNSECURE_HOST_PORT}:80" diff --git a/edgebox-compose.yml b/edgebox-compose.yml index af93ec8..f75fb31 100644 --- a/edgebox-compose.yml +++ b/edgebox-compose.yml @@ -6,7 +6,7 @@ services: api-ws: # image: ghcr.io/edgebox-iot/api:latest build: - context: ../api/bin/api-ws + context: ./ container_name: '${COMPOSE_PROJECT_NAME}-api-ws' restart: always volumes: From 59b3c2346beba10d6b12515eaa50c1f7fa6df20b Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Sun, 8 Dec 2024 13:11:05 +0100 Subject: [PATCH 2/6] Edited references for build-push, added dockerfile build step to PR ci --- .github/workflows/build-push.yml | 2 +- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ README.md | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 2ea3558..470ede1 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -39,7 +39,7 @@ jobs: name: Build and push uses: docker/build-push-action@v5 with: - context: ./bin/api-ws/ + context: ./ platforms: linux/amd64,linux/arm/v7,linux/arm64 push: true tags: ${{ env.REGISTRY_IMAGE_TAG }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3357a1..40b5efd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,28 @@ name: CI on: [push] jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: ./ + platforms: linux/amd64,linux/arm/v7,linux/arm64 + push: false + # tags: ghcr.io/edgebox-iot/api:${{ github.ref_name }},ghcr.io/edgebox-iot/api:latest test: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 8c4755c..955da99 100755 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ By default following extensions are installed. * xmlrpc * gd -> If you want to install more extensions, just update `./bin/api-ws/Dockerfile`. You can also generate a PR and it will be merged if it seems good for general purpose. +> If you want to install more extensions, just update `./Dockerfile`. You can also generate a PR and it will be merged if it seems good for general purpose. > You have to rebuild the docker image by running `docker-compose build` and restart the docker containers. ## phpMyAdmin From 7365d17af85e7b2c2f8400bfd5bd35384bc45235 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Sun, 8 Dec 2024 13:15:50 +0100 Subject: [PATCH 3/6] Added APP_ENV as prod to image build --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index ae876a4..38067da 100755 --- a/Dockerfile +++ b/Dockerfile @@ -56,6 +56,8 @@ COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer # Add Source Code COPY ./src /var/www/html +ENV APP_ENV=prod + # Install Composer Dependencies RUN composer install --no-dev --optimize-autoloader From cf28ce1fb74d33a272e3a739b11facd7f3e6e2a7 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Sun, 8 Dec 2024 17:24:26 +0100 Subject: [PATCH 4/6] Layered Dockerfile and removed armv7 from build step on github actions --- .github/workflows/ci.yml | 2 +- Dockerfile | 40 ++++++++++++++++++---------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40b5efd..a266384 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: uses: docker/build-push-action@v5 with: context: ./ - platforms: linux/amd64,linux/arm/v7,linux/arm64 + platforms: linux/amd64,linux/arm64 push: false # tags: ghcr.io/edgebox-iot/api:${{ github.ref_name }},ghcr.io/edgebox-iot/api:latest test: diff --git a/Dockerfile b/Dockerfile index 38067da..4da36fe 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.1-apache-buster +FROM php:8.1-apache as php-base ARG DEBIAN_FRONTEND=noninteractive @@ -22,22 +22,17 @@ RUN apt-get -y update --fix-missing \ libfreetype6-dev \ libjpeg62-turbo-dev \ libpng-dev \ - && rm -rf /var/lib/apt/lists/* - - # Additional packages that might be removed - # libmagickwand-dev \ - -# Install PHP Extensions -RUN docker-php-ext-install \ - pdo_sqlite \ - mysqli \ - curl \ - zip \ - intl \ - mbstring \ - gettext \ - exif \ - gd + && rm -rf /var/lib/apt/lists/* \ + && docker-php-ext-install \ + pdo_sqlite \ + mysqli \ + curl \ + zip \ + intl \ + mbstring \ + gettext \ + exif \ + gd # Install additional PHP Extensions # RUN pecl install xdebug-3.2.0 \ @@ -47,19 +42,20 @@ RUN docker-php-ext-install \ # && pecl install imagick \ # && docker-php-ext-enable imagick -# Enable apache modules -# RUN a2enmod rewrite headers +FROM php-base as final -# Layering Composer binary COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer +COPY ./src/composer.json ./src/composer.lock ./ -# Add Source Code +# Copy application code (most frequently changed) COPY ./src /var/www/html ENV APP_ENV=prod -# Install Composer Dependencies RUN composer install --no-dev --optimize-autoloader # Cleanup RUN rm -rf /usr/src/* + +# Configure apache if needed +# RUN a2enmod rewrite headers \ No newline at end of file From 019c2f1b44d3fa4ca328af4b8f8ff6bf37ec346d Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Sun, 8 Dec 2024 17:28:07 +0100 Subject: [PATCH 5/6] Removing uneeded comments --- Dockerfile | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4da36fe..26a2b62 100755 --- a/Dockerfile +++ b/Dockerfile @@ -34,7 +34,7 @@ RUN apt-get -y update --fix-missing \ exif \ gd -# Install additional PHP Extensions +# To Install additional PHP Extensions you can also use pecl # RUN pecl install xdebug-3.2.0 \ # && docker-php-ext-enable xdebug \ # && pecl install redis-5.3.3 \ @@ -47,15 +47,10 @@ FROM php-base as final COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer COPY ./src/composer.json ./src/composer.lock ./ -# Copy application code (most frequently changed) COPY ./src /var/www/html ENV APP_ENV=prod RUN composer install --no-dev --optimize-autoloader -# Cleanup -RUN rm -rf /usr/src/* - -# Configure apache if needed -# RUN a2enmod rewrite headers \ No newline at end of file +RUN rm -rf /usr/src/* \ No newline at end of file From e4960e4084d8b76d30f8da3d9b9626c759d0fbd7 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Sun, 8 Dec 2024 17:31:58 +0100 Subject: [PATCH 6/6] Added changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c24825..98e623d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## [1.3.1] - Unreleased * Fixed linting and code style issues across the project +* Added action to build docker image on push to Pull Requests +* Optimized the Dockerfile build to include the app and dependencies in different layers ## [1.3.0] - 05-12-2020