Skip to content

Commit

Permalink
Merge pull request #100 from SemanticMediaWiki/docker-compose-ci
Browse files Browse the repository at this point in the history
Docker compose ci
  • Loading branch information
gesinn-it-evl authored Oct 19, 2023
2 parents 12aca7d + 7f27311 commit ae00dac
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 228 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Run tests
run: make ci
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "build"]
path = build
url = [email protected]:gesinn-it-pub/docker-compose-ci.git
29 changes: 0 additions & 29 deletions Dockerfile

This file was deleted.

176 changes: 20 additions & 156 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,168 +1,32 @@
-include .env
export

# ======== Naming ========
EXTENSION := Mermaid
EXTENSION_FOLDER := /var/www/html/extensions/$(EXTENSION)
extension := $(shell echo $(EXTENSION) | tr A-Z a-z})
IMAGE_NAME := $(extension):test-$(MW_VERSION)-$(SMW_VERSION)-$(PS_VERSION)-$(AL_VERSION)-$(MAPS_VERSION)-$(SRF_VERSION)
# setup for docker-compose-ci build directory
# delete "build" directory to update docker-compose-ci


# ======== CI ENV Variables ========
MW_VERSION ?= 1.35
SMW_VERSION ?= 4.1.2
PHP_VERSION ?= 7.4
DB_TYPE ?= sqlite
DB_IMAGE ?= ""


environment = IMAGE_NAME=$(IMAGE_NAME) \
MW_VERSION=$(MW_VERSION) \
SMW_VERSION=$(SMW_VERSION) \
PHP_VERSION=$(PHP_VERSION) \
DB_TYPE=$(DB_TYPE) \
DB_IMAGE=$(DB_IMAGE) \
EXTENSION_FOLDER=$(EXTENSION_FOLDER)


ifneq (,$(wildcard ./docker-compose.override.yml))
COMPOSE_OVERRIDE=-f docker-compose.override.yml
ifeq (,$(wildcard ./build/))
$(shell git submodule update --init --remote)
endif

EXTENSION=Mermaid

compose = $(environment) docker-compose $(COMPOSE_OVERRIDE) $(COMPOSE_ARGS)
compose-ci = $(environment) docker-compose -f docker-compose.yml -f docker-compose-ci.yml $(COMPOSE_OVERRIDE) $(COMPOSE_ARGS)
compose-dev = $(environment) docker-compose -f docker-compose.yml -f docker-compose-dev.yml $(COMPOSE_OVERRIDE) $(COMPOSE_ARGS)

compose-run = $(compose) run -T --rm
compose-exec-wiki = $(compose) exec -T wiki

show-current-target = @echo; echo "======= $@ ========"

# ======== CI ========
# ======== Global Targets ========

.PHONY: ci
ci: install composer-test

.PHONY: ci-coverage
ci-coverage: install composer-test-coverage

.PHONY: install
install: destroy up .install

.PHONY: up
up: .init .build .up

.PHONY: down
down: .init .down

.PHONY: destroy
destroy: .init .destroy

.PHONY: bash
bash: up .bash

# ======== General Docker-Compose Helper Targets ========
# docker images
MW_VERSION?=1.35
PHP_VERSION?=7.4
DB_TYPE?=sqlite
DB_IMAGE?=""

.PHONY: .build
.build:
$(show-current-target)
$(compose-ci) build wiki
.PHONY: .up
.up:
$(show-current-target)
$(compose-ci) up -d
# extensions
SMW_VERSION?=4.1.2

.PHONY: .install
.install: .wait-for-db
$(show-current-target)
$(compose-exec-wiki) bash -c "sudo -u www-data \
php maintenance/install.php \
--pass=wiki4everyone --server=http://localhost:8080 --scriptpath='' \
--dbname=wiki --dbuser=wiki --dbpass=wiki $(WIKI_DB_CONFIG) wiki WikiSysop && \
cat __setup_extension__ >> LocalSettings.php && \
sudo -u www-data php maintenance/update.php --skip-external-dependencies --quick \
"
# composer
# Enables "composer update" inside of extension
COMPOSER_EXT?=true

