Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ochorocho committed Jun 6, 2024
0 parents commit 942ba10
Show file tree
Hide file tree
Showing 14 changed files with 325 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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: 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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea
11 changes: 11 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/ddev-dind.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# DDEV Docker in Docker (dind)


# ddev-docker
75 changes: 75 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions ddev-install.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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)"

0 comments on commit 942ba10

Please sign in to comment.