Skip to content

Commit

Permalink
[TASK] Add testing
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
ochorocho committed Jul 7, 2024
1 parent 040a135 commit 18e86bb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 49 deletions.
25 changes: 12 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on:
branches:
- main
schedule:
- cron: "0 5 * * *"
- cron: "0 1 * * 1"

jobs:
build:
name: Build Container
name: Build and Push Container
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -21,9 +21,6 @@ jobs:
-
name: Docker info
run: docker info
-
name: Docker Builder
run: docker buildx ls
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -32,23 +29,25 @@ jobs:
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Setup BATS
-
name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.2.1

- name: Check out code
bats-version: 1.11.0
-
name: Check out code
uses: actions/checkout@v1

- name: "Test ddev ${{ matrix.version }} image"
-
name: "Test ddev ${{ matrix.version }} image"
shell: 'script -q -e -c "bash {0}"'
run: |
sudo snap install yq
./build.sh -v ${{ matrix.version }} -l
DDEV_VERSION=${{ matrix.version }} bash bats tests
-
name: "ddev ${{ matrix.version }}"
name: "Build ddev ${{ matrix.version }} multi-arch image"
shell: 'script -q -e -c "bash {0}"'
run: |
echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
docker buildx create --use --platform=linux/arm64,linux/amd64
./build.sh -v ${{ matrix.version }} -p
./build.sh -v ${{ matrix.version }} -x -p
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '!main'
jobs:
build:
name: Build Container
name: Build and Test Container
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -20,9 +20,6 @@ jobs:
-
name: Docker info
run: docker info
-
name: Docker Builder
run: docker buildx ls
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -31,9 +28,6 @@ jobs:
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
-
name: Setup yq
uses: mikefarah/yq@master
-
name: Setup BATS
uses: mig4/setup-bats@v1
Expand All @@ -46,5 +40,6 @@ jobs:
name: "Test ddev ${{ matrix.version }} image"
shell: 'script -q -e -c "bash {0}"'
run: |
sudo snap install yq
./build.sh -v ${{ matrix.version }} -l
DDEV_VERSION=${{ matrix.version }} bash bats tests
26 changes: 6 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Available options:
* v - DDEV version e.g. 'v1.23.1'
* l - Load the image (--load)
* p - Push the image (--push)
* x - Build multi-arch image (--platform linux/amd64,linux/arm64)

## Version to tags

Expand All @@ -27,26 +28,11 @@ Available options:
| ./build.sh -v v1.23 | v1.23, v1.23.x (latest bugfix) |
| ... | ... |

## Run tests locally

## TEST
Requires [bats-core](https://bats-core.readthedocs.io/en/stable/installation.html) and [yq](https://github.com/mikefarah/yq/tree/v4.44.2?tab=readme-ov-file#install).

Any good to disable TLS?!

```bash
NETWORK="ddev-docker"
if docker network inspect "$NETWORK" &>/dev/null; then
echo "Network '$NETWORK' already exists."
else
echo "Creating network '$NETWORK'."
docker network create "$NETWORK"
fi

# Get DinD ready - need privileged mode?!?!?
# WORKING::: docker run --privileged -e DOCKER_TLS_CERTDIR="" --name ddev-dind -d --network ddev-docker --network-alias docker docker:dind
docker run --privileged -e DOCKER_TLS_CERTDIR="" --name ddev-dind -d --network ddev-docker --network-alias docker docker:dind-rootless

# Wait till DinD is ready

# Run ddev/docker related commands - - -e DOCKER_HOST="tcp://docker:2375/"
docker run --rm -it --network ddev-docker ghcr.io/ochorocho/ddev-gitlab-ci:v1.23.3 version
```
DDEV_VERSION=v1.23.3 bash bats tests
```

13 changes: 6 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ help() {
echo " * v - DDEV version e.g. 'v1.23.1'"
echo " * l - Load the image (--load)"
echo " * p - Push the image (--push)"
echo " * x - Build multi-arch image (--platform linux/amd64,linux/arm64)"
}

loadVersionAndTags() {
Expand Down Expand Up @@ -49,7 +50,7 @@ loadVersionAndTags() {
fi
}

while getopts ":v:hpl" opt; do
while getopts ":v:hplx" opt; do
case $opt in
h)
help
Expand All @@ -64,6 +65,9 @@ while getopts ":v:hpl" opt; do
l)
LOAD="--load"
;;
x)
PLATFORM="--platform linux/amd64,linux/arm64"
;;
*)
echo "Invalid option: -$OPTARG"
help
Expand All @@ -74,9 +78,4 @@ done

loadVersionAndTags

docker buildx build --platform linux/amd64,linux/arm64 --progress plain --no-cache --pull . -f Dockerfile ${DOCKER_TAGS[@]} --build-arg ddev_version="$DDEV_VERSION" $PUSH $LOAD

if [ $LOAD ]; then
docker run --rm -it -v "$(pwd)/test.sh:/tmp/test.sh" --entrypoint "ash" "$IMAGE_NAME:$DDEV_VERSION" /tmp/test.sh
fi

docker buildx build ${PLATFORM} --progress plain --no-cache --pull . -f Dockerfile ${DOCKER_TAGS[@]} --build-arg ddev_version="$DDEV_VERSION" $PUSH $LOAD
4 changes: 2 additions & 2 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@test "See ddev version" {
run docker-run "ddev version -j"

version=$(echo "$output" | head -2 | tail -1 | yq '.raw.["DDEV version"]')
version=$(echo "$output" | tail -n 1 | yq '.raw.["DDEV version"]')
regex='^v([0-9]+)\.([0-9]+)\.([0-9]+)$'

[[ $version =~ $regex ]]
Expand Down Expand Up @@ -71,6 +71,6 @@

docker-run() {
local COMMAND=${1}
# @todo: Pass in the current version

docker run --rm -it --network ddev-docker ghcr.io/ochorocho/ddev-gitlab-ci:"${DDEV_VERSION}" /bin/sh -c "${COMMAND}"
}

0 comments on commit 18e86bb

Please sign in to comment.