diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d8fe4fa70f618843e9ab2df67167b49565c71f25 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.project diff --git a/Dockerfile b/Dockerfile index 4de8215caa0e70a36063e9db402a832617fb0470..cf62a183763fa2d5ec8a5cb4cdf9d8f9357b402d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,11 @@ FROM mariadb:10.5.8 + +ARG FAAS_DB_IMAGE +ARG FAAS_DB_NAME +ARG FAAS_DB_VERSION + +RUN echo $FAAS_DB_IMAGE > /faas-docker-image +RUN echo $FAAS_DB_NAME > /faas-docker-name +RUN echo $FAAS_DB_VERSION > /faas-docker-version + +EXPOSE 3306 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d5344941faf10788f62bd607b4d25d09f11dc673 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +# import config file +config ?= conf/faas-db.cnf +include $(config) +export $(shell sed 's/=.*//' $(config)) + + +.DEFAULT_GOAL := help + +clean: # clean DB docker volume + sudo rm -fr ${FAAS_DB_VOLUME_VAR_LIB_MYSQL} + +build: # build container + docker build -t ${FAAS_DB_IMAGE} --build-arg FAAS_DB_NAME=${FAAS_DB_NAME} --build-arg FAAS_DB_IMAGE=${FAAS_DB_IMAGE} --build-arg FAAS_DB_VERSION=${FAAS_DB_VERSION} . + +build-nc: # build container without caching + docker build --no-cache -t ${FAAS_DB_IMAGE} --build-arg FAAS_DB_NAME=${FAAS_DB_NAME} --build-arg FAAS_DB_IMAGE=${FAAS_DB_IMAGE} --build-arg FAAS_DB_VERSION=${FAAS_DB_VERSION} . + +run: # run container + docker run -i -t --detach --rm --env-file=$(config) -p=${FAAS_DB_PORT}:3306 --name="${FAAS_DB_NAME}" -v ${FAAS_DB_VOLUME_VAR_LIB_MYSQL}:/var/lib/mysql ${FAAS_DB_IMAGE} + +run-nd: # run container in no-deamon mode + docker run -i -t --rm --env-file=$(config) -p=${FAAS_DB_PORT}:3306 --name="${FAAS_DB_NAME}" -v ${FAAS_DB_VOLUME_VAR_LIB_MYSQL}:/var/lib/mysql ${FAAS_DB_IMAGE} + +up: build run # build and run container + +logs: # print docker logs + docker logs ${FAAS_DB_NAME} + +stop: # stop container + docker stop ${FAAS_DB_NAME} + +version: # print current component version + @echo ${FAAS_DB_VERSION} + +test: testFaasDB # run all tests + +testFaasDB: # run checking docker image tests + @echo "# run test version" + bats test/faas-db-tests.bats + +help: # this help + @awk 'BEGIN {FS = ":.*?# "} /^[a-zA-Z_-]+:.*?# / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) diff --git a/README.md b/README.md index db916d12f7b8498ecca0957868cd60a9d705e959..44f38bedf5f55e87dba92098eb8507230d106ba6 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,32 @@ ## structure `_conf/`_ - directory with configuration files -`scripts/` - directory with utils and scripts + +`test/` - directory with tests files ## build image -To build `faas-db` docker image +To build `faas-db` docker image ` -cd scripts && ./build.sh +make build ` - ## run image To run `faas-db` docker image ` -cd scripts && ./run.sh +make run ` - - +## additional commands +``` +clean clean DB docker volume +build build container +build-nc build container without caching +run run container +run-nd run container in no-deamon mode +up build and run container +logs print docker logs +stop stop container +version print current component version +test run all tests +testFaasDB run checking docker image tests +``` diff --git a/conf/faas-db.cnf b/conf/faas-db.cnf index ab58617555eb4e04f94163056527aae5c6f7708e..e60dca321a091b5b9d3f26196ba87dd7701ace32 100644 --- a/conf/faas-db.cnf +++ b/conf/faas-db.cnf @@ -1,6 +1,11 @@ -FAAS_DB_IMAGE=faas/faas-db:1.0-SNAPSHOT +FAAS_DB_REPO=faas +FAAS_DB_VERSION=1.0-SNAPSHOT +FAAS_DB_NAME=faas-db + +FAAS_DB_IMAGE=${FAAS_DB_REPO}/${FAAS_DB_NAME}:${FAAS_DB_VERSION} + FAAS_DB_VOLUME_VAR_LIB_MYSQL=/tmp/faas-db FAAS_DB_PORT=8306 # TODO - remove to external resource -FAAS_DB_ROOT_PASSWORD=secure +MYSQL_ROOT_PASSWORD=secure diff --git a/conf/faas-db.compose.yml b/conf/faas-db.compose.yml deleted file mode 100644 index a1823743eacdb4a879063087b95020900962450a..0000000000000000000000000000000000000000 --- a/conf/faas-db.compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '3.1' - -services: - db: - image: ${FAAS_DB_IMAGE} - build: - context: ../ - dockerfile: Dockerfile - restart: always - environment: - MYSQL_ROOT_PASSWORD: ${FAAS_DB_ROOT_PASSWORD} - volumes: - - ${FAAS_DB_VOLUME_VAR_LIB_MYSQL}:/var/lib/mysql - ports: - - "${FAAS_DB_PORT}:3306" diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index b1c82a0584e7dfe466d51944ffe0c88be800b085..0000000000000000000000000000000000000000 --- a/scripts/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/bash - -docker-compose --env-file ../conf/faas-db.cnf -f ../conf/faas-db.compose.yml build diff --git a/scripts/run.sh b/scripts/run.sh deleted file mode 100755 index 38268c8b8324327032cd6f2cebcee2411594fdd5..0000000000000000000000000000000000000000 --- a/scripts/run.sh +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/bash - -docker-compose --env-file ../conf/faas-db.cnf -f ../conf/faas-db.compose.yml up diff --git a/test/faas-db-tests.bats b/test/faas-db-tests.bats new file mode 100644 index 0000000000000000000000000000000000000000..41313a4b0d1d071dd884b8f64c50828051de08c9 --- /dev/null +++ b/test/faas-db-tests.bats @@ -0,0 +1,38 @@ +#! /usr/bin/env bats + +@test "faas-db - checking version in variables" { + [ $FAAS_DB_VERSION = "1.0-SNAPSHOT" ] +} + +@test "faas-db - checking app name in variables" { + [ $FAAS_DB_NAME = "faas-db" ] +} + +@test "faas-db - checking image string in variables" { + [ $FAAS_DB_IMAGE = "faas/faas-db:1.0-SNAPSHOT" ] +} + +@test "faas-db - checking version in image file" { + run docker exec $FAAS_DB_NAME bash -c 'cat /faas-docker-version' + [ "$output" = "1.0-SNAPSHOT" ] +} + +@test "faas-db - checking app name in image file" { + run docker exec $FAAS_DB_NAME bash -c 'cat /faas-docker-name' + [ "$output" = "faas-db" ] +} + +@test "faas-db - checking image string in image file" { + run docker exec $FAAS_DB_NAME bash -c 'cat /faas-docker-image' + [ "$output" = "faas/faas-db:1.0-SNAPSHOT" ] +} + +@test "faas-db - checking DB version in client command" { + run docker exec $FAAS_DB_NAME bash -c 'mysql --version' + [ "$output" = "mysql Ver 15.1 Distrib 10.5.8-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2" ] +} + +@test "faas-db - checking DB version in running DB instance" { + run docker exec $FAAS_DB_NAME bash -c "mysql --disable-column-names -uroot -p${MYSQL_ROOT_PASSWORD} mysql -e 'select version();'" + [ "$output" = "10.5.8-MariaDB-1:10.5.8+maria~focal" ] +}