diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c76c0540..63d66030 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/docker-compose/cron.dockerfile b/docker-compose/cron.dockerfile deleted file mode 100644 index 4e76af25..00000000 --- a/docker-compose/cron.dockerfile +++ /dev/null @@ -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"] diff --git a/docker-compose/setup.sh b/docker-compose/setup.sh deleted file mode 100755 index a7ce3137..00000000 --- a/docker-compose/setup.sh +++ /dev/null @@ -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 diff --git a/Dockerfile b/docker/Dockerfile similarity index 66% rename from Dockerfile rename to docker/Dockerfile index 2df8e43b..7c2d9018 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/docker/cron.dockerfile b/docker/cron.dockerfile new file mode 100644 index 00000000..17245706 --- /dev/null +++ b/docker/cron.dockerfile @@ -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"] diff --git a/docker-compose/crontab b/docker/crontab similarity index 100% rename from docker-compose/crontab rename to docker/crontab diff --git a/docker-compose.yml b/docker/docker-compose.yml similarity index 64% rename from docker-compose.yml rename to docker/docker-compose.yml index b0194cf2..289c2c82 100644 --- a/docker-compose.yml +++ b/docker/docker-compose.yml @@ -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 diff --git a/docker/nginx.Dockerfile b/docker/nginx.Dockerfile new file mode 100644 index 00000000..ef1e186c --- /dev/null +++ b/docker/nginx.Dockerfile @@ -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/ diff --git a/docker-compose/nginx/nginx.conf b/docker/nginx/nginx.conf similarity index 90% rename from docker-compose/nginx/nginx.conf rename to docker/nginx/nginx.conf index d9b28d8a..ba2aa53b 100644 --- a/docker-compose/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -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; } } diff --git a/docker-compose/php/uploads.ini b/docker/php/uploads.ini similarity index 100% rename from docker-compose/php/uploads.ini rename to docker/php/uploads.ini