From 429135806198908f729f0581a072d881f8df38f7 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen.haas@lakedrops.com> Date: Thu, 29 Feb 2024 16:25:26 +0100 Subject: [PATCH] docker/gitlab-drupal-ci#48 - Copy docker-compose.yml into l3drun if it exists - Only write to files that are writable - Update to v2.2.17 of upstream image --- .gitlab-ci.yml | 2 +- run/scripts/start | 7 +++--- setup/scripts/l3d | 6 ++++++ start.sh | 55 +++++++++++++++++++++++++---------------------- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b6e5fbe..4fd9b71 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ include: variables: VERSION: ${CI_COMMIT_TAG} - CI_VERSION: v2.2.16 + CI_VERSION: v2.2.17 before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY diff --git a/run/scripts/start b/run/scripts/start index 367d7bf..c3f546d 100755 --- a/run/scripts/start +++ b/run/scripts/start @@ -1,9 +1,10 @@ #!/bin/bash function getConfig() { - if [[ -f "docker-compose.yml" ]]; then - COMPOSE_PROJECT_NAME=$(yq .name docker-compose.yml) - PHP_VERSION=$(yq .services.php.image docker-compose.yml | cut -d':' -f 2) + if [[ "$L3D_COMPOSE" != "[]" ]]; then + COMPOSE_PROJECT_NAME=$(yq .name $L3D_COMPOSE) + PHP_VERSION=$(yq .services.php.image $L3D_COMPOSE | cut -d':' -f 2) + rm "$L3D_COMPOSE" fi if [[ ! -n ${PHP_VERSION} ]]; then while true; do diff --git a/setup/scripts/l3d b/setup/scripts/l3d index c4ec7d2..74c31a8 100755 --- a/setup/scripts/l3d +++ b/setup/scripts/l3d @@ -99,6 +99,11 @@ if [[ -f ".lakedrops.yml" ]]; then L3D_CONFIG=/tmp/${RANDOM}.lakedrops.yml docker cp .lakedrops.yml l3drun:$L3D_CONFIG >/dev/null 2>&1 fi +L3D_COMPOSE=[] +if [[ -f "docker-compose.yml" ]]; then + L3D_COMPOSE=/tmp/${RANDOM}-docker-compose.yml + docker cp docker-compose.yml l3drun:$L3D_COMPOSE >/dev/null 2>&1 +fi # Create project container parameters project_params=( @@ -110,6 +115,7 @@ project_params=( --env L3DSHELL=${L3DSHELL} --env L3D_ALWAYS_CLEANUP=${L3D_ALWAYS_CLEANUP} --env L3D_CONFIG=${L3D_CONFIG} + --env L3D_COMPOSE=${L3D_COMPOSE} --env WORKDIR=${PWD} --env PHP_VERSION=${PHP_VERSION} --env COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME} diff --git a/start.sh b/start.sh index f54a8aa..a617753 100755 --- a/start.sh +++ b/start.sh @@ -32,23 +32,22 @@ function restoreEnvFile { if [[ "${COMPOSE_PROJECT_NAME}" == "." ]]; then return fi - if [[ ! -w ".env" ]]; then - return - fi - if [[ -n ${PHP_VERSION} ]]; then - echo "PHP_VERSION=${PHP_VERSION}" >>.env - fi - if [[ -n ${COMPOSE_PROJECT_NAME} ]]; then - echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}" >>.env - fi - if [[ -n ${COMPOSER_DOWNGRADE} ]]; then - echo "COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE}" >>.env - fi - if [[ -f ".env" ]]; then - # shellcheck disable=SC2046 - # shellcheck disable=SC2094 - # shellcheck disable=SC2002 - env -i $(cat .env | xargs) >.env + if [[ -f ".env" && -w ".env" ]] || [[ ! -f ".env" && -w . ]]; then + if [[ -n ${PHP_VERSION} ]]; then + echo "PHP_VERSION=${PHP_VERSION}" >>.env + fi + if [[ -n ${COMPOSE_PROJECT_NAME} ]]; then + echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}" >>.env + fi + if [[ -n ${COMPOSER_DOWNGRADE} ]]; then + echo "COMPOSER_DOWNGRADE=${COMPOSER_DOWNGRADE}" >>.env + fi + if [[ -f ".env" ]]; then + # shellcheck disable=SC2046 + # shellcheck disable=SC2094 + # shellcheck disable=SC2002 + env -i $(cat .env | xargs) >.env + fi fi } @@ -210,7 +209,7 @@ function initialSetup { } function setupAhoy { - if [[ ! -f .ahoy.yml ]]; then + if [[ ! -f .ahoy.yml && -w . ]]; then echo "ahoyapi: v2" >.ahoy.yml echo "commands:" >>.ahoy.yml fi @@ -220,20 +219,24 @@ function setupAhoy { if [[ -f .gitignore ]]; then EXISTING=$(cat .gitignore | grep "^/.ahoy.l3d$") if [[ -z ${EXISTING} ]]; then - echo "/.ahoy.l3d" >>.gitignore + if [[ -f ".gitignore" && -w ".gitignore" ]] || [[ ! -f ".gitignore" && -w . ]]; then + echo "/.ahoy.l3d" >>.gitignore + fi 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 + if [[ -f ".ahoy.yml" && -w ".ahoy.yml" ]] || [[ ! -f ".ahoy.yml" && -w . ]]; then + 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 fi } if [[ -n ${PHP_VERSION} ]]; then - if [[ -w ".env" ]]; then + if [[ -f ".env" && -w ".env" ]] || [[ ! -f ".env" && -w . ]]; then echo "PHP_VERSION=${PHP_VERSION}" >>.env fi fi -- GitLab