.PHONY: .down
.down:
$(show-current-target)
$(compose-ci) down
# nodejs
# Enables node.js related tests and "npm install"
# NODE_JS?=true

.PHONY: .destroy
.destroy:
$(show-current-target)
$(compose-ci) down -v

.PHONY: .bash
.bash: .init
$(show-current-target)
$(compose-exec-wiki) bash -c "cd $(EXTENSION_FOLDER) && bash"

# ======== Test Targets ========

.PHONY: composer-test
composer-test:
$(show-current-target)
$(compose-exec-wiki) bash -c "cd $(EXTENSION_FOLDER) && composer phpunit"

.PHONY: composer-test-coverage
composer-test-coverage:
$(show-current-target)
$(compose-exec-wiki) bash -c "cd $(EXTENSION_FOLDER) && composer phpunit-coverage"

# ======== Dev Targets ========

.PHONY: dev-bash
dev-bash: .init
$(compose-dev) run -it wiki bash -c 'service apache2 start && bash'

.PHONY: run
run:
$(compose-dev) -f docker-compose-dev.yml run -it wiki

# ======== Releasing ========
VERSION = `node -e 'console.log(require("./extension.json").version)'`

.PHONY: release
release: ci git-push gh-login
gh release create $(VERSION)

.PHONY: git-push
git-push:
git diff --quiet || (echo 'git directory has changes'; exit 1)
git push

.PHONY: gh-login
gh-login: require-GH_API_TOKEN
gh config set prompt disabled
@echo $(GH_API_TOKEN) | gh auth login --with-token

.PHONY: require-GH_API_TOKEN
require-GH_API_TOKEN:
ifndef GH_API_TOKEN
$(error GH_API_TOKEN is not set)
endif


# ======== Helpers ========
.PHONY: .init
.init:
$(show-current-target)
$(eval COMPOSE_ARGS = --project-name ${extension}-$(DB_TYPE) --profile $(DB_TYPE))
ifeq ($(DB_TYPE), sqlite)
$(eval WIKI_DB_CONFIG = --dbtype=$(DB_TYPE) --dbpath=/tmp/sqlite)
else
$(eval WIKI_DB_CONFIG = --dbtype=$(DB_TYPE) --dbserver=$(DB_TYPE) --installdbuser=root --installdbpass=database)
endif
@echo "COMPOSE_ARGS: $(COMPOSE_ARGS)"
# check for build dir and git submodule init if it does not exist
include build/Makefile

.PHONY: .wait-for-db
.wait-for-db:
$(show-current-target)
ifeq ($(DB_TYPE), mysql)
$(compose-run) wait-for $(DB_TYPE):3306 -t 120
else ifeq ($(DB_TYPE), postgres)
$(compose-run) wait-for $(DB_TYPE):5432 -t 120
endif
1 change: 1 addition & 0 deletions build
Submodule build added at 91d005
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
}
},
"scripts":{
"test": [
"@phpunit"
],
"test-coverage": [
"@phpunit-coverage"
],
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist",
"phpunit-coverage": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox --coverage-text --coverage-html coverage/php --coverage-clover coverage/php/coverage.xml",
"phpdbg": "phpdbg -qrr ../../tests/phpunit/phpunit.php -c phpunit.xml.dist",
"test": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist"
"phpdbg": "phpdbg -qrr ../../tests/phpunit/phpunit.php -c phpunit.xml.dist"
}
}
4 changes: 0 additions & 4 deletions docker-compose-ci.yml

This file was deleted.

8 changes: 0 additions & 8 deletions docker-compose-dev.yml

This file was deleted.

29 changes: 0 additions & 29 deletions docker-compose.yml

This file was deleted.

0 comments on commit ae00dac

Please sign in to comment.