From e4e5b0c1ff70aaf3110ea2b1132b61e31057d4d1 Mon Sep 17 00:00:00 2001 From: Marius Klocke Date: Sat, 17 Jul 2021 00:28:00 +0200 Subject: [PATCH 1/4] Use plain docker in build.sh --- build.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/build.sh b/build.sh index 291bef29..7fb51287 100755 --- a/build.sh +++ b/build.sh @@ -12,34 +12,40 @@ fi echo "TAG: ${TAG}" # Pull images -TAG=$TAG docker-compose -f docker-compose.build.yml pull +docker pull mariadb:10.4 +docker pull redis:5-alpine +docker pull mklocke/liga-manager-api:$TAG # Build images -TAG=$TAG docker-compose -f docker-compose.build.yml build +docker build -f docker/php/Dockerfile . cleanup() { echo 'Cleanup: Removing containers ...' - TAG=$TAG docker-compose -f docker-compose.build.yml down -v + docker rm -f php mariadb redis + docker network rm build } # Make sure we clean up running containers in case of error trap cleanup EXIT # Launch containers -TAG=$TAG docker-compose -f docker-compose.build.yml up -d +docker network create build +docker run -d --name=mariadb --network=build --env-file=build.env mariadb:10.4 +docker run -d --name=redis --network=build redis:5-alpine +docker run -d --name=php --network=build --env-file=build.env mklocke/liga-manager-api # Run deptrac -TAG=$TAG docker-compose -f docker-compose.build.yml exec -T php bin/deptrac.phar --no-progress +docker exec -t php bin/deptrac.phar --no-progress # Run tests without coverage -TAG=$TAG docker-compose -f docker-compose.build.yml exec -T php run-tests.sh +docker exec -t php run-tests.sh if [[ ! -z "${CI}" ]]; then # Enable xdebug - TAG=$TAG docker-compose -f docker-compose.build.yml exec -T -u root php docker-php-ext-enable xdebug + docker exec -t -u root php docker-php-ext-enable xdebug # Run tests with coverage - TAG=$TAG docker-compose -f docker-compose.build.yml exec -T -e COVERAGE_REPORT=1 -e COVERALLS_RUN_LOCALLY -e COVERALLS_REPO_TOKEN php run-tests.sh + docker exec -t -e COVERAGE_REPORT=1 -e COVERALLS_RUN_LOCALLY -e COVERALLS_REPO_TOKEN php run-tests.sh # Login to docker hub echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin From 1bf630cbfc896136017589c607dbbe744f94c007 Mon Sep 17 00:00:00 2001 From: Marius Klocke Date: Sat, 17 Jul 2021 00:32:54 +0200 Subject: [PATCH 2/4] Remove docker-compose.build.yml --- docker-compose.build.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 docker-compose.build.yml diff --git a/docker-compose.build.yml b/docker-compose.build.yml deleted file mode 100644 index 3ccff4f3..00000000 --- a/docker-compose.build.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: '3' -services: - php: - image: mklocke/liga-manager-api:$TAG - build: - context: . - dockerfile: docker/php/Dockerfile - depends_on: - - mariadb - - redis - env_file: - - build.env - - mariadb: - image: mariadb:10.4 - env_file: - - build.env - - redis: - image: redis:5-alpine From 8b70d050131749eb3202bf6f14df5724c131eb15 Mon Sep 17 00:00:00 2001 From: Marius Klocke Date: Sat, 17 Jul 2021 00:38:00 +0200 Subject: [PATCH 3/4] Use --cache-from option in build.sh --- build.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 7fb51287..818add77 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -echo "GITHUB_REF: ${GITHUB_REF}" +IMAGE="mklocke/liga-manager-api" if [[ $GITHUB_REF == *"refs/tags"* ]]; then TAG=$(sed 's#refs/tags/##' <<< "${GITHUB_REF}") @@ -9,15 +9,17 @@ else TAG="latest" fi +echo "GITHUB_REF: ${GITHUB_REF}" +echo "IMAGE: ${IMAGE}" echo "TAG: ${TAG}" # Pull images docker pull mariadb:10.4 docker pull redis:5-alpine -docker pull mklocke/liga-manager-api:$TAG +docker pull $IMAGE:$TAG # Build images -docker build -f docker/php/Dockerfile . +docker build -f docker/php/Dockerfile -t $IMAGE:$TAG --cache-from $IMAGE:$TAG . cleanup() { echo 'Cleanup: Removing containers ...' @@ -32,7 +34,7 @@ trap cleanup EXIT docker network create build docker run -d --name=mariadb --network=build --env-file=build.env mariadb:10.4 docker run -d --name=redis --network=build redis:5-alpine -docker run -d --name=php --network=build --env-file=build.env mklocke/liga-manager-api +docker run -d --name=php --network=build --env-file=build.env $IMAGE:$TAG # Run deptrac docker exec -t php bin/deptrac.phar --no-progress @@ -51,5 +53,5 @@ if [[ ! -z "${CI}" ]]; then echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin # Push image to docker hub - docker push mklocke/liga-manager-api:$TAG + docker push $IMAGE:$TAG fi From 4f89758a0660948967378d3e46d93d6ecc74ab9f Mon Sep 17 00:00:00 2001 From: Marius Klocke Date: Sun, 18 Jul 2021 12:45:10 +0200 Subject: [PATCH 4/4] Always cache from "latest" tag --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 818add77..64d9e242 100755 --- a/build.sh +++ b/build.sh @@ -19,7 +19,7 @@ docker pull redis:5-alpine docker pull $IMAGE:$TAG # Build images -docker build -f docker/php/Dockerfile -t $IMAGE:$TAG --cache-from $IMAGE:$TAG . +docker build -f docker/php/Dockerfile -t $IMAGE:$TAG --cache-from $IMAGE:latest . cleanup() { echo 'Cleanup: Removing containers ...'