diff --git a/README.md b/README.md index 9292657..1a176a2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Expects to run as part of the LSIO CI process. Not for public consumption. -## Running against local project +## Running against image If you need to test functionality just run: @@ -13,6 +13,15 @@ docker pull lscr.io/linuxserver/d2-builder:latest && \ docker run -d --rm -v /tmp/d2:/output -e PUID=1000 -e PGID=1000 lscr.io/linuxserver/d2-builder:latest mastodon:latest ``` +## Running against local project + +If you need to test functionality, make sure you have the necessary repos cloned locally and the correct branches checked out then just run: + +```bash +docker pull lscr.io/linuxserver/d2-builder:latest && \ +docker run -d --rm -v /tmp/d2:/output -v /opt/repos:/input:ro -e PUID=1000 -e PGID=1000 -e LOCAL=true lscr.io/linuxserver/d2-builder:latest mastodon:latest +``` + Generated svg files will be created in `/output`. ## Versions diff --git a/root/etc/s6-overlay/s6-rc.d/init-d2-config/run b/root/etc/s6-overlay/s6-rc.d/init-d2-config/run index aae3a2b..fbe80b3 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-d2-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-d2-config/run @@ -16,13 +16,18 @@ OUTPUTNAME="${IMAGENAME}-${TAGNAME}.d2" mkdir -p "/work/merge" if [[ ! ${IMAGENAME} == "baseimage"* ]]; then - git clone --depth=1 "https://github.com/linuxserver/docker-${IMAGENAME}" "/tmp/${IMAGENAME}" - IMAGEBRANCH=$(grep -Po "/tmp/${IMAGENAME}/jenkins-vars.yml" -e "^release_tag: \K(.*)$" | tr -d '"') - if [[ "${IMAGEBRANCH}" != "${TAGNAME}" ]]; then - cd "/tmp/${IMAGENAME}" || exit - git remote set-branches origin "${TAGNAME}" - git fetch --depth=1 - git checkout "${TAGNAME}" + if [[ -n ${LOCAL} ]]; then + mkdir -p "/tmp/${IMAGENAME}" + cp -R "/input/docker-${IMAGENAME}/"* "/tmp/${IMAGENAME}/" + else + git clone --depth=1 "https://github.com/linuxserver/docker-${IMAGENAME}" "/tmp/${IMAGENAME}" + IMAGEBRANCH=$(grep -Po "/tmp/${IMAGENAME}/jenkins-vars.yml" -e "^release_tag: \K(.*)$" | tr -d '"') + if [[ "${IMAGEBRANCH}" != "${TAGNAME}" ]]; then + cd "/tmp/${IMAGENAME}" || exit + git remote set-branches origin "${TAGNAME}" + git fetch --depth=1 + git checkout "${TAGNAME}" + fi fi BASEIMAGE=$(grep "/tmp/${IMAGENAME}/Dockerfile" -e "^FROM" | tail -l) @@ -37,13 +42,18 @@ else fi if [[ ${BASEIMAGENAME} =~ "baseimage" ]]; then - git clone --depth=1 "https://github.com/linuxserver/docker-${BASEIMAGENAME}" "/tmp/${BASEIMAGENAME}" - BASEBRANCH=$(grep -Po "/tmp/${BASEIMAGENAME}/jenkins-vars.yml" -e "^release_tag: \K(.*)$" | tr -d '"') - if [[ "${BASEBRANCH}" != "${BASEIMAGETAG}" ]]; then - cd "/tmp/${BASEIMAGENAME}" || exit - git remote set-branches origin "${BASEIMAGETAG}" - git fetch --depth=1 - git checkout "${BASEIMAGETAG}" + if [[ -n ${LOCAL} ]]; then + mkdir -p "/tmp/${BASEIMAGENAME}" + cp -R "/input/docker-${BASEIMAGENAME}/"* "/tmp/${BASEIMAGENAME}/" + else + git clone --depth=1 "https://github.com/linuxserver/docker-${BASEIMAGENAME}" "/tmp/${BASEIMAGENAME}" + BASEBRANCH=$(grep -Po "/tmp/${BASEIMAGENAME}/jenkins-vars.yml" -e "^release_tag: \K(.*)$" | tr -d '"') + if [[ "${BASEBRANCH}" != "${BASEIMAGETAG}" ]]; then + cd "/tmp/${BASEIMAGENAME}" || exit + git remote set-branches origin "${BASEIMAGETAG}" + git fetch --depth=1 + git checkout "${BASEIMAGETAG}" + fi fi fi @@ -58,13 +68,18 @@ while [[ ${BASEIMAGENAME} =~ "baseimage" ]]; do else BASELIST="\"${BASEIMAGE}\"" fi - git clone --depth=1 "https://github.com/linuxserver/docker-${BASEIMAGENAME}" "/tmp/${BASEIMAGENAME}" - BASEBRANCH=$(grep -Po "/tmp/${BASEIMAGENAME}/jenkins-vars.yml" -e "^release_tag: \K(.*)$" | tr -d '"') - if [[ "${BASEBRANCH}" != "${BASEIMAGETAG}" ]]; then - cd "/tmp/${BASEIMAGENAME}" || exit - git remote set-branches origin "${BASEIMAGETAG}" - git fetch --depth=1 - git checkout "${BASEIMAGETAG}" + if [[ -n ${LOCAL} ]]; then + mkdir -p "/tmp/${BASEIMAGENAME}" + cp -R "/input/docker-${BASEIMAGENAME}/"* "/tmp/${BASEIMAGENAME}/" + else + git clone --depth=1 "https://github.com/linuxserver/docker-${BASEIMAGENAME}" "/tmp/${BASEIMAGENAME}" + BASEBRANCH=$(grep -Po "/tmp/${BASEIMAGENAME}/jenkins-vars.yml" -e "^release_tag: \K(.*)$" | tr -d '"') + if [[ "${BASEBRANCH}" != "${BASEIMAGETAG}" ]]; then + cd "/tmp/${BASEIMAGENAME}" || exit + git remote set-branches origin "${BASEIMAGETAG}" + git fetch --depth=1 + git checkout "${BASEIMAGETAG}" + fi fi BASEIMAGE=$(grep "/tmp/${BASEIMAGENAME}/Dockerfile" -e "^FROM" | tail -1) BASEIMAGE=${BASEIMAGE##*/}