Skip to content
Snippets Groups Projects
Commit 0429de60 authored by jurgenhaas's avatar jurgenhaas
Browse files

#10 Refactor the start script and add new option to eneter into a running l3d...

#10 Refactor the start script and add new option to eneter into a running l3d container from everywhere
parent a22188c0
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash #!/usr/bin/env bash
if [[ "$1" == "help" ]]; then function help {
echo "L3D - LakeDropsDrupalDev" echo "L3D - LakeDropsDrupalDev"
echo "=========================" echo "========================="
echo "" echo ""
echo "Version: 1.3.0" echo "Version: 1.3.0"
echo "Info and support: https://gitlab.lakedrops.com/docker/l3d" echo "Info and support: https://gitlab.lakedrops.com/docker/l3d"
exit 0 echo ""
fi echo "Usage:"
echo " l3d [ help | selfupdate | update | PROJECTNAME]"
echo ""
echo ""
}
if [[ "$1" == "selfupdate" ]]; then function selfupdate {
DEST=$(which l3d) DEST=$(which l3d)
WGET=$(which wget) WGET=$(which wget)
CURL=$(which curl) CURL=$(which curl)
if [[ -n "$WGET" ]]; then if [[ -n "$WGET" ]]; then
sudo wget -O $DEST https://gitlab.lakedrops.com/docker/l3d/raw/master/l3d sudo wget -O $DEST https://gitlab.lakedrops.com/docker/l3d/raw/master/l3d > /dev/null 2>&1
elif [[ -n "$CURL" ]]; then elif [[ -n "$CURL" ]]; then
sudo curl -o $DEST https://gitlab.lakedrops.com/docker/l3d/raw/master/l3d sudo curl -o $DEST https://gitlab.lakedrops.com/docker/l3d/raw/master/l3d > /dev/null 2>&1
else else
echo "Could't find wget or curl to perform the update!" echo "Could't find wget or curl to perform the update!"
exit 1 exit 1
fi fi
sudo chmod +x $DEST sudo chmod +x $DEST
echo "Self update succeeded!" echo "Self update succeeded!"
exit 0 }
fi
export $(cat .env | xargs)
if [[ "${PHP_VERSION}" == "" ]]; then
while true; do
read -p "Which PHP version is your project using? " PHP_VERSION
case ${PHP_VERSION} in
7.0 ) break;;
7.1 ) break;;
7.2 ) break;;
* ) echo "Version not supported.";;
esac
done
echo "PHP_VERSION=${PHP_VERSION}" >>.env
fi
if [[ "${COMPOSE_PROJECT_NAME}" == "" ]]; then
read -p "Name your project (used as subdomain): " COMPOSE_PROJECT_NAME
echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}" >>.env
fi
ID=$(docker container ls -q -f name=${COMPOSE_PROJECT_NAME}_l3d)
if [[ "$1" == "update" ]]; then function update {
getenv
IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d:php-${PHP_VERSION}) IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d:php-${PHP_VERSION})
echo "Updating the image ..." echo "Updating the image ..."
STATUS=$(docker pull registry.lakedrops.com/docker/l3d:php-${PHP_VERSION}) STATUS=$(docker pull registry.lakedrops.com/docker/l3d:php-${PHP_VERSION})
...@@ -68,23 +51,81 @@ if [[ "$1" == "update" ]]; then ...@@ -68,23 +51,81 @@ if [[ "$1" == "update" ]]; then
done done
fi fi
fi fi
fi }
function getenv {
if [[ -f ".env" ]]; then
export $(cat .env | xargs) > /dev/null 2>&1
fi
if [[ "${PHP_VERSION}" == "" ]]; then
while true; do
read -p "Which PHP version is your project using? " PHP_VERSION
case ${PHP_VERSION} in
7.0 ) break;;
7.1 ) break;;
7.2 ) break;;
* ) echo "Version not supported.";;
esac
done
echo "PHP_VERSION=${PHP_VERSION}" >>.env
fi
if [[ "${COMPOSE_PROJECT_NAME}" == "" ]]; then
read -p "Name your project (used as subdomain): " COMPOSE_PROJECT_NAME
echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}" >>.env
fi
}
if [[ -n "$ID" ]]; then function start {
docker start ${COMPOSE_PROJECT_NAME}_l3d if [[ -n "${COMPOSE_PROJECT_NAME}" ]]; then
else ID=$(docker container ls -q -f name=${COMPOSE_PROJECT_NAME}_l3d)
docker run --name ${COMPOSE_PROJECT_NAME}_l3d -dt \
--hostname ${COMPOSE_PROJECT_NAME}-l3d \ if [[ -n "$ID" ]]; then
--env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} \ docker start ${COMPOSE_PROJECT_NAME}_l3d
--env SSH_AUTH_SOCK=/ssh-agent \ else
--env-file ${PWD}/.env \ docker run --name ${COMPOSE_PROJECT_NAME}_l3d -dt \
--volume /var/run/docker.sock:/var/run/docker.sock \ --hostname ${COMPOSE_PROJECT_NAME}-l3d \
--volume ${PWD}:/drupal \ --env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} \
--volume ${SSH_AUTH_SOCK}:/ssh-agent \ --env SSH_AUTH_SOCK=/ssh-agent \
--volume ${HOME}/.traefik:/root/.traefik \ --env-file ${PWD}/.env \
--volume ${HOME}/.gitconfig:/root/.gitconfig \ --volume /var/run/docker.sock:/var/run/docker.sock \
--workdir /drupal \ --volume ${PWD}:/drupal \
--restart unless-stopped \ --volume ${SSH_AUTH_SOCK}:/ssh-agent \
registry.lakedrops.com/docker/l3d:php-${PHP_VERSION} --volume ${HOME}/.traefik:/root/.traefik \
fi --volume ${HOME}/.gitconfig:/root/.gitconfig \
docker exec -it ${COMPOSE_PROJECT_NAME}_l3d /usr/bin/fish --workdir /drupal \
--restart unless-stopped \
registry.lakedrops.com/docker/l3d:php-${PHP_VERSION}
fi
docker exec -it ${COMPOSE_PROJECT_NAME}_l3d /usr/bin/fish
fi
}
COMPOSE_PROJECT_NAME=
case $1 in
help )
help
;;
selfupdate )
selfupdate
;;
update )
update
start
;;
* )
if [[ -n "$1" ]]; then
ID=$(docker container ls -q -f name=$1_l3d)
if [[ -n "${ID}" ]]; then
COMPOSE_PROJECT_NAME=$1
fi
else
getenv
fi
start
;;
esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment