Skip to content

Commit 2a17794

Browse files
committed
add Dockerfile and build workflow
1 parent 1eeb9b9 commit 2a17794

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

.github/workflows/docker-build.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# Standard Docker build and push workflow
3+
# https://github.com/marketplace/actions/build-and-push-docker-images
4+
5+
name: docker-build
6+
7+
env:
8+
IMAGE_NAME: "drupal-postgres"
9+
10+
on:
11+
push:
12+
branches:
13+
- 'main'
14+
15+
jobs:
16+
docker-build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Login to Docker Hub
23+
uses: docker/login-action@v3
24+
with:
25+
username: ${{ secrets.DOCKERHUB_USERNAME }}
26+
password: ${{ secrets.DOCKERHUB_TOKEN }}
27+
28+
- name: Build and push
29+
uses: docker/build-push-action@v5
30+
with:
31+
push: true
32+
tags: "${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ github.run_number }}"

Dockerfile

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Start from the original Drupal image
2+
FROM drupal:10.2.6-php8.2-apache-bookworm
3+
# Set working directory to root of drupal project set in base image
4+
WORKDIR /opt/drupal
5+
# Install drush and any additional Drupal extensions using Composer
6+
# drush https://www.drupal.org/docs/develop/development-tools/drush
7+
RUN composer require 'drush/drush'
8+
# Add volumes for the Drupal installation and files directories
9+
VOLUME ["/var/www/html/modules", "/var/www/html/profiles", "/var/www/html/themes", "/var/www/html/sites"]
10+
# Enable output buffering in PHP
11+
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
12+
&& echo "output_buffering = On" >> /usr/local/etc/php/php.ini
13+
# Install the APCu extension
14+
RUN pecl install apcu \
15+
&& docker-php-ext-enable apcu
16+
# Configure APCu
17+
RUN echo "apc.enabled=1" >> /usr/local/etc/php/php.ini \
18+
&& echo "apc.shm_size=256M" >> /usr/local/etc/php/php.ini \
19+
&& echo "apc.ttl=7200" >> /usr/local/etc/php/php.ini \
20+
&& echo "apc.enable_cli=0" >> /usr/local/etc/php/php.ini
21+
# Copy default.settings.php to settings.php
22+
RUN cp /var/www/html/sites/default/default.settings.php /var/www/html/sites/default/settings.php
23+
# Append database configuration to settings.php
24+
# Append hash salt to settings.php
25+
# Append configuration sync directory to settings.php
26+
RUN echo "\$databases['default']['default'] = array (" >> /var/www/html/sites/default/settings.php && \
27+
echo " 'database' => getenv('POSTGRES_DB')," >> /var/www/html/sites/default/settings.php && \
28+
echo " 'username' => getenv('POSTGRES_USER')," >> /var/www/html/sites/default/settings.php && \
29+
echo " 'password' => getenv('POSTGRES_PASSWORD')," >> /var/www/html/sites/default/settings.php && \
30+
echo " 'prefix' => ''," >> /var/www/html/sites/default/settings.php && \
31+
echo " 'host' => getenv('POSTGRES_HOST')," >> /var/www/html/sites/default/settings.php && \
32+
echo " 'port' => '5432'," >> /var/www/html/sites/default/settings.php && \
33+
echo " 'driver' => 'pgsql'," >> /var/www/html/sites/default/settings.php && \
34+
echo " 'namespace' => 'Drupal\\\\\\\\pgsql\\\\\\\\Driver\\\\\\\\Database\\\\\\\\pgsql'," >> /var/www/html/sites/default/settings.php && \
35+
echo " 'autoload' => 'core/modules/pgsql/src/Driver/Database/pgsql/'," >> /var/www/html/sites/default/settings.php && \
36+
echo ");" >> /var/www/html/sites/default/settings.php && \
37+
echo "\$settings['hash_salt'] = getenv('DRUPAL_HASH_SALT');" >> /var/www/html/sites/default/settings.php && \
38+
echo "\$config_directories['sync'] = getenv('DRUPAL_CONFIG_SYNC_DIRECTORY');" >> /var/www/html/sites/default/settings.php
39+
# Set file permissions
40+
RUN chown -R www-data:www-data /var/www/html/sites/default/settings.php && \
41+
chmod 644 /var/www/html/sites/default/settings.php
42+
# Docs
43+
LABEL description="Single Dockerfile build of Drupal with drush and defaulted settings including Postgres"
44+
LABEL version="1.0"

0 commit comments

Comments
 (0)