Jenkinsfile and xai cli for nextcloud deployment

This commit is contained in:
2020-06-13 07:40:42 -04:00
parent a065a8207e
commit 7683000a2f
30 changed files with 449 additions and 232 deletions

View File

@@ -1,7 +0,0 @@
FROM nextcloud:13-fpm
#FROM nextcloud:stable-apache
RUN apt-get update && apt-get install -y smbclient && rm -rf /var/lib/apt/lists/*
COPY php/errorlog.conf /usr/local/etc/php-fpm.d/errorlog.conf

View File

@@ -1,6 +1,3 @@
FROM nextcloud:16-apache FROM nextcloud:16-apache
RUN apt-get update && apt-get install -y smbclient && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y smbclient && rm -rf /var/lib/apt/lists/*
#COPY php/errorlog.conf /usr/local/etc/php-fpm.d/errorlog.conf

View File

@@ -1,3 +0,0 @@
FROM nginx
COPY nginx.conf /etc/nginx/conf.d/default.conf

View File

@@ -0,0 +1,62 @@
pipeline {
environment {
APP_NAME = 'xaibox'
WORKDIR = 'dockerfiles/services/nextcloud'
}
agent { label 'docker' }
options {
buildDiscarder(logRotator(numToKeepStr: '2'))
}
triggers {
cron('@weekly')
}
stages {
stage('prepare') {
steps {
checkout scm
sh 'ls'
}
}
stage('build') {
options {
ansiColor('xterm')
timeout(2)
}
steps {
dir(WORKDIR) {
withDockerRegistry(credentialsId: 'b11d7f1a-81ac-4daf-8842-56afc0d2370e', url: 'http://dkregistry.xai-corp.net:5000') {
sh "pwd"
sh "xai build"
}
}
}
}
stage('deploy') {
options {
ansiColor('xterm')
timeout(2)
}
steps {
dir(WORKDIR) {
withDockerRegistry(credentialsId: 'b11d7f1a-81ac-4daf-8842-56afc0d2370e', url: 'http://dkregistry.xai-corp.net:5000') {
sh "xai deploy"
}
}
}
post {
failure {
dir(WORKDIR) {
withDockerRegistry(credentialsId: 'b11d7f1a-81ac-4daf-8842-56afc0d2370e', url: 'http://dkregistry.xai-corp.net:5000') {
sh "xai rollback"
}
}
}
}
}
}
}

View File

@@ -1,7 +0,0 @@
#!/bin/bash -ex
export DOCKER_HOST=dkmanager:2376
docker login -u richard -p $DKREGISTRY_PASS $DKREGISTRY
docker-compose -f docker-compose-mono.yml build
docker push dkregistry.xai-corp.net:5000/xaicorp/nextcloud:16

View File

@@ -0,0 +1,89 @@
#!/usr/bin/env bash
set -e
#set -x
LOCAL_IMAGE=xaicorp/nextcloud
TAG=16.0-${BUILD_NUMBER:-dev}
REMOTE_IMAGE=dkregistry.xai-corp.net:5000/${LOCAL_IMAGE}:${TAG}
LOG=$(mktemp)
export LOCAL_IMAGE
export REMOTE_IMAGE
export TAG
dc() {
# shellcheck disable=SC2068
docker-compose \
-f docker-compose.yml \
-f docker-compose.build.yml \
$@
}
####
build() {
echo -e "\e[33m building the image\e[39m"
dc build
}
build_test() {
echo -e "\e[33m testing the image\e[39m"
#todo test that occ is present
dc run --rm app php /usr/src/nextcloud/occ --version
#test for smbclient installed
dc run --rm --user www-data app which smbclient
}
build_save() {
echo -e "\e[33m saving the image\e[39m"
docker tag "$LOCAL_IMAGE:$TAG" "$REMOTE_IMAGE"
docker push "$REMOTE_IMAGE"
}
function trap_exit() {
code=$?
dc down
if [ $code -gt 0 ]; then
echo
cat "$LOG"
rm "$LOG"
dc logs --tail=10
echo -e "\033[31mFailed to build functional image\033[39m"
exit $code
fi
rm "$LOG"
echo -e "\033[32mSuccess:\033[39m ${LOCAL_IMAGE}:${TAG} successfully built"
}
trap trap_exit EXIT
print_usage() {
printf "Usage: %s: [-b] [-t] [-s] \n" "$0"
echo -b build
echo -t test
echo -s push to registry
echo -h help
exit 0
}
######
if [ -z "$1" ]; then
build && build_test && build_save
exit
fi
while getopts btdhs name
do
case $name in
b) build;;
t) build_test;;
s) build_save;;
*) print_usage;;
esac
done

View File

@@ -0,0 +1,5 @@
-b build image
-t test image
-s save image
default: xai build -bts

View File

@@ -0,0 +1 @@
[-b][-t][-s]

View File

@@ -0,0 +1,136 @@
#!/usr/bin/env bash
set -e
#set -x
LOCAL_IMAGE=xaicorp/nextcloud
TAG=16.0-${BUILD_NUMBER:-dev}
REMOTE_IMAGE=dkregistry.xai-corp.net:5000/${LOCAL_IMAGE}:${TAG}
STACK_NAME=xaibox
SERVICE_NAME=app
APP_NAME=${STACK_NAME}_${SERVICE_NAME}
LOG=$(mktemp)
export LOCAL_IMAGE
export REMOTE_IMAGE
export TAG
export DOCKER_HOST=${DOCKER_HOST:-'dkhost:2376'}
###
function deploy() {
docker pull "$REMOTE_IMAGE"
docker stack deploy \
--with-registry-auth \
-c docker-compose.prod.yml \
${STACK_NAME}
sleep 2
docker stack ps ${STACK_NAME}
wait_for_completed
occ upgrade
occ app:update --all
}
wait_for_completed() {
#states supported: "rollback_completed", "updating", "completed"
state=$(docker service inspect ${APP_NAME} | jq -r .[0].UpdateStatus.State)
while [ "completed" != "$state" ]; do
echo "$state"
sleep 3
state=$(docker service inspect ${APP_NAME} | jq -r .[0].UpdateStatus.State)
done
sleep 5
}
function deploy_test() {
docker ps | grep ${APP_NAME}
assertOK https xaibox.xai-corp.net
assertNetwork prod_ui
assertNetwork prod_app
assertNetwork prod_db
assertNetwork prod_cache
occ check
occ status
}
function deploy_save() {
#tag as latest
docker tag "$REMOTE_IMAGE" "${REMOTE_IMAGE//${TAG}/latest}"
docker push "${REMOTE_IMAGE//${TAG}/latest}"
}
dc() {
# shellcheck disable=SC2068
docker-compose \
-f docker-compose.yml \
-f docker-compose.prod.yml \
$@
}
occ() {
container=$(docker ps -qn1)
# shellcheck disable=SC2068
docker exec -it -u www-data "$container" php occ $@
}
function assertOK() {
proto=$1
domain=$2
set -e
echo -e "\033[94m${proto}://${domain}\033[39m"
curl -IskH "Host: ${domain}" "${proto}://dkhost.xai-corp.net" |
tee "$LOG" | grep -P "200 OK|302 Found|403 Forbidden"
}
function assertNetwork() {
network=$1
echo -e "\033[94minspecting network\033[39m $network"
docker network inspect "$network" | jq -r .[].Containers[].Name | tee "$LOG" | grep ${APP_NAME}
}
function trap_exit() {
code=$?
docker service ls | grep "${APP_NAME}"
if [ $code -gt 0 ]; then
echo
cat "$LOG"
rm "$LOG"
echo -e "\033[31mFailed to deploy ${REMOTE_IMAGE} \033[39m"
exit $code
fi
rm "$LOG"
echo -e "\033[32mSuccess:\033[39m ${REMOTE_IMAGE} successfully deployed"
}
trap trap_exit EXIT
print_usage() {
printf "Usage: %s: [-b] [-t] [-s] \n" "$0"
echo -d deploy
echo -t smoke tests
echo -s tag as latest
echo -h help
exit 0
}
######
if [ -z "$1" ]; then
deploy && deploy_test && deploy_save
exit
fi
while getopts tdhs name; do
case $name in
d) deploy ;;
t) deploy_test ;;
s) deploy_save ;;
*) print_usage ;;
esac
done

View File

@@ -0,0 +1,3 @@
ARGS - The arguments you wish to provide to this command
TODO: Fill out the help information for this command.

View File

@@ -0,0 +1 @@
ARGS...

View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
switch='--off';
if [ "$1" == 'on' ]; then
switch='--on'
fi
xai occ maintenance:mode $switch

View File

@@ -0,0 +1,3 @@
ARGS - The arguments you wish to provide to this command
TODO: Fill out the help information for this command.

View File

@@ -0,0 +1 @@
[on|off]

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -ex
export DOCKER_HOST=${DOCKER_HOST:-'dkhost:2376'}
container=$(docker ps -qn1)
while getopts c: name
do
case $name in
c)
container=$OPTARG
;;
*)
;;
esac
done
shift $((OPTIND -1))
# shellcheck disable=SC2068
docker exec -it -u www-data "$container" php occ $@

View File

@@ -0,0 +1,3 @@
ARGS - The arguments you wish to provide to this command
TODO: Fill out the help information for this command.

View File

@@ -0,0 +1 @@
ARGS...

View File

@@ -0,0 +1,89 @@
#!/usr/bin/env bash
set -e
#set -x
LOCAL_IMAGE=xaicorp/nextcloud
TAG=16.0-${BUILD_NUMBER:-dev}
REMOTE_IMAGE=dkregistry.xai-corp.net:5000/${LOCAL_IMAGE}:${TAG}
STACK_NAME=xaibox
SERVICE_NAME=app
APP_NAME=${STACK_NAME}_${SERVICE_NAME}
LOG=$(mktemp)
#export LOCAL_IMAGE
export REMOTE_IMAGE
#export TAG
export DOCKER_HOST=${DOCKER_HOST:-'dkhost:2376'}
###
function rollback() {
# docker service inspect ${APP_NAME}
docker service update --rollback "${APP_NAME}"
wait_for_completed
# docker service scale "${APP_NAME}=2"
}
wait_for_completed() {
#states supported: "rollback_completed", "updating", "completed"
state=$(docker service inspect ${APP_NAME} | jq -r .[0].UpdateStatus.State)
while [ "rollback_completed" != "$state" ]; do
echo "$state"
sleep 3
state=$(docker service inspect ${APP_NAME} | jq -r .[0].UpdateStatus.State)
done
}
function rollback_test() {
docker service ps --filter "desired-state=Healthy" ${APP_NAME}
docker ps | grep "${APP_NAME}"
}
function rollback_save() {
echo TODO
}
function trap_exit() {
code=$?
docker service ls | grep ${APP_NAME}
if [ $code -gt 0 ]; then
echo
rm "$LOG"
echo -e "\033[31mFailed rolling back ${APP_NAME} \033[39m"
exit $code
fi
rm "$LOG"
echo -e "\033[32mSuccess:\033[39m ${APP_NAME} successfully rolled back"
}
trap trap_exit EXIT
print_usage() {
printf "Usage: %s: [-b] [-t] [-s] \n" "$0"
echo -r rollback
echo -t smoke tests
echo -s tag as latest
echo -h help
exit 0
}
######
if [ -z "$1" ]; then
rollback && rollback_test && rollback_save
exit
fi
while getopts tdhs name
do
case $name in
d) rollback;;
t) rollback_test;;
s) rollback_save;;
*) print_usage;;
esac
done

View File

@@ -0,0 +1,3 @@
ARGS - The arguments you wish to provide to this command
TODO: Fill out the help information for this command.

View File

@@ -0,0 +1 @@
ARGS...

View File

@@ -16,4 +16,6 @@ $CONFIG = [
// 'overwritehost' => 'xaibox.xai-corp.net', // 'overwritehost' => 'xaibox.xai-corp.net',
// 'overwriteprotocol' => 'https', // 'overwriteprotocol' => 'https',
// 'overwrite.cli.url' => 'https://xaibox.xai-corp.net', // 'overwrite.cli.url' => 'https://xaibox.xai-corp.net',
'config_is_read_only' => true
]; ];

View File

@@ -1,10 +0,0 @@
#!/bin/bash -ex
export DOCKER_HOST=dkmanager:2376
docker login -u richard -p $DKREGISTRY_PASS $DKREGISTRY
docker stack deploy --with-registry-auth --prune -c docker-compose-prod.yml xaibox
#docker service update -q xaibox_app
(cd ../ && ./scaleout.sh xaibox_app 180)

View File

@@ -1,28 +0,0 @@
---
# docker-compose file for nextcloud server
# docker login dkregistry.xai-corp.net:5000
# docker-compose build && docker push dkregistry.xai-corp.net:5000/xaicorp/nextcloud:latest
# DOCKER_HOST=dkhost:2376 docker stack deploy --with-registry-auth -c docker-compose-prod.yml owncloud
version: '3'
services:
xaicloud:
image: "dkregistry.xai-corp.net:5000/xaicorp/nextcloud:latest"
build:
context: .
dockerfile: Dockerfile
ports:
- 8083:80
# - 9083:9000
volumes:
- ./data:/var/www/html
web:
image: "dkregistry.xai-corp.net:5000/xaicorp/nextcloud-web:latest"
build:
context: .
dockerfile: Dockerfile-web
ports:
- 8083:80

View File

@@ -1,15 +0,0 @@
---
# docker-compose file for nextcloud server
# docker login dkregistry.xai-corp.net:5000
# docker-compose -f docker-compose-mono.yml build && docker push dkregistry.xai-corp.net:5000/xaicorp/nextcloud:14
# DOCKER_HOST=dkhost:2376 docker stack deploy --with-registry-auth -c docker-compose-prod.yml xaibox
version: '2'
services:
mono:
build:
context: .
dockerfile: ./Dockerfile-mono
image: dkregistry.xai-corp.net:5000/xaicorp/nextcloud:16

View File

@@ -0,0 +1,17 @@
---
# docker-compose file for nextcloud server
# docker login dkregistry.xai-corp.net:5000
# docker-compose build && docker push dkregistry.xai-corp.net:5000/xaicorp/nextcloud:latest
# DOCKER_HOST=dkhost:2376 docker stack deploy --with-registry-auth -c docker-compose-prod.yml owncloud
version: '3.4'
services:
app:
build:
context: .
dockerfile: ./Dockerfile-mono
volumes:
- ./config:/var/www/html/config

View File

@@ -12,7 +12,7 @@ volumes:
services: services:
app: app:
image: "dkregistry.xai-corp.net:5000/xaicorp/nextcloud:16" image: ${REMOTE_IMAGE}
ports: ports:
- 8083:80 - 8083:80
volumes: volumes:
@@ -67,41 +67,6 @@ services:
# tag: nextcloud # tag: nextcloud
# web:
# image: "dkregistry.xai-corp.net:5000/xaicorp/nextcloud-web:latest"
# ports:
# - 8083:80
# volumes:
# - cache:/data/nginx/cache/nextcloud
## - code:/var/www/html
# - /opt/nextcloud/nextcloud2/data:/var/www/html/data
# - /opt/nextcloud/nextcloud2/config:/var/www/html/config
# - /opt/nextcloud/nextcloud2/apps:/var/www/html/custom_apps
#
# deploy:
# mode: replicated
# replicas: 1
# restart_policy:
# condition: any
# delay: "30s"
# max_attempts: 5
# update_config:
# parallelism: 1
# delay: 2s
# order: start-first
# resources:
# limits:
## cpus: '1'
# memory: 512M
## healthcheck:
## test: curl -f http://localhost ||exit 1
## interval: 1m30s
## timeout: 1s
## retries: 2
# networks:
# - prod_ui
# - prod_app
networks: networks:
prod_ui: prod_ui:
external: external:

View File

@@ -5,53 +5,9 @@
# docker-compose build && docker push dkregistry.xai-corp.net:5000/xaicorp/nextcloud:latest # docker-compose build && docker push dkregistry.xai-corp.net:5000/xaicorp/nextcloud:latest
# DOCKER_HOST=dkhost:2376 docker stack deploy --with-registry-auth -c docker-compose-prod.yml owncloud # DOCKER_HOST=dkhost:2376 docker stack deploy --with-registry-auth -c docker-compose-prod.yml owncloud
version: '3' version: '3.4'
volumes:
# nextcloud:
db:
cache:
services: services:
db:
image: mariadb
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=test
- MYSQL_PASSWORD=test
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app: app:
image: dkregistry.xai-corp.net:5000/xaicorp/nextcloud:latest image: ${LOCAL_IMAGE}:${TAG}
ports:
- 8083:80
volumes:
# - nextcloud:/var/www/html
- ./config:/var/www/html/config
- ./php/errorlog.conf:/usr/local/etc/php-fpm.d/errorlog.conf
environment:
- DBTYPE=mysql
- DBHOST=db
- DBPORT=3306
- DBNAME=nextcloud
- DBUSER=nextcloud
- DBPASS=test
- REDISHOST=redis
- REDISPORT=6379
- LOGLEVEL=3
memcached:
image: "memcached:alpine"
ports:
- "11211:11211"
command:
- memcached
- -m64
redis:
image: "redis:4-alpine"
ports:
- "6379:6379"

View File

@@ -1,75 +0,0 @@
proxy_cache_path /data/nginx/cache/nextcloud levels=1:2 keys_zone=my_cache:10m max_size=10g
inactive=60m use_temp_path=off;
upstream xaibox_upstream {
server app:9000;
}
server {
listen 80;
index index.php index.html;
server_name xaibox.xai-corp.net;
client_max_body_size 256m;
root /var/www/html;
location /remote.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass xaibox_upstream;
fastcgi_index remote.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location /public.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass xaibox_upstream;
fastcgi_index public.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass xaibox_upstream;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location /index.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass xaibox_upstream;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_param HTTP_PROXY "";
fastcgi_pass xaibox_upstream;
#fastcgi_index public.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
#location / {
# try_files $uri $uri/;
#}
}

View File

@@ -1,2 +0,0 @@
[www]
catch_workers_output = yes