From 5ba15646218890e9b7b94106b86eb9720a0efcf8 Mon Sep 17 00:00:00 2001
From: Dariusz Janny <janny@man.poznan.pl>
Date: Thu, 21 Jan 2021 23:13:37 +0100
Subject: [PATCH] [#17] rebase faas-db and use Makefile.

---
 .gitignore               |  1 +
 Dockerfile               | 10 ++++++++++
 Makefile                 | 36 ++++++++++++++++++++++++++++++++++++
 README.md                | 22 +++++++++++++++-------
 conf/faas-db.cnf         |  9 +++++++--
 conf/faas-db.compose.yml | 15 ---------------
 scripts/build.sh         |  3 ---
 scripts/run.sh           |  3 ---
 8 files changed, 69 insertions(+), 30 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 Makefile
 delete mode 100644 conf/faas-db.compose.yml
 delete mode 100755 scripts/build.sh
 delete mode 100755 scripts/run.sh

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d8fe4fa
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/.project
diff --git a/Dockerfile b/Dockerfile
index 4de8215..cf62a18 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 0000000..e7a0ddc
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,36 @@
+# 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}
+
+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 db916d1..9c6fca5 100644
--- a/README.md
+++ b/README.md
@@ -2,20 +2,28 @@
 
 ## structure
 `_conf/`_ - directory with configuration files
-`scripts/` - directory with utils and scripts
 
 ## 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
+`
diff --git a/conf/faas-db.cnf b/conf/faas-db.cnf
index ab58617..e60dca3 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 a182374..0000000
--- 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 b1c82a0..0000000
--- 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 38268c8..0000000
--- 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
-- 
GitLab