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

Merge branch 'release/v2.0.0'

parents 6c721437 0886f548
No related branches found
No related tags found
No related merge requests found
/.ahoy.l3d
/.ahoy.yml
/.env
v1.17.5 2021-01-04
------------------
docker/l3d#44 Update readme for requirements
docker/l3d#71 Output recommendation to run l3d reset at the end of selfupdate
docker/l3d#70 Add a list command
v1.17.4 2021-01-04
------------------
#69 Fix selfupdate to grab the correct latest tag
v1.17.3 2020-12-30
------------------
docker/l3d#61 Mount traefik config directory into l3drun and kill the traefik container before removing network
v1.17.2 2020-12-30
------------------
docker/l3d#61 Add docker-compose to the image
v1.17.1 2020-12-30
------------------
docker/l3d#61 Add a delete command to remove a project's containers and network
v1.17.0 2020-12-29
------------------
composer/plugin/docker4drupal#39 Add support for PHP 8.0
docker/l3d#26 Check for correct PHP version when starting the L3D container
docker/l3d#59 Add support for optional .env file in user home directory
v1.16.0 2020-12-28
------------------
docker/l3d#47 Optionally downgrade composer to version 1
docker/l3d#51 Add curly brackets to auth.json if the file is empty
docker/l3d#53 Fix bug when creating auth.json
docker/l3d#54 Add COMPOSER_DOWNGRADE to .env file if available
docker/l3d#57 Mount the sudoers config
docker/l3d#57 Mount the sudoers.d config, mount into correct home directory, add all group IDs
docker/l3d#57 Mount the whole home directory, also solves the permissions
docker/l3d#57 Pass through UID and GID from host
docker/l3d#57 Set user 1000 for the main l3d container
docker/l3d#57 Set user and group id dynamically and mount password files into container
v1.15.0 2020-11-07
------------------
docker/l3d#47 Composer 2 compatibility
v1.14.1 2020-10-15
------------------
docker/l3d#46 Add support for PHP 7.4
v1.13.1 2020-07-15
------------------
Map the local .gitignore_global into containers
v1.13.0 2020-07-20
------------------
Add support for Drupal 9 project templates
v1.12.8 2020-05-22
------------------
Force update to update to base image v1.4.4
v1.12.7 2020-05-22
------------------
Force update to update to base image v1.4.3
v1.12.6 2020-05-22
------------------
Force update to update to base image v1.4.2
v1.12.5 2020-03-31
------------------
Remove debug code
Set write permissions for group after initial composer command
v1.12.4 2020-03-31
------------------
Ensure .composer/auth.json and .gitconfig more explicitly
Make sure to always write the .env file after having started the container
Add mechanism to interact with extra|l3d in composer.json when starting l3d
v1.12.3 2020-02-17
------------------
Correct the path to the user home directory on Mac OS X in the readme file
Make sure that .gitconfig and composer's auth.json exist even before l3drun gets started, not before l3d project container starts as that's too late
v1.12.2 2020-02-12
------------------
Better define the destination for composer create project which is required on some Macs
v1.12.1 2020-02-10
------------------
Force update to update to composer version 1.9.3
v1.12.0 2020-01-12
------------------
docker/l3d#4 Set permissions after "drush generate"
docker/l3d#39 Update to git-extras version 5.1.0 by hard-copying column as a binary
docker/l3d#34 Add support for PHP 7.3
docker/l3d#36 Add apropos which also brings man
docker/l3d#37 Add phpstan script which runs in its own docker container
docker/l3d#38 Update Docker to 19.03.5
docker/l3d#38 Update Docker Compose to 1.25.1
docker/l3d#40 Update to Python 3
v1.11.0 2020-01-11
------------------
Update to v1.3.0 of the gitlab-drupal-ci image which comes with more node versions (10, 12, 13)
Delete all node images during selfupdate
v1.10.2 2019-12-27
------------------
Fix update scripts to remove old containers
v1.10.1 2019-12-27
------------------
Force rebuild to include Sodium support for PHP 7.2
...@@ -16,6 +16,10 @@ ADD config.fish /etc/fish/ ...@@ -16,6 +16,10 @@ ADD config.fish /etc/fish/
ADD start.sh /usr/local/bin/.start ADD start.sh /usr/local/bin/.start
ADD configIdea.sh /usr/local/bin/.configIdea ADD configIdea.sh /usr/local/bin/.configIdea
ADD l3dComposer.php /usr/local/bin/.l3dComposer.php ADD l3dComposer.php /usr/local/bin/.l3dComposer.php
ADD ahoy.changelog.yml /etc/ahoy/changelog.yml
ADD run/scripts/info /usr/local/bin/l3d
ADD run/scripts/version /usr/local/bin/version
ADD run/scripts/l3dnewversion /usr/local/bin/l3dnewversion
RUN echo "Install dorgflow" && \ RUN echo "Install dorgflow" && \
cd /var/opt && \ cd /var/opt && \
......
# LakeDropsDrupalDev - L3D
Provides fully configured Docker images for local Drupal development where your local host requires nothing else than Docker being installed but no PHP, Composer or any other tool on this planet. It simply works.
## Prerequisites
Nothing else than docker being installed on your host. You don't need any other tool - none!
Please refer to the [official Docker documentation](https://docs.docker.com/get-docker/) to quickly find out how to install docker on your platform.
Depending on your system setup you may also want to add your own user to the group `docker` afterwards.
If your IDE doesn't come with integrated Git support, you may also have to install tools like [Git](https://git-scm.com/downloads), [Git Flow](https://github.com/nvie/gitflow/wiki/Installation) or [Git LFS](https://git-lfs.github.com) - but all that depends on your specific needs. Usually all you need can be found inside of the L3D containers and you don't have to install any other tool on your host at all.
## Quick start Linux
You can install the tool with the following command:
```bash
docker run -v /usr/local/bin:/setup --rm registry.lakedrops.com/docker/l3d/setup:latest
```
This will install the script `l3d` into the given directory `/usr/local/bin` from where it is executable everywhere on your host (assuming this path being in your search path). If you want that script to be installed elsewhere then provide that alternative path in the install command above. Instead of `latest` you can also start with any other specific version number of this tool. You can find all available version strings in the [tag list](https://gitlab.lakedrops.com/docker/l3d/tags) of this project.
## Quick start MacOS
Here we have to circumwent some limitations that come with Docker for Mac:
1. Docker for Mac is not able to mount certain directories and one of those is anything underneath `/usr`. Therefore you have to use a different directory where the L3D script and some additional files get stored.
2. Docker for Mac does not properly mount sockets such that SSH agent can not be used inside of Docker containers the same way this is being done on Linux platforms. There are many workarounds available and we have integrated the approach from [mariusgrigaitis](https://github.com/mariusgrigaitis/docker-mac-ssh-auth-sock) into this project.
This requires [socat](https://linux.die.net/man/1/socat). You can install that with `brew install socat` or `sudo port install socat` or any other method that is applicable to you specific Mac. After installation make sure that `socat` can be found in your search path. If it got installed in a directory that isn't in the path, you can create a symbolic link to it into `/usr/local/bin`.
Then use the following command to install L3D (replace `myname` with your correct username:
```bash
docker run -v /Users/myname/bin:/setup --rm registry.lakedrops.com/docker/l3d/setup:latest
```
Then make sure that the directory `/Users/myname/bin` is included in the PATH environment variable or create a symbolic link in `/usr/local/bin`. If you work with a symbolic link, MacOS also requires [coreutils](https://de.wikipedia.org/wiki/GNU_Core_Utilities) which can be installed with `brew install coreutils` or `sudo port install coreutils`.
## Verifying SSH
As you will require SSH functionality in most development environments, let's make sure that this really works. In order to find out if your host is properly configured to use (and forward) SSH authentication, you should call `ssh-add -l` and see if it lists your public key(s). if it doesn't, just call `ssh-add` to add you public keys to the ssh agent. If this doesn't persist after a reboot of you host on MacOS, then please follow [these instructions](https://apple.stackexchange.com/questions/253779/macos-10-12-sierra-will-not-forget-my-ssh-keyfile-passphrase/254619#254619).
To test SSH easily, you can do something like this:
```shell script
$> ssh -T git@github.com
# Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.
$> ssh -T git@gitlab.com
# Welcome to GitLab, @yourusername!
```
The same test also works with other hosts where your public key is configured as your authentication method. Please note, you can repeat these SSH tests inside the L3D container later on as well and they should produce the very same results.
## Usage
Go to the project root for which you want to use **L3D** and execute the installed script: simply type `l3d` at the command prompt.
It will ask you for the PHP version (input `7.0`, `7.1`, `7.2`, `7.3`, `7.4` or `8.0`), the project name and template to be used. Then it will download the matching **L3D** image and start a container for you. Furthermore you can choose, if want to use composer 1 for some reason. To downgrade just set the value `1`. The default is the version 2.
Inside the container you'll find the directory `/drupal` which contains everything from your project's root. You can work from there by using these available tools:
| Tool | Command | Shortcut |
| --- | --- | --- |
| Ahoy | `ahoy` | `a` |
| Composer | `composer` | `c` |
| Docker | `docker` | |
| Docker Composer | `docker-compose` | `d-c` |
| DorgFlow | `dorgflow` | |
| Drush | `drush` | `d` |
### LakeDrops Drupal 8 or Drupal 9 project template
If you have chosen the LakeDrops Drupal 8 or Drupal 9 project template, type 'a d4d up' at the command prompt within the container to start the remaining containers.
'drush status' will then show you the URL of your project.
## Update the start script
Just call `l3d selfupdate` and the start script will be updated from the original repository. This will also update all your existing **L3D** images and remove the outdated containers so that they will be recreated the next timne you're going to use them.
## Resetting containers
Sometimes the mounted volumes into existing containers will change, e.g. after a reboot on a Mac, the directory where the SSH-Agent stores their information will have gotten a different name. In such situations, starting one of the existing containers will throw error messages to the console. To resolve this, all L3D-related existing containers need to be rebuilt.
You chould call `l3d reset` which cleans up all the related containers and prepares the system such that next call to L3D will rebuild those required containers from scratch. Note that removing containers will not remove their volumes. This is a good thing, because it makes sure that all your data will remain intact and will be used by the newly created containers just as before.
## Working with Git credentials
In order to commit and push with git you have to at least configure your email address and username for the git client. If you configure those globally on your host, each of the **L3D** containers will inherit those settings and there is nothing that needs to be done inside the container.
To configure those credentials, use these commands:
```bash
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
```
## Configuring the shell
By default, L3D tries to use the same shell inside the containers that you also use on your host. If that's not possible, it falls back to [FISH](https://fishshell.com).
If you want to overwrite the shell deliberatly, then define an environment variable on your host, like e.g.
```shell script
export L3DSHELL=/bin/bash
```
Note that only new containers will get affected by this setting.
## Getting help
Calling `l3d help` displays information about **L3D** and provides a link to further details.
## Examples
### Start a new project
```bash
cd /var/www
mkdir testproject1
cd testproject1
l3d
```
You will be presented with a list of options on how to get started and you can simply follow the instructions on screen.
### Use with an existing project
```bash
cd /path/to/your/project
l3d
composer update
```
ahoyapi: v2
commands:
extract:
cmd: git log $(git describe --tags `git rev-list --tags --max-count=1`)..HEAD --oneline | cut -d' ' -f 2-999
usage: Extract changelog from Git for the current project since the last release.
...@@ -14,7 +14,7 @@ ARG glibc_version=2.28-r0 ...@@ -14,7 +14,7 @@ ARG glibc_version=2.28-r0
ADD scripts/* /usr/local/bin/ ADD scripts/* /usr/local/bin/
RUN apk add bash curl jq && \ RUN apk add --no-cache bash curl jq && \
wget -q https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -O /etc/apk/keys/sgerrand.rsa.pub && \ wget -q https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -O /etc/apk/keys/sgerrand.rsa.pub && \
wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${glibc_version}/glibc-${glibc_version}.apk && \ wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${glibc_version}/glibc-${glibc_version}.apk && \
apk add --no-cache glibc-${glibc_version}.apk && \ apk add --no-cache glibc-${glibc_version}.apk && \
......
...@@ -28,7 +28,7 @@ function removenetwork() { ...@@ -28,7 +28,7 @@ function removenetwork() {
docker-compose stop docker-compose stop
docker rm -f traefik_traefik_1 docker rm -f traefik_traefik_1
docker network rm traefik_${PROJECT} docker network rm traefik_${PROJECT}
docker-compose up -d docker-compose --project-name traefik up -d
fi fi
} }
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
echo "L3D - LakeDropsDrupalDev" echo "L3D - LakeDropsDrupalDev"
echo "=========================" echo "========================="
echo "" echo ""
echo "Version: ${VERSION}" echo "Version: ${L3DVERSION}"
echo "Support: https://gitlab.lakedrops.com/docker/l3d" echo "Support: https://gitlab.lakedrops.com/docker/l3d"
echo "" echo ""
echo "Usage: l3d [ help | version | selfupdate [VERSION] | update | reset | PROJECTNAME | delete PROJECTNAME ] | list" echo "Usage: l3d [ help | version | selfupdate [VERSION] | update | reset | PROJECTNAME | delete PROJECTNAME ] | list | info | . "
echo "" echo ""
#!/bin/bash
function sectionHeader() {
echo ""
echo "======================================================================="
echo $1
echo ""
echo ""
}
function sectionFooter() {
echo ""
echo "-----------------------------------------------------------------------"
echo ""
}
function infol3d() {
sectionHeader "Your L3D"
${SCRIPTPATH}/version
if [[ $HOSTMODE == true ]]; then
echo ""
${SCRIPTPATH}/list
else
if [[ "$1" == "info" ]]; then
if [[ -f .env ]]; then
more .env
fi
else
echo -e "\\033[31m ======================================== \\033[0m"
echo -e "\\033[31m Calling L3D inside of L3D is not useful. \\033[0m"
echo -e "\\033[31m ======================================== \\033[0m"
fi
fi
sectionFooter
}
function infohost() {
sectionHeader "Your Host"
echo "OS: ${L3DHOSTOS}"
echo "User: ${USERNAME} (${USERID}:${GROUPID} - ${GROUPIDS})"
echo "Home: ${HOMEDIR}"
echo "Shell: ${L3DSHELL}"
echo "Workdir: ${WORKDIR}"
echo "SSH: ${SSHAUTH} - ${SSHAUTHSOCK}"
sectionFooter
}
function infodocker() {
sectionHeader "Your Docker"
docker info 2>/dev/null | grep "Server Version:"
docker info 2>/dev/null | grep "Operating System:"
docker info 2>/dev/null | grep "OSType:"
docker info 2>/dev/null | grep "Architecture:"
sectionFooter
}
SCRIPTPATH="$(cd "$(dirname "$0")" && pwd -P)"
HOSTMODE=false
if [[ -f ${SCRIPTPATH}/selfupdate ]]; then
HOSTMODE=true
fi
infol3d $1
if [[ $HOSTMODE == true ]]; then
infohost
infodocker
fi
#!/bin/bash
NEWVERSION=$(curl -s "https://gitlab.lakedrops.com/api/v4/projects/282/repository/tags?order_by=updated&search=^v" | jq -r .[0].name)
if [[ "$NEWVERSION" == "$L3DVERSION" ]]; then
return
fi
printf "%s" $NEWVERSION
...@@ -8,12 +8,11 @@ function listprojects() { ...@@ -8,12 +8,11 @@ function listprojects() {
echo "No active L3D projects found." echo "No active L3D projects found."
return return
fi fi
echo "Active L3D projects:" printf "Active L3D projects:"
echo "===================="
echo ""
for CONTAINERID in `cat /tmp/l3d.lst`; do for CONTAINERID in `cat /tmp/l3d.lst`; do
docker inspect $CONTAINERID | jq -r .[0].Config.Hostname | cut -d'-' -f 1 printf " %s" "$(docker inspect $CONTAINERID | jq -r .[0].Config.Hostname | cut -d'-' -f 1)"
done done
echo ""
rm /tmp/l3d.lst rm /tmp/l3d.lst
} }
...@@ -25,12 +24,11 @@ function listnetworks() { ...@@ -25,12 +24,11 @@ function listnetworks() {
echo "No active L3D networks found." echo "No active L3D networks found."
return return
fi fi
echo "Active L3D networks:" printf "Active L3D networks:"
echo "===================="
echo ""
for NETWORKID in `cat /tmp/l3d.lst`; do for NETWORKID in `cat /tmp/l3d.lst`; do
docker inspect $NETWORKID | jq -r .[0].Name | cut -d'_' -f 2 printf " %s" "$(docker inspect $NETWORKID | jq -r .[0].Name | cut -d'_' -f 2)"
done done
echo ""
rm /tmp/l3d.lst rm /tmp/l3d.lst
} }
......
#!/bin/bash #!/bin/bash
export VERSION='{{ version }}' export L3DVERSION='{{ version }}'
COMMAND=start COMMAND=start
if [[ -n "$1" ]]; then if [[ -n "$1" ]]; then
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
if [[ -n $1 ]]; then if [[ -n $1 ]]; then
NEWVERSION=$1 NEWVERSION=$1
else else
NEWVERSION=$(curl -s "https://gitlab.lakedrops.com/api/v4/projects/282/repository/tags?order_by=updated&search=^v" | jq -r .[0].name) NEWVERSION=$(/usr/local/bin/l3dnewversion)
fi fi
if [[ "$NEWVERSION" == "$VERSION" ]]; then if [[ "$NEWVERSION" == "" ]]; then
echo "No new version available" echo "No new version available"
exit exit
fi fi
...@@ -19,18 +19,23 @@ if [[ "$UPDATE" == *"setup:${NEWVERSION} not found"* ]]; then ...@@ -19,18 +19,23 @@ if [[ "$UPDATE" == *"setup:${NEWVERSION} not found"* ]]; then
fi fi
echo "Self update to version ${NEWVERSION} succeeded!" echo "Self update to version ${NEWVERSION} succeeded!"
export VERSION=${NEWVERSION}
export L3D_FORCE_UPDATE=0
/usr/local/bin/reset
echo "" echo ""
echo "" echo ""
echo "" echo ""
echo "================================================================" echo "=================================================================="
echo "It's recommended to run" echo "The cleanup process only removes unused and outdated components."
echo "If you also want to update the components of your current projects"
echo "you need to run"
echo ""
echo -e " \\033[31m l3d reset \\033[0m"
echo "" echo ""
echo " l3d reset" echo "when the self-update has completed."
echo "=================================================================="
echo "" echo ""
echo "now, so that we can clean the legacy components properly." echo ""
echo "================================================================" echo ""
docker pull registry.lakedrops.com/docker/l3d/run:${NEWVERSION} 2>&1
export L3DVERSION=${NEWVERSION}
export L3D_FORCE_UPDATE=0
/usr/local/bin/reset
#!/bin/bash #!/bin/bash
function getConfig { function getConfig() {
if [[ ! -n ${PHP_VERSION} ]]; then if [[ ! -n ${PHP_VERSION} ]]; then
while true; do while true; do
read -p "Which PHP version is your project using? " PHP_VERSION read -p "Which PHP version is your project using? " PHP_VERSION
case ${PHP_VERSION} in case ${PHP_VERSION} in
7.0 ) break;; 7.0) break ;;
7.1 ) break;; 7.1) break ;;
7.2 ) break;; 7.2) break ;;
7.3 ) break;; 7.3) break ;;
7.4 ) break;; 7.4) break ;;
8.0 ) break;; 8.0) break ;;
* ) echo "Version not supported.";; *) echo "Version not supported." ;;
esac esac
done done
fi fi
if [[ ! -n ${COMPOSER_DOWNGRADE} ]]; then if [[ ! -n ${COMPOSER_DOWNGRADE} ]]; then
while true; do while true; do
read -p "Do you want to downgrade Composer to version 1? " COMPOSER_DOWNGRADE read -p "Do you want to downgrade Composer to version 1? " COMPOSER_DOWNGRADE
case ${COMPOSER_DOWNGRADE} in case ${COMPOSER_DOWNGRADE} in
0 ) break;; 0) break ;;
1 ) break;; 1) break ;;
* ) echo "Only 1 or 0 are valid responses.";; *) echo "Only 1 or 0 are valid responses." ;;
esac esac
done done
fi fi
if [[ ! -n ${COMPOSE_PROJECT_NAME} ]]; then if [[ ! -n ${COMPOSE_PROJECT_NAME} ]]; then
...@@ -30,33 +30,70 @@ function getConfig { ...@@ -30,33 +30,70 @@ function getConfig {
fi fi
} }
function startContainer { function startContainer() {
if [[ -n ${COMPOSE_PROJECT_NAME} ]]; then if [[ -n ${COMPOSE_PROJECT_NAME} ]]; then
ID=$(docker container ls --all -q -f name=^${COMPOSE_PROJECT_NAME}_l3d$) mode=REBUILD
if [[ -n ${ID} ]]; then if [[ $COMPOSE_PROJECT_NAME == "." ]]; then
docker start ${COMPOSE_PROJECT_NAME}_l3d mode=NONPRESISTENT
else else
docker run --name ${COMPOSE_PROJECT_NAME}_l3d -dt \ ID=$(docker container ls --all -q -f name=^${COMPOSE_PROJECT_NAME}_l3d$)
--hostname ${COMPOSE_PROJECT_NAME}-l3d \ if [[ -n ${ID} ]]; then
--user ${USERID}:${GROUPID} \ docker start ${COMPOSE_PROJECT_NAME}_l3d
--group-add ${GROUPIDS// / --group-add } \ mode=REGULAR
--env L3DSHELL=${L3DSHELL} \ fi
--env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} \ fi
--env COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE} \ if [[ "$mode" != "REGULAR" ]]; then
--env PHP_VERSION=${PHP_VERSION} \ start_params=(
--env SSH_AUTH_SOCK=${SSHAUTHSOCK} \ --env L3DVERSION=${L3DVERSION}
--volume /var/run/docker.sock:/var/run/docker.sock \ --env L3DSHELL=${L3DSHELL}
--volume ${WORKDIR}:/drupal \ --env HOME=/home/${USERNAME}
--volume /etc/group:/etc/group:ro \ --env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}
--volume /etc/passwd:/etc/passwd:ro \ --env COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE}
--volume /etc/shadow:/etc/shadow:ro \ --env PHP_VERSION=${PHP_VERSION}
--volume /etc/sudoers:/etc/sudoers:ro \ --env SSH_AUTH_SOCK=${SSHAUTHSOCK}
--volume /etc/sudoers.d:/etc/sudoers.d:ro \ --volume ${L3DDOCKERHOST}:/var/run/docker.sock
--volume ${SSHAUTH}:${SSHAUTHSOCK} \ --volume ${WORKDIR}:/drupal
--volume ${HOMEDIR}:${HOMEDIR} \ --volume ${SSHAUTH}:${SSHAUTHSOCK}
--workdir /drupal \ --volume ${HOMEDIR}:/home/${USERNAME}
--restart unless-stopped \ --workdir /drupal
registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION} )
if [[ ${L3DHOSTOS} != Darwin ]]; then
start_params+=(
--user ${USERID}:${GROUPID}
--group-add ${GROUPIDS// / --group-add }
--volume /etc/group:/etc/group:ro
--volume /etc/passwd:/etc/passwd:ro
--volume /etc/shadow:/etc/shadow:ro
--volume /etc/sudoers:/etc/sudoers:ro
--volume /etc/sudoers.d:/etc/sudoers.d:ro
)
# else
# (see #62) Disabled for now.
#start_params+=(
# --volume ${HOMEDIR}/.passwd:/etc/passwd:ro
#)
fi
if [[ "$mode" == "REBUILD" ]]; then
start_params+=(
--hostname ${COMPOSE_PROJECT_NAME}-l3d
)
docker run --name ${COMPOSE_PROJECT_NAME}_l3d -dt \
"${start_params[@]}" \
--restart unless-stopped \
registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION}
else
start_params+=(
--hostname "L3D"
--env HOMEDIR=${HOMEDIR}
--env WORKDIR=${WORKDIR}
--env SSHAUTH=${SSHAUTH}
)
docker run -it --rm \
"${start_params[@]}" \
registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION} \
/usr/local/bin/.start
return
fi
fi fi
docker exec -it \ docker exec -it \
--env HOMEDIR=${HOMEDIR} \ --env HOMEDIR=${HOMEDIR} \
...@@ -68,10 +105,14 @@ function startContainer { ...@@ -68,10 +105,14 @@ function startContainer {
} }
if [[ -n $1 ]]; then if [[ -n $1 ]]; then
ID=$(docker container ls --all -q -f name=^$1_l3d$) if [[ "$1" == "." ]]; then
if [[ -n ${ID} ]]; then COMPOSE_PROJECT_NAME=.
PHP_VERSION=unknown else
COMPOSE_PROJECT_NAME=$1 ID=$(docker container ls --all -q -f name=^$1_l3d$)
if [[ -n ${ID} ]]; then
PHP_VERSION=unknown
COMPOSE_PROJECT_NAME=$1
fi
fi fi
fi fi
getConfig getConfig
......
...@@ -24,7 +24,7 @@ function cleanup { ...@@ -24,7 +24,7 @@ function cleanup {
removecontainer $IMAGEID removecontainer $IMAGEID
done done
else else
IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION} | head -1) IMAGEID=$(docker image ls -q registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION} | head -1)
removecontainer $IMAGEID rmi removecontainer $IMAGEID rmi
fi fi
docker image ls -q registry.lakedrops.com/docker/node > /tmp/reset.lst docker image ls -q registry.lakedrops.com/docker/node > /tmp/reset.lst
...@@ -43,7 +43,7 @@ if [[ -n ${PHP_VERSION} ]]; then ...@@ -43,7 +43,7 @@ if [[ -n ${PHP_VERSION} ]]; then
exit exit
fi fi
echo "Updating the image ..." echo "Updating the image ..."
STATUS=$(docker pull registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION}) STATUS=$(docker pull registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${L3DVERSION})
if [[ "$STATUS" == *"Status: Image is up to date"* ]]; then if [[ "$STATUS" == *"Status: Image is up to date"* ]]; then
echo "Already up to date" echo "Already up to date"
else else
......
#!/bin/bash #!/bin/bash
echo "${VERSION}" echo "Version: ${L3DVERSION}"
NEWVERSION=$(/usr/local/bin/l3dnewversion)
if [[ "$NEWVERSION" != "" ]]; then
echo ""
echo "A new version is available: $NEWVERSION"
echo " run 'l3d selfupdate'"
fi
#!/bin/bash #!/bin/bash
GROUPID=$(id -g)
GROUPIDS=$(id -G)
L3DHOSTOS="$(uname -s)"
L3DDOCKERHOST=/var/run/docker.sock
SSHAUTH=${SSH_AUTH_SOCK} SSHAUTH=${SSH_AUTH_SOCK}
SSHAUTHSOCK=/ssh-agent SSHAUTHSOCK=/ssh-agent
L3DHOSTOS="$(uname -s)" USERID=$(id -u)
USERNAME=${USER}
case "${L3DHOSTOS}" in case "${L3DHOSTOS}" in
Darwin*) Darwin*)
if ! which greadlink >/dev/null; then if ! which greadlink >/dev/null; then
...@@ -11,8 +17,17 @@ case "${L3DHOSTOS}" in ...@@ -11,8 +17,17 @@ case "${L3DHOSTOS}" in
else else
# This works on MacOS when coreutils is installed. # This works on MacOS when coreutils is installed.
SCRIPTPATH="$(dirname "$(greadlink -f "$0")")" SCRIPTPATH="$(dirname "$(greadlink -f "$0")")"
# (see #62) L3DDOCKERHOST="$(dirname "$(greadlink -f "/var/run/docker.sock")")/docker.sock"
fi fi
${SCRIPTPATH}/prepareMac4L3d GROUPID=1
# (see #62) Write a fake passwd file which will later be mounted into containers.
# echo "${USERNAME}:x:${USERID}:${GROUPID}:${USERNAME},,,:/home/${USERNAME}:${L3DSHELL}" >${HOME}/.passwd
USERNAME=root
# This variable is used to access the ssh agent on MacOS.
SSHAUTHMAGICPATH="/run/host-services/ssh-auth.sock"
SSHAUTH=${SSHAUTHMAGICPATH}
SSHAUTHSOCK=${SSHAUTHMAGICPATH}
if [[ $? > 0 ]]; then if [[ $? > 0 ]]; then
exit $? exit $?
fi fi
...@@ -30,15 +45,25 @@ fi ...@@ -30,15 +45,25 @@ fi
touch ${HOME}/.gitconfig touch ${HOME}/.gitconfig
touch ${HOME}/.gitignore_global touch ${HOME}/.gitignore_global
# l3d container
ID=$(docker container ls --all -q -f name=^l3drun$) ID=$(docker container ls --all -q -f name=^l3drun$)
if [[ ! -n ${ID} ]]; then if [[ ! -n ${ID} ]]; then
# Create l3drun container parameters
l3drun_params=(
--env L3DHOSTOS=${L3DHOSTOS}
--env SCRIPTPATH=${SCRIPTPATH}
--env L3DDOCKERHOST=${L3DDOCKERHOST}
--volume /var/run/docker.sock:/var/run/docker.sock
--volume ${SCRIPTPATH}:/setup
--volume ${HOME}/.traefik:/root/.traefik
)
# Execute l3drun container
docker run --name=l3drun -dt --rm \ docker run --name=l3drun -dt --rm \
--env SCRIPTPATH=${SCRIPTPATH} \ "${l3drun_params[@]}" \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume ${SCRIPTPATH}:/setup \
--volume ${HOME}/.traefik:/root/.traefik \
registry.lakedrops.com/docker/l3d/run:'{{ version }}' registry.lakedrops.com/docker/l3d/run:'{{ version }}'
fi fi
# Set l3d shell
if [[ -n ${L3DSHELL} ]]; then if [[ -n ${L3DSHELL} ]]; then
# Nothing to do, we go with this value # Nothing to do, we go with this value
L3DSHELL=${L3DSHELL} L3DSHELL=${L3DSHELL}
...@@ -47,26 +72,33 @@ elif [[ -n ${SHELL} ]]; then ...@@ -47,26 +72,33 @@ elif [[ -n ${SHELL} ]]; then
else else
L3DSHELL="/usr/bin/fish" L3DSHELL="/usr/bin/fish"
fi fi
# Read environment variables
if [[ -f "${HOME}/.env" ]]; then if [[ -f "${HOME}/.env" ]]; then
export $(cat ${HOME}/.env | xargs) > /dev/null 2>&1 export $(cat ${HOME}/.env | xargs) > /dev/null 2>&1
fi fi
if [[ -f ".env" ]]; then if [[ -f ".env" ]]; then
export $(cat .env | xargs) > /dev/null 2>&1 export $(cat .env | xargs) > /dev/null 2>&1
fi fi
export USERID=$(id -u)
export GROUPID=$(id -g) # Create project container parameters
export GROUPIDS=$(id -G) project_params=(
--env USERID=${USERID}
--env USERNAME=${USERNAME}
--env GROUPID=${GROUPID}
--env GROUPIDS="${GROUPIDS}"
--env HOMEDIR=${HOME}
--env L3DSHELL=${L3DSHELL}
--env WORKDIR=${PWD}
--env SSHAUTH=${SSHAUTH}
--env SSHAUTHSOCK=${SSHAUTHSOCK}
--env PHP_VERSION=${PHP_VERSION}
--env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}
--env COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE}
)
# Execute project container
docker exec -it \ docker exec -it \
--env USERID=${USERID} \ "${project_params[@]}" \
--env GROUPID=${GROUPID} \
--env GROUPIDS="${GROUPIDS}" \
--env HOMEDIR=${HOME} \
--env L3DSHELL=${L3DSHELL} \
--env WORKDIR=${PWD} \
--env SSHAUTH=${SSHAUTH} \
--env SSHAUTHSOCK=${SSHAUTHSOCK} \
--env PHP_VERSION=${PHP_VERSION} \
--env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} \
--env COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE} \
l3drun \ l3drun \
/usr/local/bin/run $@ /usr/local/bin/run $@
#!/usr/bin/env bash
# Credit: https://github.com/mariusgrigaitis/docker-mac-ssh-auth-sock
SOCATID=$(docker container ls --all -q -f name=l3d_socat)
if [[ -n ${SOCATID} ]]; then
exit 0
fi
if ! which socat >/dev/null; then
echo "socat is missing. Install it and make sure the executable is in the local search path."
echo "For help see https://stackoverflow.com/questions/16808543/install-socat-on-mac"
exit 1
fi
if ! docker ps >/dev/null; then
echo "Docker for Mac is not running. Make sure it's running."
exit 1
fi
if [[ -z "${SSH_AUTH_SOCK}" ]]; then
echo "SSH_AUTH_SOCK is missing. Is ssh-agent running?"
exit 1
fi
if ! test -S ${SSH_AUTH_SOCK}; then
echo "$SSH_AUTH_SOCK is not a socket. Check agent?"
exit 1
fi
TTY_FILE=~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
TTY_FILE_NEW=~/Library/Containers/com.docker.docker/Data/vms/0/tty
if ! test -c $TTY_FILE; then
echo "$TTY_FILE is not available. Docker for Mac setup has changed? Trying newer file..."
if ! test -c $TTY_FILE_NEW; then
echo "$TTY_FILE_NEW is not available. Docker for Mac setup has changed? Giving up."
exit 1
else
TTY_FILE=$TTY_FILE_NEW
fi
fi
# This is where the UGLY hack starts
#
# Problem: if you do: docker run -v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK container
# you get a socket file which is mounted over osxfs from Mac host.
# This socket file can't be reused or removed because it would make ssh commands on
# host machine to not work
#
# Solution:
# 1. connect to VM over special tty channel
# 2. create an empty directory
# 3. bind mount that empty directory over $SSH_AUTH_SOCK directory
# 4. Profit
#
# This makes other docker containers see the created directory instead of osxfs mounted one.
# It also allows to create socket file under same path that does not collide with host one.
# Command is sent over special tty channel to Docker for Mac VM and does not check for errors, etc
# meaning it could be very "unreliable"
COMMAND="mkdir -p /ssh-auth-sock-hack && mount -o bind /ssh-auth-sock-hack $(dirname $SSH_AUTH_SOCK) && rmdir $SSH_AUTH_SOCK"
echo ctr -n services.linuxkit tasks exec --exec-id 'ssh-$(hostname)-$$' '$(ctr -n services.linuxkit tasks ls -q | grep docker)' sh -c \"$COMMAND\" > $TTY_FILE
# give some time for command to execute.
sleep 1
echo "Docker for Mac is now prepared."
echo "Starting socket proxy."
# This is where the proxying magic happens
# On host machine it connects to $SSH_AUTH_SOCK socket and pipes output to stdout, takes input from stdin
# On docker VM it launches a container running socat, which creates a socket file under $SSH_AUTH_SOCK path, accepts
# input and forwards it to stdout/stdin
# socat running on host machine connects stdin/stdout between those two sockets can communicate over stdin/stdout
#
# This is not really reliable because forwarding input/output over stdin/stdout does not allow for multiple communications
# at the same time. It fails when doing multiple connections to $SSH_AUTH_SOCK at the same time.
exec socat "EXEC:\"docker run -i --rm --name l3d_socat -v $(dirname $SSH_AUTH_SOCK):$(dirname $SSH_AUTH_SOCK) alpine/socat UNIX-LISTEN:$SSH_AUTH_SOCK,reuseaddr,fork -\"" "EXEC:\"socat - UNIX:${SSH_AUTH_SOCK}\"" &
echo "Waiting ..."
sleep 2
SOCATID=$(docker container ls --all -q -f name=l3d_socat)
if [[ -n ${SOCATID} ]]; then
ssh-add
echo "All set!"
exit 0
fi
exit 1
#!/bin/sh #!/bin/sh
cp /usr/local/bin/l3d /setup/l3d cp /usr/local/bin/l3d /setup/l3d
cp /usr/local/bin/prepareMac4L3d /setup/prepareMac4L3d
echo "L3D installed successfully!" echo "L3D installed successfully!"
echo "" echo ""
......
...@@ -188,13 +188,36 @@ function initialSetup { ...@@ -188,13 +188,36 @@ function initialSetup {
done done
} }
function setupAhoy {
if [[ ! -f .ahoy.yml ]]; then
echo "ahoyapi: v2" >.ahoy.yml
echo "commands:" >>.ahoy.yml
fi
if [[ ! -L .ahoy.l3d ]]; then
ln -s /etc/ahoy .ahoy.l3d
fi
if [[ -f .gitignore ]]; then
EXISTING=$(cat .gitignore | grep "^/.ahoy.l3d$")
if [[ -z ${EXISTING} ]]; then
echo "/.ahoy.l3d" >>.gitignore
fi
fi
EXISTING=$(cat .ahoy.yml | grep "^ changelog:")
if [[ -z ${EXISTING} ]]; then
echo " changelog:" >>.ahoy.yml
echo " imports:" >>.ahoy.yml
echo " - ./.ahoy.l3d/changelog.yml" >>.ahoy.yml
echo " usage: Changelog tools." >>.ahoy.yml
fi
}
readEnv readEnv
# Validate PHP version # Validate PHP version
INSTALLED_PHP_VERSION=$(php -r "echo(substr(phpversion(),0,3));") INSTALLED_PHP_VERSION=$(php -r "echo(substr(phpversion(),0,3));")
if [[ "$INSTALLED_PHP_VERSION" != "$PHP_VERSION" ]]; then if [[ "$INSTALLED_PHP_VERSION" != "$PHP_VERSION" ]]; then
echo -e "\\033[31m" ============================================= "\\033[0m" echo -e "\\033[31m ============================================= \\033[0m"
echo -e "\\033[31m" ERROR: PHP $INSTALLED_PHP_VERSION installed but $PHP_VERSION expected !!! "\\033[0m" echo -e "\\033[31m ERROR: PHP $INSTALLED_PHP_VERSION installed but $PHP_VERSION expected !!! \\033[0m"
echo -e "\\033[31m" ============================================= "\\033[0m" echo -e "\\033[31m ============================================= \\033[0m"
fi fi
if [[ "$COMPOSER_DOWNGRADE" == "1" ]]; then if [[ "$COMPOSER_DOWNGRADE" == "1" ]]; then
composer self-update --1 composer self-update --1
...@@ -212,6 +235,7 @@ else ...@@ -212,6 +235,7 @@ else
l3dComposer l3dComposer
fi fi
setupAhoy
if [[ -d /drupal/.idea ]]; then if [[ -d /drupal/.idea ]]; then
/usr/local/bin/.configIdea /usr/local/bin/.configIdea
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment