diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3f6455a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,44 @@ +name: Build + +on: + push: + branches: + - main + schedule: + - cron: "0 4 * * *" + +jobs: + build: + name: Build Container + runs-on: ubuntu-latest + strategy: + matrix: + version: [ v1.23, v1.22 ] + steps: + - + name: Checkout code + uses: actions/checkout@v3 + - + name: Install composer + uses: php-actions/composer@v6 + - + name: Docker info + run: docker info + - + name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + platforms: linux/amd64,linux/arm64 + - + name: "ddev ${{ matrix.version }}" + shell: 'script -q -e -c "bash {0}"' + run: ./build.sh -v ${{ matrix.version }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..e1de4e4 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,11 @@ + +ddev-initialize: + stage: project-template-test + image: ochorocho/ochorocho/ddev-docker:v1.23.1 + services: + - name: docker:dind + when: always + script: + - su ddev -c "ddev --version" + - su ddev -c "ddev typo3-init" + - su ddev -c "ddev restart" diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..a09c56d --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1 @@ +/.idea diff --git a/.idea/ddev-dind.iml b/.idea/ddev-dind.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/ddev-dind.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..fa7fe28 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..f324872 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..3843949 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + { + "associatedIndex": 7 +} + + + + { + "keyToString": { + "RunOnceActivity.ShowReadmeOnStart": "true", + "last_opened_file_path": "/Users/jochen/Development/ddev-dind", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" + } +} + + + + + + + + + + + + + + + + + 1717618198507 + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e40ea63 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM docker:latest + +ARG ddev_version +ENV DDEV_VERSION=${ddev_version} + +COPY ddev-install.sh ddev-install.sh +RUN ash ddev-install.sh +USER ddev +RUN mkcert -install diff --git a/README.md b/README.md new file mode 100644 index 0000000..04f32e3 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# DDEV Docker in Docker (dind) + + +# ddev-docker diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..fd00cf1 --- /dev/null +++ b/build.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +GITHUB_OWNER=ddev +PUSH="" +IMAGE_NAME="ochorocho/ddev-docker" +DDEV_VERSION="" + +# @todo: +# * Allow version v1.23 -> v1.23 +# * --push --load options +# * Use bats for tests?! + +help() { + echo "Available options:" + echo " * v - DDEV version e.g. 'v1.23.1'" + echo " * l - Load the image (--load)" + echo " * p - Push the image (--push)" +} + +loadVersionAndTags() { + # @todo: Currently limited to 99 releases, may use pagination + ddev_releases=($(curl --silent -L -H "Accept: application/vnd.github+json" https://api.github.com/repos/${GITHUB_OWNER}/ddev/releases?per_page=99 | jq -r '.[].tag_name')) + + IFS='.' read -r -a version <<< "$OPTION_VERSION" + bugfix_release="${version[2]}" + + if [[ "${version[2]}" == "" ]]; then + bugfix_release="[0-9]+" + # Add minor tag version. In cas only major.minor is given, it will be tagged as well + additional_tag="${version[0]}.${version[1]}" + fi + + pattern="^${version[0]}\.${version[1]}\.${bugfix_release}$" + filtered_array=() + + for element in "${ddev_releases[@]}"; do + if [[ $element =~ $pattern ]]; then + filtered_array+=("$element") + fi + done + + DDEV_VERSION="${filtered_array[0]}" + + # Define image tags + if [[ $additional_tag == "" ]]; then + DOCKER_TAGS=("-t $IMAGE_NAME:${DDEV_VERSION}") + else + DOCKER_TAGS=("-t $IMAGE_NAME:$additional_tag" "-t $IMAGE_NAME:$DDEV_VERSION") + fi +} + +while getopts ":v:h:p" opt; do + case $opt in + h) + help + exit 1 + ;; + v) + OPTION_VERSION="${OPTARG}" + ;; + p) + PUSH="--push" + ;; + *) + echo "Invalid option: -$OPTARG" + help + exit 1 + ;; + esac +done + +loadVersionAndTags + +docker build --progress plain --platform linux/amd64,linux/arm64 --no-cache --pull . -f Dockerfile ${DOCKER_TAGS[@]} --build-arg ddev_version="$DDEV_VERSION" --load $PUSH && \ +docker run --rm -it -v "$(pwd)/test.sh:/tmp/test.sh" --entrypoint "ash" "$IMAGE_NAME:$DDEV_VERSION" /tmp/test.sh diff --git a/ddev-install.sh b/ddev-install.sh new file mode 100755 index 0000000..e5a75e6 --- /dev/null +++ b/ddev-install.sh @@ -0,0 +1,31 @@ +#!/usr/bin/ash + +apk add bash sudo +adduser -D ddev -g "ddev" -s /bin/bash -D ddev -h /home/ddev +echo "ddev ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/ddev && chmod 0440 /etc/sudoers.d/ddev +unamearch=$(uname -m) +case ${unamearch} in + x86_64) ARCH="amd64"; +;; + aarch64) ARCH="arm64"; +;; + arm64) ARCH="arm64" +;; +*) printf "${RED}Sorry, your machine architecture ${unamearch} is not currently supported.\n${RESET}" && exit 106 +;; +esac + +echo "https://github.com/ddev/ddev/releases/download/${DDEV_VERSION}/ddev_linux-${ARCH}.${DDEV_VERSION}.tar.gz" + +wget "https://github.com/ddev/ddev/releases/download/${DDEV_VERSION}/ddev_linux-${ARCH}.${DDEV_VERSION}.tar.gz" +tar xfvz "ddev_linux-${ARCH}.${DDEV_VERSION}.tar.gz" +mv ddev /usr/local/bin/ + +# Ensure required folders exist +mkdir -p /home/ddev/.ddev/commands/host +chown -R ddev:ddev /home/ddev/.ddev/ + +# Install mkcert +wget "https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-${ARCH}" +mv "mkcert-v1.4.4-linux-${ARCH}" /usr/local/bin/mkcert +chmod +x /usr/local/bin/mkcert diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..cd56ea6 --- /dev/null +++ b/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker --version | head -n 1 || exit 1 +docker-compose --version | head -n 1 || exit 1 +ddev --version | head -n 1 || exit 1 +mkcert -version +echo "Current user: $(whoami)"