Created
October 5, 2018 22:39
-
-
Save whaleinvasion/ef6442bfa4a6435dbe681241df72c110 to your computer and use it in GitHub Desktop.
WordPress on Amazon ECS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if env | grep -q ^WP_WEBROOT=; then | |
echo "Replacing nginx webroot for WordPress with environment variable: $WP_WEBROOT" | |
sed -i 's#root /var/www/html;#root '$WP_WEBROOT';#' /etc/nginx/nginx.conf | |
fi | |
echo "INFO: Running /usr/bin/supervisord" | |
echo "\n\n" | |
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf | |
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:3.3 | |
MAINTAINER Tom Maiaroto <[email protected]> | |
# Install packages | |
RUN apk --update --repository http://dl-3.alpinelinux.org/alpine/edge/main add \ | |
freetype-dev \ | |
libjpeg-turbo-dev \ | |
libpng-dev \ | |
libwebp-dev \ | |
php7 \ | |
php7-xml \ | |
php7-xmlreader \ | |
php7-xsl \ | |
php7-pdo_mysql \ | |
php7-mcrypt \ | |
php7-curl \ | |
php7-json \ | |
php7-fpm \ | |
php7-phar \ | |
php7-openssl \ | |
php7-mysqli \ | |
php7-ctype \ | |
php7-opcache \ | |
php7-mbstring \ | |
php7-zlib \ | |
php7-gd \ | |
nginx \ | |
supervisor --repository http://nl.alpinelinux.org/alpine/edge/testing/ | |
# Small fixes and cleanup | |
RUN ln -s /etc/php7 /etc/php && \ | |
ln -s /usr/bin/php7 /usr/bin/php && \ | |
ln -s /usr/sbin/php-fpm7 /usr/bin/php-fpm && \ | |
ln -s /usr/lib/php7 /usr/lib/php && \ | |
rm -fr /var/cache/apk/* | |
# PHP Composer | |
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer | |
# Configure nginx | |
COPY config/nginx.conf /etc/nginx/nginx.conf | |
# Configure PHP-FPM | |
COPY config/fpm-pool.conf /etc/php7/php-fpm.d/zzz_custom.conf | |
COPY config/php.ini /etc/php7/conf.d/zzz_custom.ini | |
# Configure supervisord | |
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf | |
# This runs supervisord as well as configures some things like nginx's webroot. | |
COPY config/config-and-run.sh /usr/local/bin/config-and-run.sh | |
RUN chmod +x /usr/local/bin/config-and-run.sh | |
# Note: The NGINX_WEBROOT environment variable should be set to change | |
# the webroot so that this file is never served. | |
COPY config/index.php /var/www/html/ | |
# Permissions | |
RUN chown nginx:www-data -R /var/lib/nginx | |
RUN chmod -R g+w /var/lib/nginx | |
# /run/nginx/nginx.pid needs /run/nginx to exist | |
# https://github.com/gliderlabs/docker-alpine/issues/185 | |
RUN mkdir -p /run/nginx | |
# The following should be set or overwritten when the Docker container runs (ECS Task definition). | |
# These are used by WordPress. | |
# ENV DB_HOST | |
# ENV DB_NAME | |
# ENV DB_USER | |
# ENV DB_PASSWORD | |
ENV WP_ENV='development' | |
ENV WP_HOME='http://localhost' | |
ENV WP_SITEURL='http://localhost/wp' | |
# Not used by WordPress, but used by the config-and-run.sh script to replace | |
# the webroot in nginx.conf. It should point to where you have WordPress. | |
ENV WP_WEBROOT='/var/www/html' | |
EXPOSE 80 1443 | |
CMD ["/usr/local/bin/config-and-run.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Join the default ECS cluster | |
echo ECS_CLUSTER=default >> /etc/ecs/ecs.config | |
PATH=$PATH:/usr/local/bin | |
# Instance should be added to an security group that allows HTTP outbound | |
yum update | |
# Install jq, a JSON parser | |
yum -y install jq | |
# Install NFS client | |
if ! rpm -qa | grep -qw nfs-utils; then | |
yum -y install nfs-utils | |
fi | |
if ! rpm -qa | grep -qw python27; then | |
yum -y install python27 | |
fi | |
# Install pip | |
yum -y install python27-pip | |
# Install awscli | |
pip install awscli | |
# Upgrade to the latest version of the awscli | |
# pip install --upgrade awscli | |
# Add support for EFS to the CLI configuration | |
aws configure set preview.efs true | |
# Create mount point | |
mkdir /mnt/efs | |
# Instance needs to be a member of security group that allows 2049 | |
# The security group that the instance belongs to has to be added to EFS file system configuration | |
# Mount EFS file system | |
sudo mount -t nfs4 -o nfsvers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-37c93f9e.efs.us-west-2.amazonaws.com:/ /mnt/efs | |
# Restart docker (has to be done afer mounting EFS apparently: https://forums.aws.amazon.com/thread.jspa?messageID=671360) | |
sudo service docker restart && sudo start ecs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment