Skip to content

Commit

Permalink
Add source code and composer dependencies to image build (#79)
Browse files Browse the repository at this point in the history
* Moved Dockerfile to root, added source code and running composer

* Edited references for build-push, added dockerfile build step to PR ci

* Added APP_ENV as prod to image build

* Layered Dockerfile and removed armv7 from build step on github actions

* Removing uneeded comments

* Added changelog entry
  • Loading branch information
paulotruta authored Dec 8, 2024
1 parent b194792 commit f9c728d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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/arm64
push: false
# tags: ghcr.io/edgebox-iot/api:${{ github.ref_name }},ghcr.io/edgebox-iot/api:latest
test:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
47 changes: 23 additions & 24 deletions bin/api-ws/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.1-apache-buster
FROM php:8.1-apache as php-base

ARG DEBIAN_FRONTEND=noninteractive

Expand All @@ -22,36 +22,35 @@ 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

# Install additional PHP Extensions
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install \
pdo_sqlite \
mysqli \
curl \
zip \
intl \
mbstring \
gettext \
exif \
gd

# 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 \
# && docker-php-ext-enable redis \
# && 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 ./

COPY ./src /var/www/html

ENV APP_ENV=prod

RUN composer install --no-dev --optimize-autoloader

# Cleanup
RUN rm -rf /usr/src/*
RUN rm -rf /usr/src/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3"
services:
api-ws:
build:
context: ./bin/api-ws
context: ./
restart: 'always'
ports:
- "${HOST_MACHINE_UNSECURE_HOST_PORT}:80"
Expand Down
2 changes: 1 addition & 1 deletion edgebox-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f9c728d

Please sign in to comment.