diff --git a/.dockerignore b/.dockerignore index 21edee14..cffa2348 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,5 @@ .git .gitignore .gitattributes +node_modules +vendor diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 00000000..e1125e6c --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,64 @@ +name: Build container image + +on: push + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/metadata-action@v5 + id: meta_foundation + with: + images: ghcr.io/tissue-foundation + + - uses: docker/build-push-action@v5 + with: + push: true + context: . + file: ./docker/production/foundation.dockerfile + tags: ${{ steps.meta_foundation.outputs.tags }} + labels: ${{ steps.meta_foundation.outputs.labels }} + + - uses: docker/metadata-action@v5 + id: meta_nginx + with: + images: ghcr.io/tissue-nginx + + - uses: docker/build-push-action@v5 + with: + push: true + context: . + file: ./docker/production/nginx.dockerfile + tags: ${{ steps.meta_nginx.outputs.tags }} + labels: ${{ steps.meta_nginx.outputs.labels }} + build-args: | + TISSUE_FOUNDATION_IMAGE_NAME=${{ steps.meta_foundation.outputs.tags }} + + - uses: docker/metadata-action@v5 + id: meta_php + with: + images: ghcr.io/tissue-php + + - uses: docker/build-push-action@v5 + with: + push: true + context: . + file: ./docker/production/php.dockerfile + tags: ${{ steps.meta_php.outputs.tags }} + labels: ${{ steps.meta_php.outputs.labels }} + build-args: | + TISSUE_FOUNDATION_IMAGE_NAME=${{ steps.meta_foundation.outputs.tags }} diff --git a/docker/production/compose.yaml b/docker/production/compose.yaml new file mode 100644 index 00000000..df46b9b0 --- /dev/null +++ b/docker/production/compose.yaml @@ -0,0 +1,12 @@ +services: + php: + image: shibafu528/tissue-php + env_file: .env + nginx: + image: shibafu528/tissue-nginx + environment: + PHP_APP_HOST: php + ports: + - 4519:80 + depends_on: + - php diff --git a/docker/production/default.conf.template b/docker/production/default.conf.template new file mode 100644 index 00000000..fa16d2f3 --- /dev/null +++ b/docker/production/default.conf.template @@ -0,0 +1,18 @@ +server { + listen 80; + server_name _; + + root /app/public; + index index.php index.html; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + fastcgi_pass ${PHP_APP_HOST}:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} diff --git a/docker/production/foundation.dockerfile b/docker/production/foundation.dockerfile new file mode 100644 index 00000000..b62aaee0 --- /dev/null +++ b/docker/production/foundation.dockerfile @@ -0,0 +1,22 @@ +FROM php:8.0.30-cli-bullseye as php + +RUN apt-get update \ + && apt-get install -y git libpq-dev unzip libicu-dev \ + && docker-php-ext-install pdo_pgsql intl \ + && curl -sS https://getcomposer.org/installer | php \ + && mv composer.phar /usr/local/bin/composer \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app +COPY . /app + +RUN composer install -n --no-dev --prefer-dist --optimize-autoloader + +FROM node:16.20.2-bullseye + +WORKDIR /app +COPY --from=php /app /app + +RUN yarn install \ + && yarn run prod \ + && yarn run doc diff --git a/docker/production/nginx.dockerfile b/docker/production/nginx.dockerfile new file mode 100644 index 00000000..6833f38d --- /dev/null +++ b/docker/production/nginx.dockerfile @@ -0,0 +1,9 @@ +ARG TISSUE_FOUNDATION_IMAGE_NAME + +FROM ${TISSUE_FOUNDATION_IMAGE_NAME} as foundation + +FROM nginx:alpine + +COPY ./docker/production/default.conf.template /etc/nginx/templates/ + +COPY --from=foundation /app/public /app/public diff --git a/docker/production/php.dockerfile b/docker/production/php.dockerfile new file mode 100644 index 00000000..cf106590 --- /dev/null +++ b/docker/production/php.dockerfile @@ -0,0 +1,15 @@ +ARG TISSUE_FOUNDATION_IMAGE_NAME + +FROM ${TISSUE_FOUNDATION_IMAGE_NAME} as foundation + +FROM php:8.0.30-fpm-bullseye + +RUN apt-get update \ + && apt-get install -y --no-install-recommends libpq-dev libicu-dev \ + && docker-php-ext-install pdo_pgsql intl \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=foundation --chown=www-data:www-data /app /app + +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" +