|
| 1 | +#!/usr/bin/env sh |
| 2 | + |
| 3 | +# createComposerDockerExtras <result-var-by-ref> |
| 4 | +createComposerDockerExtras() { |
| 5 | + local __resultvar=$1 |
| 6 | + |
| 7 | + result="" |
| 8 | + |
| 9 | + if [ -n "$SSH_FORWARD_ENABLED" ]; then |
| 10 | + if [ "$(uname)" = "Linux" ]; then |
| 11 | + result="--volume /etc/passwd:/etc/passwd:ro --volume /etc/group:/etc/group:ro --volume $SSH_AUTH_SOCK:/ssh-auth.sock --env SSH_AUTH_SOCK=/ssh-auth.sock ${result}" |
| 12 | + else |
| 13 | + result="--volume /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock --env SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock ${result}" |
| 14 | + fi |
| 15 | + fi |
| 16 | + |
| 17 | + if [ -n "${COMPOSER_AUTH_ENABLED}" ]; then |
| 18 | + if [ -n "${COMPOSER_AUTH}" ]; then |
| 19 | + result="--env COMPOSER_AUTH=${COMPOSER_AUTH} ${result}" |
| 20 | + elif [ -n "${COMPOSER_AUTH_REPO}" ] && [ -n "${COMPOSER_AUTH_USER}" ] && [ -n "${COMPOSER_AUTH_PASSWORD}" ]; then |
| 21 | + composerAuth='{"http-basic":{"'${COMPOSER_AUTH_REPO}'":{"username":"'${COMPOSER_AUTH_USER}'","password":"'${COMPOSER_AUTH_PASSWORD}'"}}}' |
| 22 | + result="--env COMPOSER_AUTH=${composerAuth} ${result}" |
| 23 | + elif [ ! -f "${HOME}/.composer/auth.json" ]; then |
| 24 | + printf "${warning}Please make sure that %s/.composer/auth.json exists and the credentials of your repository are present, or provide env vars COMPOSER_AUTH_REPO, COMPOSER_AUTH_USER and COMPOSER_AUTH_PASSWORD${reset}\n" "${HOME}" |
| 25 | + fi |
| 26 | + fi |
| 27 | + |
| 28 | + eval $__resultvar="'$result'" |
| 29 | +} |
| 30 | + |
| 31 | +# createComposerDockerExtras <result-var-by-ref> |
| 32 | +createComposerDockerBuildExtras() { |
| 33 | + local __resultvar=$1 |
| 34 | + |
| 35 | + if [ -n "${COMPOSER_AUTH_ENABLED}" ]; then |
| 36 | + if [ -n "${COMPOSER_AUTH}" ]; then |
| 37 | + result="--build-arg COMPOSER_AUTH=${COMPOSER_AUTH} ${COMPOSER_DOCKER_EXTRAS}" |
| 38 | + elif [ -n "${COMPOSER_AUTH_REPO}" ] && [ -n "${COMPOSER_AUTH_USER}" ] && [ -n "${COMPOSER_AUTH_PASSWORD}" ]; then |
| 39 | + composerAuth='{"http-basic":{"'${COMPOSER_AUTH_REPO}'":{"username":"'${COMPOSER_AUTH_USER}'","password":"'${COMPOSER_AUTH_PASSWORD}'"}}}' |
| 40 | + result="--build-arg COMPOSER_AUTH=${composerAuth} ${DOCKER_BUILD_EXTRAS}" |
| 41 | + elif [ -f "${HOME}/.composer/auth.json" ]; then |
| 42 | + result="--secret id=composer-auth-json,src=${HOME}/.composer/auth.json ${DOCKER_BUILD_EXTRAS}" |
| 43 | + else |
| 44 | + printf "Please make sure that %s/.composer/auth.json exists and the credentials of your repository are present, or provide env vars COMPOSER_AUTH_REPO, COMPOSER_AUTH_USER and COMPOSER_AUTH_PASSWORD\n" "${HOME}" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + fi |
| 48 | + |
| 49 | + eval $__resultvar="'$result'" |
| 50 | +} |
0 commit comments