mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-19 19:24:03 +00:00
Refactor CI, Build docker on push
This commit is contained in:
105
.github/workflows/ci.yaml
vendored
105
.github/workflows/ci.yaml
vendored
@@ -1,37 +1,86 @@
|
|||||||
name: CI
|
name: CI
|
||||||
|
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
env:
|
||||||
|
INVOICESHELF_VERSION: 1.0.0
|
||||||
jobs:
|
jobs:
|
||||||
build-test:
|
build-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
php: ['7.4', '8.0']
|
php: ['8.1', '8.2']
|
||||||
|
|
||||||
name: PHP ${{ matrix.php }}
|
name: PHP ${{ matrix.php }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php }}
|
php-version: ${{ matrix.php }}
|
||||||
extensions: exif
|
extensions: exif
|
||||||
|
|
||||||
- name: Install PHP 7 dependencies
|
- name: Install PHP dependencies
|
||||||
run: composer update --no-interaction --no-progress
|
run: composer update --ignore-platform-req=php --no-interaction --no-progress
|
||||||
if: "matrix.php < 8"
|
|
||||||
|
|
||||||
- name: Install PHP 8 dependencies
|
- name: Check coding style
|
||||||
run: composer update --ignore-platform-req=php --no-interaction --no-progress
|
run: ./vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no --config=.php-cs-fixer.dist.php
|
||||||
if: "matrix.php >= 8"
|
|
||||||
|
|
||||||
- name: Check coding style
|
- name: Unit Tests
|
||||||
run: ./vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no --config=.php-cs-fixer.dist.php
|
run: php ./vendor/bin/pest
|
||||||
|
docker:
|
||||||
- name: Unit Tests
|
if: ${{ needs.build-test.result == 'success' && github.event_name != 'pull_request'}}
|
||||||
run: php ./vendor/bin/pest
|
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
|
||||||
|
|||||||
@@ -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"]
|
|
||||||
@@ -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
|
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
FROM php:8.1-fpm-bookworm
|
FROM php:8.1-fpm-bookworm
|
||||||
|
|
||||||
# Arguments defined in docker-compose.yml
|
ENV user=invoiceshelf-user
|
||||||
ARG user
|
ENV uid=1000
|
||||||
ARG uid
|
|
||||||
|
|
||||||
# Install system dependencies
|
# Install system dependencies
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
git \
|
git \
|
||||||
curl \
|
curl \
|
||||||
nano \
|
|
||||||
libpng-dev \
|
libpng-dev \
|
||||||
libonig-dev \
|
libonig-dev \
|
||||||
libxml2-dev \
|
libxml2-dev \
|
||||||
@@ -16,6 +14,7 @@ RUN apt-get update && apt-get install -y \
|
|||||||
unzip \
|
unzip \
|
||||||
libzip-dev \
|
libzip-dev \
|
||||||
libmagickwand-dev \
|
libmagickwand-dev \
|
||||||
|
nano \
|
||||||
mariadb-client
|
mariadb-client
|
||||||
|
|
||||||
# Clear cache
|
# Clear cache
|
||||||
@@ -35,7 +34,18 @@ RUN useradd -G www-data,root -u $uid -d /home/$user $user
|
|||||||
RUN mkdir -p /home/$user/.composer && \
|
RUN mkdir -p /home/$user/.composer && \
|
||||||
chown -R $user:$user /home/$user
|
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
|
# Set working directory
|
||||||
WORKDIR /var/www
|
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
|
USER $user
|
||||||
10
docker/cron.dockerfile
Normal file
10
docker/cron.dockerfile
Normal 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"]
|
||||||
@@ -2,18 +2,9 @@ version: '3'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
build:
|
image: invoiceshelf/invoiceshelf-php
|
||||||
args:
|
|
||||||
user: invoiceshelf-user
|
|
||||||
uid: 1000
|
|
||||||
context: ./
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: invoiceshelf-php
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
working_dir: /var/www/
|
working_dir: /var/www/
|
||||||
volumes:
|
|
||||||
- ./:/var/www
|
|
||||||
- ./docker-compose/php/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini:rw,delegated
|
|
||||||
networks:
|
networks:
|
||||||
- invoiceshelf
|
- invoiceshelf
|
||||||
|
|
||||||
@@ -36,22 +27,20 @@ services:
|
|||||||
- invoiceshelf
|
- invoiceshelf
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx:1.17-alpine
|
image: invoiceshelf/invoiceshelf-nginx
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
volumes:
|
|
||||||
- ./:/var/www
|
|
||||||
- ./docker-compose/nginx:/etc/nginx/conf.d/
|
|
||||||
networks:
|
networks:
|
||||||
- invoiceshelf
|
- invoiceshelf
|
||||||
|
|
||||||
cron:
|
cron:
|
||||||
build:
|
build:
|
||||||
context: ./
|
context: ../
|
||||||
dockerfile: ./docker-compose/cron.dockerfile
|
dockerfile: docker/cron.dockerfile
|
||||||
|
image: invoiceshelf-cron
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/var/www
|
- ../:/var/www
|
||||||
networks:
|
networks:
|
||||||
- invoiceshelf
|
- invoiceshelf
|
||||||
|
|
||||||
5
docker/nginx.Dockerfile
Normal file
5
docker/nginx.Dockerfile
Normal 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/
|
||||||
@@ -16,7 +16,7 @@ server {
|
|||||||
fastcgi_read_timeout 300;
|
fastcgi_read_timeout 300;
|
||||||
}
|
}
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.php$is_args$query_string;
|
try_files $uri $uri/ /index.php?$query_string;
|
||||||
gzip_static on;
|
gzip_static on;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user