Refactor CI, Build docker on push

This commit is contained in:
gdarko
2024-01-29 11:20:11 +01:00
parent 9676924047
commit 613d6c2cb2
10 changed files with 113 additions and 66 deletions

View File

@@ -1,37 +1,86 @@
name: CI
on: [push, pull_request]
on:
push:
branches:
- master
tags:
- "*"
pull_request:
branches: [ master ]
env:
INVOICESHELF_VERSION: 1.0.0
jobs:
build-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0']
build-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2']
name: PHP ${{ matrix.php }}
name: PHP ${{ matrix.php }}
steps:
- name: Checkout
uses: actions/checkout@v2
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: exif
- name: Install dependencies
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: exif
- name: Install PHP 7 dependencies
run: composer update --no-interaction --no-progress
if: "matrix.php < 8"
- name: Install PHP dependencies
run: composer update --ignore-platform-req=php --no-interaction --no-progress
- name: Install PHP 8 dependencies
run: composer update --ignore-platform-req=php --no-interaction --no-progress
if: "matrix.php >= 8"
- name: Check coding style
run: ./vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no --config=.php-cs-fixer.dist.php
- name: Check coding style
run: ./vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no --config=.php-cs-fixer.dist.php
- name: Unit Tests
run: php ./vendor/bin/pest
- name: Unit Tests
run: php ./vendor/bin/pest
docker:
if: ${{ needs.build-test.result == 'success' && github.event_name != 'pull_request'}}
name: Docker build and publish
runs-on: ubuntu-latest
needs:
- build-test
steps:
- name: derive version tag
run: |
if [[ "${{ github.ref }}" =~ ^refs/tags* ]]; then
GITHUB_TAG=${GITHUB_REF#refs/tags/}
echo "running for a release $GITHUB_TAG"
if [ "$GITHUB_TAG" != "${{ env.INVOICESHELF_VERSION }}" ]; then
echo "tag $GITHUB_TAG pushed does not match with INVOICESHELF_VERSION ${{ env.INVOICESHELF_VERSION }} in .github/worlflows/ci. Please push correct release tag"
exit 1
fi
echo "VERSION_TAG=${{ env.INVOICESHELF_VERSION }}" >> $GITHUB_ENV
else
echo "running for a master commit"
if [ $(git tag -l ${{ env.INVOICESHELF_VERSION }}) ]; then
echo "Version ${{ env.INVOICESHELF_VERSION }} already released. Please update your version in .github/worlflows/ci"
exit 1
fi
echo "VERSION_TAG=${{ env.INVOICESHELF_VERSION }}-${{ github.run_number }}" >> $GITHUB_ENV
fi
- name: Checkout
uses: actions/checkout@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Docker Build and push invoiceshelf-php
uses: docker/build-push-action@v2
with:
context: .
file: docker/Dockerfile
push: true
tags: invoiceshelf/invoiceshelf-php:${{env.VERSION_TAG}},invoiceshelf/invoiceshelf-php:latest
- name: Docker Build and push invoiceshelf-nginx
uses: docker/build-push-action@v2
with:
context: .
file: docker/nginx.Dockerfile
push: true
tags: invoiceshelf/invoiceshelf-nginx:${{env.VERSION_TAG}},invoiceshelf/invoiceshelf-nginx:latest

View File

@@ -1,10 +0,0 @@
FROM php:8.1-fpm-bookworm
RUN apt update && apt install -y cron
RUN docker-php-ext-install pdo pdo_mysql bcmath
COPY docker-compose/crontab /etc/crontabs/root
RUN crontab /etc/crontabs/root
CMD ["/usr/sbin/cron", "-f"]

View File

@@ -1,6 +0,0 @@
#!/bin/sh
docker-compose exec app composer install --no-interaction --prefer-dist --optimize-autoloader
docker-compose exec app php artisan storage:link || true
docker-compose exec app php artisan key:generate

View File

@@ -1,14 +1,12 @@
FROM php:8.1-fpm-bookworm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
ENV user=invoiceshelf-user
ENV uid=1000
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
nano \
libpng-dev \
libonig-dev \
libxml2-dev \
@@ -16,6 +14,7 @@ RUN apt-get update && apt-get install -y \
unzip \
libzip-dev \
libmagickwand-dev \
nano \
mariadb-client
# Clear cache
@@ -35,7 +34,18 @@ RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
COPY . /var/www/
COPY docker/php/uploads.ini /usr/local/etc/php/conf.d/uploads.ini
RUN cp /var/www/.env.example /var/www/.env
RUN chown -R $user:$user /var/www/
RUN chmod -R 775 /var/www/storage
RUN chmod -R 775 /var/www/bootstrap
# Set working directory
WORKDIR /var/www
RUN composer install --no-interaction --prefer-dist --optimize-autoloader
RUN php artisan key:generate
RUN php artisan storage:link || true
USER $user

10
docker/cron.dockerfile Normal file
View File

@@ -0,0 +1,10 @@
FROM php:8.1-fpm-alpine
RUN apk add --no-cache \
php81-bcmath
RUN docker-php-ext-install pdo pdo_mysql bcmath
COPY /docker/crontab /etc/crontabs/root
CMD ["crond", "-f"]

View File

@@ -2,18 +2,9 @@ version: '3'
services:
app:
build:
args:
user: invoiceshelf-user
uid: 1000
context: ./
dockerfile: Dockerfile
image: invoiceshelf-php
image: invoiceshelf/invoiceshelf-php
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
- ./docker-compose/php/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini:rw,delegated
networks:
- invoiceshelf
@@ -36,22 +27,20 @@ services:
- invoiceshelf
nginx:
image: nginx:1.17-alpine
image: invoiceshelf/invoiceshelf-nginx
restart: unless-stopped
ports:
- 80:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- invoiceshelf
cron:
build:
context: ./
dockerfile: ./docker-compose/cron.dockerfile
context: ../
dockerfile: docker/cron.dockerfile
image: invoiceshelf-cron
volumes:
- ./:/var/www
- ../:/var/www
networks:
- invoiceshelf

5
docker/nginx.Dockerfile Normal file
View File

@@ -0,0 +1,5 @@
FROM nginx:1.20-alpine
COPY docker/nginx /etc/nginx/conf.d/
RUN rm /etc/nginx/conf.d/default.conf
COPY public/ /var/www/public/

View File

@@ -16,7 +16,7 @@ server {
fastcgi_read_timeout 300;
}
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}