Skip to content

Commit

Permalink
New package for core/drupal
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Adams <[email protected]>
  • Loading branch information
Paul Adams committed May 19, 2017
1 parent c21711b commit c9f9303
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 0 deletions.
38 changes: 38 additions & 0 deletions drupal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Habitat Package: Crate
The Habitat Maintainers <[email protected]>

## Description

- [www](https://www.drupal.org)
- [Docs](https://www.drupal.org/documentation/

> Drupal is content management software. It's used to make many of the
> websites and applications you use every day.
Drupal has great standard features, like easy content authoring,
reliable performance, and excellent security. But what sets it apart
is its flexibility; modularity is one of its core principles. Its
tools help you build the versatile, structured content that dynamic
web experiences need.

## Usage

### Starting

```
hab start core/drupal --bind database:<database service group> --peer <ip of database service group supervisor>
```

### Stopping

```
hab sup stop core/nginx
hab sup stop core/drupal
```

By default, Drupal will be available on port 80.

### Notes

- This package requires a running instance of `core/mysql` to bind to.
- After starting the service the user is provided with a new Drupal site with preconfigured admin username and password.
107 changes: 107 additions & 0 deletions drupal/config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
worker_processes {{cfg.nginx.worker_processes}};
daemon off;
pid {{pkg.svc_var_path}}/nginx.pid;

events {
worker_connections {{cfg.nginx.events.worker_connections}};
}

http {
include mime.types;
default_type application/octet-stream;

sendfile {{cfg.nginx.http.sendfile}};
tcp_nopush {{cfg.nginx.http.tcp_nopush}};
tcp_nodelay {{cfg.nginx.http.tcp_nodelay}};

keepalive_timeout {{cfg.nginx.http.keepalive_timeout}};

gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

server {
server_name localhost;
listen {{cfg.nginx.http.listen.port}};
root {{pkg.svc_data_path}}/drupal;
client_body_temp_path {{pkg.svc_var_path}}/client-body;
proxy_temp_path {{pkg.svc_var_path}}/proxy;
fastcgi_temp_path {{pkg.svc_var_path}}/fastcgi;
scgi_temp_path {{pkg.svc_var_path}}/scgi;
uwsgi_temp_path {{pkg.svc_var_path}}/uwsgi;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

# No reason to access these other than from the file system
location ~* \.(txt|log)$ {
deny all;
}

location ~ \..*/.*\.php$ {
return 403;
}

location ~ ^/sites/.*/private/ {
return 403;
}

# Allow "Well-Known URIs" as per RFC 5785
location ~* ^/.well-known/ {
allow all;
}

location ~ (^|/)\. {
return 403;
}

location / {
try_files $uri /index.php?$query_string;
}

location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}

location ~ /vendor/.*\.php$ {
deny all;
return 404;
}

location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
include fastcgi_params;

fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}

location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}

location ~ ^(/[a-z\-]+)?/system/files/ {
try_files $uri /index.php?$query_string;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
}
20 changes: 20 additions & 0 deletions drupal/default.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[drupal]
site_name = "drupal"
db_name = "drupal"
account_name = "admin"
account_password = "173467321476C32789777643T732V73117888732476789764376Lock"

[nginx]
worker_processes = 4

[nginx.events]
worker_connections = 1024

[nginx.http]
keepalive_timeout = 60
sendfile = "on"
tcp_nodelay = "on"
tcp_nopush = "on"

[nginx.http.listen]
port = 80
31 changes: 31 additions & 0 deletions drupal/hooks/init
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

exec 2>&1

if [ ! -d {{pkg.svc_data_path}}/drupal ]
then
# Prepare Drupal
cd {{pkg.path}}/drupal
drush -y site-install standard \
--db-url="mysql://{{bind.database.first.cfg.username}}:{{bind.database.first.cfg.password}}@{{bind.database.first.sys.ip}}/{{cfg.drupal.db_name}}" \
--site-name={{cfg.drupal.site_name}} \
--account-name={{cfg.drupal.account_name}} \
--account-pass={{cfg.drupal.account_password}}

# Now drop Drupal in the correct location
cp -r {{pkg.path}}/drupal {{pkg.svc_data_path}}
fi

# Copy the php-fom config into position
cp -n {{pkgPathFor "core/php"}}/etc/php-fpm.d/www.conf.default \
{{pkgPathFor "core/php"}}/etc/php-fpm.d/www.conf

# Set the correct permissions
chmod +x {{pkg.svc_data_path}}
chown -R hab:hab {{pkg.svc_data_path}}

# Deplay the nginx config and then launch it
cp -r {{pkg.svc_config_path}}/nginx.conf \
{{pkgPathFor "core/nginx"}}/config/nginx.conf

hab service load core/nginx --group {{svc.group}} --force
35 changes: 35 additions & 0 deletions drupal/plan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pkg_name=drupal
pkg_origin=core
pkg_version="8.3.2"
pkg_license=('gplv2+')
pkg_source="N/A"
pkg_shasum="N/A"
pkg_deps=(core/mysql-client core/drush core/nginx core/php)
pkg_binds=(
[database]="port username password"
)
pkg_svc_user="root"
pkg_svc_run="php-fpm --nodaemonize"
pkg_description="Drupal is a free and open source content-management framework written in PHP."
pkg_upstream_url="https://www.drupal.org"
pkg_maintainers="The Habitat Maintainers <[email protected]>"

do_download() {
return 0
}

do_verify() {
return 0
}

do_unpack() {
return 0
}

do_build() {
drush dl drupal-8.3.2 --drupal-project-rename=drupal
}

do_install() {
cp -r "$HAB_CACHE_SRC_PATH"/$pkg_dirname/drupal $pkg_prefix/drupal
}

0 comments on commit c9f9303

Please sign in to comment.