diff --git a/.gitignore b/.gitignore index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..108de3d3a94a3bcea0badd01a22a251cfc23c7eb 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,3 @@ +/.ahoy.l3d +/.ahoy.yml +/.env diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index 0383ee055e4ffaea3bc9fcfea7a59765cd9aba2e..0000000000000000000000000000000000000000 --- a/CHANGELOG +++ /dev/null @@ -1,116 +0,0 @@ -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 diff --git a/Dockerfile b/Dockerfile index 81e56ab0005db346fb91501f022152682cec16e7..686d5f9ee168ef858293fee9fddb619cf03a3745 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,10 @@ ADD config.fish /etc/fish/ ADD start.sh /usr/local/bin/.start ADD configIdea.sh /usr/local/bin/.configIdea 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" && \ cd /var/opt && \ diff --git a/README.md b/README.md deleted file mode 100644 index 13b81f946c988c758374cc644d0a33f13fad3aaf..0000000000000000000000000000000000000000 --- a/README.md +++ /dev/null @@ -1,137 +0,0 @@ -# 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 -``` diff --git a/ahoy.changelog.yml b/ahoy.changelog.yml new file mode 100644 index 0000000000000000000000000000000000000000..481118f470c4f042befa329d8b0c1f2e0d588cf6 --- /dev/null +++ b/ahoy.changelog.yml @@ -0,0 +1,5 @@ +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. diff --git a/run/Dockerfile b/run/Dockerfile index de57d32c9c1164ac29a3493a9efdf8ce62961519..1560373ca6def3a58cee40e49dda7d1fb7e55cab 100644 --- a/run/Dockerfile +++ b/run/Dockerfile @@ -14,7 +14,7 @@ ARG glibc_version=2.28-r0 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://github.com/sgerrand/alpine-pkg-glibc/releases/download/${glibc_version}/glibc-${glibc_version}.apk && \ apk add --no-cache glibc-${glibc_version}.apk && \ diff --git a/run/scripts/delete b/run/scripts/delete index e3efc5063dcfafce45566306ddbdce592e3ba3e9..09526c0b55405ab83ed99154b24da11ceb1a42e9 100755 --- a/run/scripts/delete +++ b/run/scripts/delete @@ -28,7 +28,7 @@ function removenetwork() { docker-compose stop docker rm -f traefik_traefik_1 docker network rm traefik_${PROJECT} - docker-compose up -d + docker-compose --project-name traefik up -d fi } diff --git a/run/scripts/help b/run/scripts/help index d3b794bb9e5629a18367c34fbe21dfc81214ad64..6670f4ca98e9423e9dc75f16b40b306529bbf60c 100755 --- a/run/scripts/help +++ b/run/scripts/help @@ -3,8 +3,8 @@ echo "L3D - LakeDropsDrupalDev" echo "=========================" echo "" -echo "Version: ${VERSION}" +echo "Version: ${L3DVERSION}" echo "Support: https://gitlab.lakedrops.com/docker/l3d" 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 "" diff --git a/run/scripts/info b/run/scripts/info new file mode 100755 index 0000000000000000000000000000000000000000..d8024647c43f593c1e74397b254a2a4c55a10d07 --- /dev/null +++ b/run/scripts/info @@ -0,0 +1,67 @@ +#!/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 diff --git a/run/scripts/l3dnewversion b/run/scripts/l3dnewversion new file mode 100755 index 0000000000000000000000000000000000000000..a0aa0e3ca664bb22063a632d3325b6401a067e4c --- /dev/null +++ b/run/scripts/l3dnewversion @@ -0,0 +1,7 @@ +#!/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 diff --git a/run/scripts/list b/run/scripts/list index 435d6ed62141ad6285073ef9a4803eec1fcc208b..ff58f40b91cb1fdb79490b172c447b4a08a09f18 100755 --- a/run/scripts/list +++ b/run/scripts/list @@ -8,12 +8,11 @@ function listprojects() { echo "No active L3D projects found." return fi - echo "Active L3D projects:" - echo "====================" - echo "" + printf "Active L3D projects:" 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 + echo "" rm /tmp/l3d.lst } @@ -25,12 +24,11 @@ function listnetworks() { echo "No active L3D networks found." return fi - echo "Active L3D networks:" - echo "====================" - echo "" + printf "Active L3D networks:" 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 + echo "" rm /tmp/l3d.lst } diff --git a/run/scripts/run b/run/scripts/run index 4cff91d5e7bafdd662d13a5a9926473d66ae6ec7..8eea159115267329d54135c882b6fdbbb54491ff 100755 --- a/run/scripts/run +++ b/run/scripts/run @@ -1,6 +1,6 @@ #!/bin/bash -export VERSION='{{ version }}' +export L3DVERSION='{{ version }}' COMMAND=start if [[ -n "$1" ]]; then diff --git a/run/scripts/selfupdate b/run/scripts/selfupdate index 33c391d5e935613bbb9fbd8e47b311551b01b65e..206ad90812eabc207efd86c5c7d230d78122bc1d 100755 --- a/run/scripts/selfupdate +++ b/run/scripts/selfupdate @@ -3,10 +3,10 @@ if [[ -n $1 ]]; then NEWVERSION=$1 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 -if [[ "$NEWVERSION" == "$VERSION" ]]; then +if [[ "$NEWVERSION" == "" ]]; then echo "No new version available" exit fi @@ -19,18 +19,23 @@ if [[ "$UPDATE" == *"setup:${NEWVERSION} not found"* ]]; then fi echo "Self update to version ${NEWVERSION} succeeded!" - -export VERSION=${NEWVERSION} -export L3D_FORCE_UPDATE=0 -/usr/local/bin/reset - echo "" echo "" echo "" -echo "================================================================" -echo "It's recommended to run" +echo "==================================================================" +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 " l3d reset" +echo "when the self-update has completed." +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 diff --git a/run/scripts/start b/run/scripts/start index c3a32e0210221cadeec0fa1dc20c72f0782455e7..e4af188a0ea1adf7ff516b2ab1dc723019a1027f 100755 --- a/run/scripts/start +++ b/run/scripts/start @@ -1,28 +1,28 @@ #!/bin/bash -function getConfig { +function getConfig() { if [[ ! -n ${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;; - 7.3 ) break;; - 7.4 ) break;; - 8.0 ) break;; - * ) echo "Version not supported.";; - esac + read -p "Which PHP version is your project using? " PHP_VERSION + case ${PHP_VERSION} in + 7.0) break ;; + 7.1) break ;; + 7.2) break ;; + 7.3) break ;; + 7.4) break ;; + 8.0) break ;; + *) echo "Version not supported." ;; + esac done fi if [[ ! -n ${COMPOSER_DOWNGRADE} ]]; then while true; do - read -p "Do you want to downgrade Composer to version 1? " COMPOSER_DOWNGRADE - case ${COMPOSER_DOWNGRADE} in - 0 ) break;; - 1 ) break;; - * ) echo "Only 1 or 0 are valid responses.";; - esac + read -p "Do you want to downgrade Composer to version 1? " COMPOSER_DOWNGRADE + case ${COMPOSER_DOWNGRADE} in + 0) break ;; + 1) break ;; + *) echo "Only 1 or 0 are valid responses." ;; + esac done fi if [[ ! -n ${COMPOSE_PROJECT_NAME} ]]; then @@ -30,33 +30,70 @@ function getConfig { fi } -function startContainer { +function startContainer() { if [[ -n ${COMPOSE_PROJECT_NAME} ]]; then - ID=$(docker container ls --all -q -f name=^${COMPOSE_PROJECT_NAME}_l3d$) - if [[ -n ${ID} ]]; then - docker start ${COMPOSE_PROJECT_NAME}_l3d + mode=REBUILD + if [[ $COMPOSE_PROJECT_NAME == "." ]]; then + mode=NONPRESISTENT else - docker run --name ${COMPOSE_PROJECT_NAME}_l3d -dt \ - --hostname ${COMPOSE_PROJECT_NAME}-l3d \ - --user ${USERID}:${GROUPID} \ - --group-add ${GROUPIDS// / --group-add } \ - --env L3DSHELL=${L3DSHELL} \ - --env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} \ - --env COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE} \ - --env PHP_VERSION=${PHP_VERSION} \ - --env SSH_AUTH_SOCK=${SSHAUTHSOCK} \ - --volume /var/run/docker.sock:/var/run/docker.sock \ - --volume ${WORKDIR}:/drupal \ - --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 \ - --volume ${SSHAUTH}:${SSHAUTHSOCK} \ - --volume ${HOMEDIR}:${HOMEDIR} \ - --workdir /drupal \ - --restart unless-stopped \ - registry.lakedrops.com/docker/l3d/php-${PHP_VERSION}:${VERSION} + ID=$(docker container ls --all -q -f name=^${COMPOSE_PROJECT_NAME}_l3d$) + if [[ -n ${ID} ]]; then + docker start ${COMPOSE_PROJECT_NAME}_l3d + mode=REGULAR + fi + fi + if [[ "$mode" != "REGULAR" ]]; then + start_params=( + --env L3DVERSION=${L3DVERSION} + --env L3DSHELL=${L3DSHELL} + --env HOME=/home/${USERNAME} + --env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} + --env COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE} + --env PHP_VERSION=${PHP_VERSION} + --env SSH_AUTH_SOCK=${SSHAUTHSOCK} + --volume ${L3DDOCKERHOST}:/var/run/docker.sock + --volume ${WORKDIR}:/drupal + --volume ${SSHAUTH}:${SSHAUTHSOCK} + --volume ${HOMEDIR}:/home/${USERNAME} + --workdir /drupal + ) + 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 docker exec -it \ --env HOMEDIR=${HOMEDIR} \ @@ -68,10 +105,14 @@ function startContainer { } if [[ -n $1 ]]; then - ID=$(docker container ls --all -q -f name=^$1_l3d$) - if [[ -n ${ID} ]]; then - PHP_VERSION=unknown - COMPOSE_PROJECT_NAME=$1 + if [[ "$1" == "." ]]; then + COMPOSE_PROJECT_NAME=. + else + ID=$(docker container ls --all -q -f name=^$1_l3d$) + if [[ -n ${ID} ]]; then + PHP_VERSION=unknown + COMPOSE_PROJECT_NAME=$1 + fi fi fi getConfig diff --git a/run/scripts/update b/run/scripts/update index ba662e8f9d1a470497766309cf4ae9433fb80676..4c1d4ca3772d5c16fb94091a99bc98832e9c820d 100755 --- a/run/scripts/update +++ b/run/scripts/update @@ -24,7 +24,7 @@ function cleanup { removecontainer $IMAGEID done 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 fi docker image ls -q registry.lakedrops.com/docker/node > /tmp/reset.lst @@ -43,7 +43,7 @@ if [[ -n ${PHP_VERSION} ]]; then exit fi 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 echo "Already up to date" else diff --git a/run/scripts/version b/run/scripts/version index 6510e0e13a25be7c118bb07c4eceb0188e46e2ba..ba93bf4b2eadf061a65ea4e811039ae144505b84 100755 --- a/run/scripts/version +++ b/run/scripts/version @@ -1,3 +1,10 @@ #!/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 diff --git a/setup/scripts/l3d b/setup/scripts/l3d index 13af5c52beb52e1af615893253bf1ba3dfccf279..03ba4fb136cb8aba2118a3a7b7c58184b02e2925 100755 --- a/setup/scripts/l3d +++ b/setup/scripts/l3d @@ -1,8 +1,14 @@ #!/bin/bash +GROUPID=$(id -g) +GROUPIDS=$(id -G) +L3DHOSTOS="$(uname -s)" +L3DDOCKERHOST=/var/run/docker.sock SSHAUTH=${SSH_AUTH_SOCK} SSHAUTHSOCK=/ssh-agent -L3DHOSTOS="$(uname -s)" +USERID=$(id -u) +USERNAME=${USER} + case "${L3DHOSTOS}" in Darwin*) if ! which greadlink >/dev/null; then @@ -11,8 +17,17 @@ case "${L3DHOSTOS}" in else # This works on MacOS when coreutils is installed. SCRIPTPATH="$(dirname "$(greadlink -f "$0")")" + # (see #62) L3DDOCKERHOST="$(dirname "$(greadlink -f "/var/run/docker.sock")")/docker.sock" 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 exit $? fi @@ -30,15 +45,25 @@ fi touch ${HOME}/.gitconfig touch ${HOME}/.gitignore_global +# l3d container ID=$(docker container ls --all -q -f name=^l3drun$) 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 \ - --env SCRIPTPATH=${SCRIPTPATH} \ - --volume /var/run/docker.sock:/var/run/docker.sock \ - --volume ${SCRIPTPATH}:/setup \ - --volume ${HOME}/.traefik:/root/.traefik \ + "${l3drun_params[@]}" \ registry.lakedrops.com/docker/l3d/run:'{{ version }}' fi + +# Set l3d shell if [[ -n ${L3DSHELL} ]]; then # Nothing to do, we go with this value L3DSHELL=${L3DSHELL} @@ -47,26 +72,33 @@ elif [[ -n ${SHELL} ]]; then else L3DSHELL="/usr/bin/fish" fi + +# Read environment variables if [[ -f "${HOME}/.env" ]]; then export $(cat ${HOME}/.env | xargs) > /dev/null 2>&1 fi if [[ -f ".env" ]]; then export $(cat .env | xargs) > /dev/null 2>&1 fi -export USERID=$(id -u) -export GROUPID=$(id -g) -export GROUPIDS=$(id -G) + +# Create project container parameters +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 \ - --env USERID=${USERID} \ - --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} \ + "${project_params[@]}" \ l3drun \ /usr/local/bin/run $@ diff --git a/setup/scripts/prepareMac4L3d b/setup/scripts/prepareMac4L3d deleted file mode 100755 index ac088d61441b6bdfc4e90db32add8ed8c39072d3..0000000000000000000000000000000000000000 --- a/setup/scripts/prepareMac4L3d +++ /dev/null @@ -1,88 +0,0 @@ -#!/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 diff --git a/setup/scripts/setup b/setup/scripts/setup index eff93626007e6150f8e455b61d12b073fc7a249b..4c6fed84af0aa18f547d8eb5d2c01a7b9df55693 100755 --- a/setup/scripts/setup +++ b/setup/scripts/setup @@ -1,7 +1,6 @@ #!/bin/sh cp /usr/local/bin/l3d /setup/l3d -cp /usr/local/bin/prepareMac4L3d /setup/prepareMac4L3d echo "L3D installed successfully!" echo "" diff --git a/start.sh b/start.sh index afb271dfa23fb601cb403052647191d2a02246d1..11e484993150bd50c0a16ca34e2a04f9c566c120 100755 --- a/start.sh +++ b/start.sh @@ -188,13 +188,36 @@ function initialSetup { 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 # Validate PHP version INSTALLED_PHP_VERSION=$(php -r "echo(substr(phpversion(),0,3));") if [[ "$INSTALLED_PHP_VERSION" != "$PHP_VERSION" ]]; then - 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" ============================================= "\\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 ============================================= \\033[0m" fi if [[ "$COMPOSER_DOWNGRADE" == "1" ]]; then composer self-update --1 @@ -212,6 +235,7 @@ else l3dComposer fi +setupAhoy if [[ -d /drupal/.idea ]]; then /usr/local/bin/.configIdea fi