Skip to content

Instantly share code, notes, and snippets.

@dkarlovi
Last active April 6, 2023 08:38

Revisions

  1. dkarlovi revised this gist Feb 2, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,8 @@ LOGS_DIR=${VAR_DIR}/logs

    # this sets up proper masking and (default and current) permissions for var/cache, var/logs
    # any user can create / edit / delete new and existing files regardless who the owner is
    # note: you do NOT need to run chmod 777 on these folders for this to work properly
    # note: you do NOT need to run chmod 777 on these folders or "sudo" anything (hello, Ubuntu users!)
    # for this to work properly
    permissions:
    setfacl -dRm m:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -Rm m:rwX ${CACHE_DIR} ${LOGS_DIR}
  2. dkarlovi revised this gist Feb 2, 2018. 2 changed files with 2 additions and 1 deletion.
    1 change: 1 addition & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@ LOGS_DIR=${VAR_DIR}/logs

    # this sets up proper masking and (default and current) permissions for var/cache, var/logs
    # any user can create / edit / delete new and existing files regardless who the owner is
    # note: you do NOT need to run chmod 777 on these folders for this to work properly
    permissions:
    setfacl -dRm m:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -Rm m:rwX ${CACHE_DIR} ${LOGS_DIR}
    2 changes: 1 addition & 1 deletion dsh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash

    # this is a wrapper which allows you to run commands within your Docker-Compose cluster
    # this is a wrapper which allows you to run commands WITHIN your Docker-Compose cluster
    # as you would with on your local machine, but with everything in the cluster available
    # just by prepending it with "bin/dsh"
    #
  3. dkarlovi revised this gist Feb 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -18,4 +18,4 @@ permissions:

    # you can run this directly from host as your current user has all correct privileges
    clean:
    rm -rf ${CACHE_DIR}/* ${VAR_DIR}/*
    rm -rf ${CACHE_DIR}/* ${LOGS_DIR}/*
  4. dkarlovi revised this gist Feb 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -18,4 +18,4 @@ permissions:

    # you can run this directly from host as your current user has all correct privileges
    clean:
    rm -rf ${CACHE_DIR}/* ${VAR_DIR}/*
    rm -rf ${CACHE_DIR}/* ${VAR_DIR}/*
  5. dkarlovi created this gist Feb 2, 2018.
    9 changes: 9 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    FROM alpine:3.7

    # this is the "app" image, contains PHP-FPM
    RUN addgroup -g 82 -S www-data && \
    adduser -u 82 -H -D -S -G www-data www-data && \
    # etc..

    # PHP-FPM is setup to run as "www-data"
    WORKDIR /app
    21 changes: 21 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # same user ID as in the Dockerfile
    APP_RUNNER_ID=82
    VAR_DIR=var
    CACHE_DIR=${VAR_DIR}/cache
    LOGS_DIR=${VAR_DIR}/logs

    # this sets up proper masking and (default and current) permissions for var/cache, var/logs
    # any user can create / edit / delete new and existing files regardless who the owner is
    permissions:
    setfacl -dRm m:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -Rm m:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -dRm u:`whoami`:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -Rm u:`whoami`:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -dRm u:${APP_RUNNER_ID}:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -Rm u:${APP_RUNNER_ID}:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -dRm u:root:rwX ${CACHE_DIR} ${LOGS_DIR}
    setfacl -Rm u:root:rwX ${CACHE_DIR} ${LOGS_DIR}

    # you can run this directly from host as your current user has all correct privileges
    clean:
    rm -rf ${CACHE_DIR}/* ${VAR_DIR}/*
    44 changes: 44 additions & 0 deletions dsh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/bin/bash

    # this is a wrapper which allows you to run commands within your Docker-Compose cluster
    # as you would with on your local machine, but with everything in the cluster available
    # just by prepending it with "bin/dsh"
    #
    # for example:
    # bin/dsh bin/console doctrine:schema:update --force
    # bin/dsh bin/console cache:clear
    # etc.
    # can also be root, but almost never needed:
    # bin/dsh -u root bin/console must:be:root:to:run:this

    usage() {
    echo "Usage: $0 [-u <www-data|root>] [-c <app>]" 1>&2;
    exit;
    }

    CONTAINER="app"
    USER="$(id -u):$(id -g)"
    while getopts ":u:c:" o; do
    case "${o}" in
    c)
    CONTAINER="${OPTARG}"
    ((CONTAINER == 'app')) || usage
    ;;
    u)
    USER="${OPTARG}"
    ((USER == 'root' || USER == 'www-data')) || usage
    USER="${USER}:${USER}"
    ;;
    *)
    usage
    ;;
    esac
    done
    shift "$((OPTIND-1))"

    ROOT="$(cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd)";
    COMMAND="${@}"
    if [ "${COMMAND}" == "" ]; then
    COMMAND="sh";
    fi;
    docker-compose -f "${ROOT}/docker-compose.yml" exec --user="${USER}" "${CONTAINER}" ${COMMAND}