From d922781ef41e3b426ed93e67823763a55ba8e731 Mon Sep 17 00:00:00 2001 From: Jonny Ervine Date: Wed, 19 Feb 2020 03:26:21 +0000 Subject: [PATCH 1/4] new file: Dockerfile new file: Jenkinsfile new file: files/run.sh Initial commit --- Dockerfile | 16 +++++++++++ Jenkinsfile | 17 ++++++++++++ files/run.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 files/run.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6c917fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM harbor.ervine.dev/library/x86_64/alpine/alpine-3.11 +LABEL maintainer "Jonathan Ervine " architecture="x86_64" version="10.3.15-r0" date="05022020" + +RUN apk --no-cache --update add mariadb mariadb-client pwgen && \ + rm -f /var/cache/apk/* + +ADD files/run.sh /scripts/run.sh +RUN mkdir /scripts/pre-exec.d && \ + mkdir /scripts/pre-init.d && \ + chmod -R 755 /scripts + +EXPOSE 3306 + +VOLUME ["/var/lib/mysql"] + +ENTRYPOINT ["/scripts/run.sh"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..1955caa --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,17 @@ +node("docker-node") { + docker.withRegistry('https://harbor.ervine.dev', 'jenkins-to-harbor') { + + git branch: "3.11.3", url: "ssh://git@gogs.ervine.org:2022/jonny/x86_64-alpine-mariadb", credentialsId: 'jenkins-to-gogs' + + sh "git rev-parse HEAD > .git/commit-id" + def commit_id = readFile('.git/commit-id').trim() + println commit_id + + stage "build" + def app = docker.build "library/x86_64/alpine/mariadb" + + stage "publish" + app.push("${env.BUILD_NUMBER}") + app.push("latest") + } +} diff --git a/files/run.sh b/files/run.sh new file mode 100644 index 0000000..a421cdd --- /dev/null +++ b/files/run.sh @@ -0,0 +1,75 @@ +#!/bin/sh +# execute any pre-init scripts +for i in /scripts/pre-init.d/*sh +do + if [ -e "${i}" ]; then + echo "[i] pre-init.d - processing $i" + . "${i}" + fi +done + +if [ -d "/run/mysqld" ]; then + echo "[i] mysqld already present, skipping creation" + chown -R mysql:mysql /run/mysqld +else + echo "[i] mysqld not found, creating...." + mkdir -p /run/mysqld + chown -R mysql:mysql /run/mysqld +fi + +if [ -d /var/lib/mysql/mysql ]; then + echo "[i] MySQL directory already present, skipping creation" + chown -R mysql:mysql /var/lib/mysql +else + echo "[i] MySQL data directory not found, creating initial DBs" + mkdir -p /var/lib/mysql + chown -R mysql:mysql /var/lib/mysql + + mysql_install_db --user=mysql --datadir=/var/lib/mysql > /dev/null + + if [ "$MYSQL_ROOT_PASSWORD" = "" ]; then + MYSQL_ROOT_PASSWORD=`pwgen 16 1` + echo "[i] MySQL root Password: $MYSQL_ROOT_PASSWORD" + fi + + MYSQL_DATABASE=${MYSQL_DATABASE:-""} + MYSQL_USER=${MYSQL_USER:-""} + MYSQL_PASSWORD=${MYSQL_PASSWORD:-""} + + tfile=`mktemp` + if [ ! -f "$tfile" ]; then + return 1 + fi + + cat << EOF > $tfile +USE mysql; +FLUSH PRIVILEGES; +GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION; +GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION; +UPDATE user SET password=PASSWORD("") WHERE user='root' AND host='localhost'; +EOF + + if [ "$MYSQL_DATABASE" != "" ]; then + echo "[i] Creating database: $MYSQL_DATABASE" + echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` CHARACTER SET utf8 COLLATE utf8_general_ci;" >> $tfile + + if [ "$MYSQL_USER" != "" ]; then + echo "[i] Creating user: $MYSQL_USER with password $MYSQL_PASSWORD" + echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile + fi + fi + + /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 < $tfile + rm -f $tfile +fi + +# execute any pre-exec scripts +for i in /scripts/pre-exec.d/*sh +do + if [ -e "${i}" ]; then + echo "[i] pre-exec.d - processing $i" + . ${i} + fi +done + +exec /usr/bin/mysqld --user=mysql --console From c1b12a19d95c28f7f05bd10b83eb30146343e2a2 Mon Sep 17 00:00:00 2001 From: Jonny Ervine Date: Wed, 19 Feb 2020 03:41:30 +0000 Subject: [PATCH 2/4] modified: Jenkinsfile Updated to use newer git server --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1955caa..2e7380c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ node("docker-node") { docker.withRegistry('https://harbor.ervine.dev', 'jenkins-to-harbor') { - git branch: "3.11.3", url: "ssh://git@gogs.ervine.org:2022/jonny/x86_64-alpine-mariadb", credentialsId: 'jenkins-to-gogs' + git branch: "3.11.3", url: "ssh://git@git.ervine.org:2222/jonny/x86_64-alpine-mariadb", credentialsId: 'jenkins-to-git' sh "git rev-parse HEAD > .git/commit-id" def commit_id = readFile('.git/commit-id').trim() From 92dde014363f105de0a6356079c6aa8c7c141cce Mon Sep 17 00:00:00 2001 From: Jonny Ervine Date: Mon, 2 Mar 2020 09:33:26 +0000 Subject: [PATCH 3/4] modified: Jenkinsfile Updated to auto-deploy to k8s --- Jenkinsfile | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2e7380c..7d25237 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,12 +6,21 @@ node("docker-node") { sh "git rev-parse HEAD > .git/commit-id" def commit_id = readFile('.git/commit-id').trim() println commit_id + + try { + stage "build" + def app = docker.build "library/x86_64/alpine/mariadb" - stage "build" - def app = docker.build "library/x86_64/alpine/mariadb" - - stage "publish" - app.push("${env.BUILD_NUMBER}") - app.push("latest") + stage "publish" + app.push("${env.BUILD_NUMBER}") + app.push("latest") + + stage('Deploy on K8s'){ + sh "/usr/local/bin/kubectl -n db delete po mariadb-0" + } + } + catch (err) { + currentBuild.result = 'FAILURE' + } } } From a7f5a169a405d495fe4031421dcc36f9098e8a00 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine Date: Thu, 4 Jun 2020 23:58:12 +0800 Subject: [PATCH 4/4] modified: Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7d25237..62bce9b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ node("docker-node") { docker.withRegistry('https://harbor.ervine.dev', 'jenkins-to-harbor') { - git branch: "3.11.3", url: "ssh://git@git.ervine.org:2222/jonny/x86_64-alpine-mariadb", credentialsId: 'jenkins-to-git' + git branch: "3.11.6", url: "ssh://git@git.ervine.org/jonny/x86_64-alpine-mariadb", credentialsId: 'jenkins-to-git' sh "git rev-parse HEAD > .git/commit-id" def commit_id = readFile('.git/commit-id').trim()