From 6a5e70ccf2b85bf7c484a08dbea34dbd5c20053d Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 16 Feb 2018 01:49:02 +0100 Subject: [PATCH] First commit --- .gitignore | 2 ++ Makefile | 35 +++++++++++++++++++++++++++++++++++ docker/include/mariadb | 4 ++++ docker/main | 19 +++++++++++++++++++ virtual/bootloader | 15 +++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 docker/include/mariadb create mode 100644 docker/main create mode 100644 virtual/bootloader diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0d0047 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/Dockerfile +/mount/* \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7d86729 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +IMAGE_NAME="alp-mdb" + +build: clean Dockerfile + @echo -n "> Building image..............."; + docker build --force-rm -t $(IMAGE_NAME) . && echo "done" || echo "error"; + +Dockerfile: docker/main docker/include/* + @echo -n "> Building file Dockerfile....."; + @cpp -o Dockerfile docker/main && echo "done" || echo "error"; + +clean: + @echo -n "> Stopping containers.........."; + @docker stop inst1; + @docker rm -flv inst1; + @echo -n "> Deleting docker image........"; + @docker rmi -f $(IMAGE_NAME) && echo "done" || echo "failed"; + @echo -n "> Deleting Dockerfile.........."; + @rm Dockerfile && echo "done" || echo "failed"; + +boot: + @while true; do \ + echo "*** 1. Updating virtual environment"; \ + git pull origin stable; \ + echo "*** 2. Building image"; \ + make build; \ + echo "*** 3. Launching container"; \ + docker run --name inst1 $(IMAGE_NAME); \ + echo "*** 4. Deleting container"; \ + docker stop inst1; \ + docker rm -flv inst1; \ + sleep 2; \ + done; + +kill: + @docker exec -ti inst1 sh -c 'rm boot.lock'; \ No newline at end of file diff --git a/docker/include/mariadb b/docker/include/mariadb new file mode 100644 index 0000000..72c7433 --- /dev/null +++ b/docker/include/mariadb @@ -0,0 +1,4 @@ +RUN apk add mariadb mariadb-client \ /* 1. install mariadb */ +&& mysql_install_db --user=mysql \ /* 2. install database */ +&& sh -c 'mysqld_safe& sleep 1' \ /* 3. Start mysql for password changing */ +&& mysqladmin -u root password 'root' /* 4. set arbitrary root password */ \ No newline at end of file diff --git a/docker/main b/docker/main new file mode 100644 index 0000000..4df4f76 --- /dev/null +++ b/docker/main @@ -0,0 +1,19 @@ +/* 1. Base image */ +FROM alpine +MAINTAINER xdrm-brackets + +/* 2. Update package manager */ +RUN apk update + + +/************************************ +************** MariaDB ************** +************************************/ +#include "./include/mariadb" + + +/************************************ +********** Set Bootloader *********** +************************************/ +COPY virtual/bootloader /bootloader +CMD export USER=ROOT; sh /bootloader diff --git a/virtual/bootloader b/virtual/bootloader new file mode 100644 index 0000000..c9dfdef --- /dev/null +++ b/virtual/bootloader @@ -0,0 +1,15 @@ +#!/bin/bash + +# 1. Start mysql +nohup mysqld_safe > /var/log/mysql_log & + + + + + +# 10. Create lock file +touch /boot.lock; +chmod 777 /boot.lock; + +# 11. Run while lock exists +while [ -f /boot.lock ]; do sleep 1; done; \ No newline at end of file