diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cb4b70f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +# Node.js / npm +/node_modules +/public/hot +/public/storage + +# Assets +/public/js +/public/css + +# PHP / Laravel +/bootstrap/cache/*.php +/storage/framework/views/*.php +/storage/*.key +/vendor + +# Env +.env.backup +.env.ci +.env.local +.env.backup +.env.docker.example + +# Tooling +.phpunit.result.cache +npm-debug.log +yarn-error.log + +# IDEs +/.idea +/.vscode + +# Docker +Dockerfile +docker-compose.yml diff --git a/.env.docker.example b/.env.docker.example new file mode 100644 index 0000000..c467929 --- /dev/null +++ b/.env.docker.example @@ -0,0 +1,16 @@ +APP_NAME=Cachent +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=https://cachent.test + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=database +DB_PORT=3306 +DB_DATABASE=cachent +DB_USERNAME=cachent +DB_PASSWORD=cachent diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..467d0d9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + docker: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + name: Docker + steps: + + - name: Checkout + uses: actions/checkout@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..90ee6f1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +FROM php:8.2-fpm-alpine as base + +WORKDIR /app + +# Install Docker PHP Extension Installer +COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ + +# Install required PHP extensions and tools +RUN install-php-extensions \ + bcmath \ + opcache \ + pdo_mysql \ + @composer + +# Remove cache +RUN rm -rf /var/cache/apk/* + +FROM base as composer_builder + +COPY composer.json /app/composer.json +COPY composer.lock /app/composer.lock + +RUN composer install --no-dev --no-scripts + +FROM node:18-alpine3.17 as npm_install + +WORKDIR /app + +COPY . /app + +RUN npm ci + +RUN npm run build + +FROM base as final + +WORKDIR /app + +ARG APP_VERSION +ENV APP_VERSION=${APP_VERSION} +ENV WEB_DOCUMENT_ROOT=/app/public + +COPY . /app + +COPY --from=npm_install /app/public/ /app/public +COPY --from=composer_builder /app/vendor /app/vendor + +RUN ln -s /data/torrents /app/storage/app/torrents + +RUN php artisan event:cache +RUN php artisan view:cache + +EXPOSE 9000 +CMD ["php-fpm"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7835a0e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +version: '3.9' + +services: + app: + build: + context: . + dockerfile: Dockerfile + environment: + DB_CONNECTION: ${DB_CONNECTION} + DB_HOST: ${DB_HOST} + DB_DATABASE: ${DB_DATABASE} + DB_USERNAME: ${DB_USERNAME} + DB_PASSWORD: ${DB_PASSWORD} + tty: true + ports: + - '9000:9000' + volumes: + - .:/app + networks: + - cachent + + caddy: + image: caddy:alpine + ports: + - '8000:80' + volumes: + - .:/app + - ./docker/Caddyfile:/etc/caddy/Caddyfile + networks: + - cachent + + database: + image: mariadb + environment: + MARIADB_RANDOM_ROOT_PASSWORD: true + MYSQL_DATABASE: ${DB_DATABASE} + MYSQL_USERNAME: ${DB_USERNAME} + MYSQL_PASSWORD: ${DB_PASSWORD} + volumes: + - database:/var/lib/mysql + ports: + - '3306:3306' + networks: + - cachent + +networks: + cachent: + driver: bridge + +volumes: + database: diff --git a/docker/Caddyfile b/docker/Caddyfile new file mode 100644 index 0000000..5947bdc --- /dev/null +++ b/docker/Caddyfile @@ -0,0 +1,5 @@ +:80 + +root * /app/public +php_fastcgi app:9000 +file_server