Skip to content

Commit 18e86bb

Browse files
committed
[TASK] Add testing
Fixes #2
1 parent 040a135 commit 18e86bb

File tree

5 files changed

+28
-49
lines changed

5 files changed

+28
-49
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ on:
55
branches:
66
- main
77
schedule:
8-
- cron: "0 5 * * *"
8+
- cron: "0 1 * * 1"
99

1010
jobs:
1111
build:
12-
name: Build Container
12+
name: Build and Push Container
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
@@ -21,9 +21,6 @@ jobs:
2121
-
2222
name: Docker info
2323
run: docker info
24-
-
25-
name: Docker Builder
26-
run: docker buildx ls
2724
-
2825
name: Set up QEMU
2926
uses: docker/setup-qemu-action@v3
@@ -32,23 +29,25 @@ jobs:
3229
uses: docker/setup-buildx-action@v3
3330
with:
3431
platforms: linux/amd64,linux/arm64
35-
- name: Setup BATS
32+
-
33+
name: Setup BATS
3634
uses: mig4/setup-bats@v1
3735
with:
38-
bats-version: 1.2.1
39-
40-
- name: Check out code
36+
bats-version: 1.11.0
37+
-
38+
name: Check out code
4139
uses: actions/checkout@v1
42-
43-
- name: "Test ddev ${{ matrix.version }} image"
40+
-
41+
name: "Test ddev ${{ matrix.version }} image"
4442
shell: 'script -q -e -c "bash {0}"'
4543
run: |
44+
sudo snap install yq
4645
./build.sh -v ${{ matrix.version }} -l
4746
DDEV_VERSION=${{ matrix.version }} bash bats tests
4847
-
49-
name: "ddev ${{ matrix.version }}"
48+
name: "Build ddev ${{ matrix.version }} multi-arch image"
5049
shell: 'script -q -e -c "bash {0}"'
5150
run: |
5251
echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
5352
docker buildx create --use --platform=linux/arm64,linux/amd64
54-
./build.sh -v ${{ matrix.version }} -p
53+
./build.sh -v ${{ matrix.version }} -x -p

.github/workflows/test.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- '!main'
99
jobs:
1010
build:
11-
name: Build Container
11+
name: Build and Test Container
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
@@ -20,9 +20,6 @@ jobs:
2020
-
2121
name: Docker info
2222
run: docker info
23-
-
24-
name: Docker Builder
25-
run: docker buildx ls
2623
-
2724
name: Set up QEMU
2825
uses: docker/setup-qemu-action@v3
@@ -31,9 +28,6 @@ jobs:
3128
uses: docker/setup-buildx-action@v3
3229
with:
3330
platforms: linux/amd64,linux/arm64
34-
-
35-
name: Setup yq
36-
uses: mikefarah/yq@master
3731
-
3832
name: Setup BATS
3933
uses: mig4/setup-bats@v1
@@ -46,5 +40,6 @@ jobs:
4640
name: "Test ddev ${{ matrix.version }} image"
4741
shell: 'script -q -e -c "bash {0}"'
4842
run: |
43+
sudo snap install yq
4944
./build.sh -v ${{ matrix.version }} -l
5045
DDEV_VERSION=${{ matrix.version }} bash bats tests

README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Available options:
1717
* v - DDEV version e.g. 'v1.23.1'
1818
* l - Load the image (--load)
1919
* p - Push the image (--push)
20+
* x - Build multi-arch image (--platform linux/amd64,linux/arm64)
2021

2122
## Version to tags
2223

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

31+
## Run tests locally
3032

31-
## TEST
33+
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).
3234

33-
Any good to disable TLS?!
34-
35-
```bash
36-
NETWORK="ddev-docker"
37-
if docker network inspect "$NETWORK" &>/dev/null; then
38-
echo "Network '$NETWORK' already exists."
39-
else
40-
echo "Creating network '$NETWORK'."
41-
docker network create "$NETWORK"
42-
fi
43-
44-
# Get DinD ready - need privileged mode?!?!?
45-
# WORKING::: docker run --privileged -e DOCKER_TLS_CERTDIR="" --name ddev-dind -d --network ddev-docker --network-alias docker docker:dind
46-
docker run --privileged -e DOCKER_TLS_CERTDIR="" --name ddev-dind -d --network ddev-docker --network-alias docker docker:dind-rootless
47-
48-
# Wait till DinD is ready
49-
50-
# Run ddev/docker related commands - - -e DOCKER_HOST="tcp://docker:2375/"
51-
docker run --rm -it --network ddev-docker ghcr.io/ochorocho/ddev-gitlab-ci:v1.23.3 version
5235
```
36+
DDEV_VERSION=v1.23.3 bash bats tests
37+
```
38+

build.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ help() {
1515
echo " * v - DDEV version e.g. 'v1.23.1'"
1616
echo " * l - Load the image (--load)"
1717
echo " * p - Push the image (--push)"
18+
echo " * x - Build multi-arch image (--platform linux/amd64,linux/arm64)"
1819
}
1920

2021
loadVersionAndTags() {
@@ -49,7 +50,7 @@ loadVersionAndTags() {
4950
fi
5051
}
5152

52-
while getopts ":v:hpl" opt; do
53+
while getopts ":v:hplx" opt; do
5354
case $opt in
5455
h)
5556
help
@@ -64,6 +65,9 @@ while getopts ":v:hpl" opt; do
6465
l)
6566
LOAD="--load"
6667
;;
68+
x)
69+
PLATFORM="--platform linux/amd64,linux/arm64"
70+
;;
6771
*)
6872
echo "Invalid option: -$OPTARG"
6973
help
@@ -74,9 +78,4 @@ done
7478

7579
loadVersionAndTags
7680

77-
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
78-
79-
if [ $LOAD ]; then
80-
docker run --rm -it -v "$(pwd)/test.sh:/tmp/test.sh" --entrypoint "ash" "$IMAGE_NAME:$DDEV_VERSION" /tmp/test.sh
81-
fi
82-
81+
docker buildx build ${PLATFORM} --progress plain --no-cache --pull . -f Dockerfile ${DOCKER_TAGS[@]} --build-arg ddev_version="$DDEV_VERSION" $PUSH $LOAD

tests/test.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@test "See ddev version" {
1414
run docker-run "ddev version -j"
1515

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

1919
[[ $version =~ $regex ]]
@@ -71,6 +71,6 @@
7171

7272
docker-run() {
7373
local COMMAND=${1}
74-
# @todo: Pass in the current version
74+
7575
docker run --rm -it --network ddev-docker ghcr.io/ochorocho/ddev-gitlab-ci:"${DDEV_VERSION}" /bin/sh -c "${COMMAND}"
7676
}

0 commit comments

Comments
 (0)