Commit d16765e9 authored by Dmytro Bogatov's avatar Dmytro Bogatov 💕

Merge branch '23-debian-package-to-control-status-site' into 'master'

Resolve "Debian package to control status site"

Closes #23

See merge request !16
parents 2269aefc 2b60193a
Pipeline #584 passed with stages
in 6 minutes and 10 seconds
POSTGRES_DB=statussite
POSTGRES_USER=statususer
POSTGRES_PASSWORD=SomethingWeird15
# BRANCH TAG (DO NOT MODIFY)
......@@ -53,3 +53,6 @@ articles/site/
documentation/out/
debug
# Debian build artifacts
debian/build
......@@ -40,7 +40,6 @@ build-app:
script:
- export ASPNETCORE_ENVIRONMENT="Production"
- printf "{\"Version\":{\"GitHash\":\"%s\"}}" $CI_BUILD_REF > src/version.json
- yarn config set registry https://registry.npmjs.cf/ # TODO: remove workaround
- ./build.sh
artifacts:
expire_in: 90 min
......@@ -110,7 +109,7 @@ blc-docs:
## RELEASE
release-all:
release-app-docs:
stage: release
dependencies:
- build-app
......@@ -128,3 +127,14 @@ release-all:
- appsettings.yml.example
tags:
- shell
release-debian:
stage: release
image: dbogatov/docker-containers:debian-latest
script:
- ./build.sh -f build-debian-package
artifacts:
paths:
- debian/build/*
tags:
- docker
......@@ -29,6 +29,7 @@
* Badges
- System health
- Individual metrics
* Debian package tool to control the app
* Rich API
* Served as a docker composition - easy to install, configure and update
* Different databases for old and recent data
......
# Deployment
## TL;DR
## The new way
Install status site official debian package - control tool.
* Make sure you have `docker` [installed](https://docs.docker.com/engine/installation/) and `docker-compose` [installed](https://docs.docker.com/compose/install/).
* Add `apt.dbogatov.org`'s key. Run `sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7BAD7958`.
* Add `apt.dbogatov.org` repository. Run `sudo add-apt-repository "deb http://apt.dbogatov.org/ trusty main"`.
* Update package listings. Run `sudo apt-get update`.
* Install `status-ctl`. Run `sudo apt-get install status-ctl`.
This will install `status-ctl` in your `/usr/bin/` directory and will create config files in `/etc/status-site/` directory.
* Launch the app. Run `status-ctl start`.
Great! The app is served on port 5555!
### To update
Update control tool the way you would update any other debian package.
`sudo apt-get update` and `sudo apt-get upgrade`.
### What the tool can do
Run `status-ctl help` or `man status-ctl` to view the available options and commands.
## The old way
Make sure you have [Docker](https://www.docker.com) and [Docker compose](https://docs.docker.com/compose/) installed.
Run the following command in a directory where you want your configuration files to be.
......
......@@ -30,6 +30,7 @@
* Badges
- System health
- Individual metrics
* Debian package tool to control the app
* Rich API
* Served as a docker composition - easy to install, configure and update
* Different databases for old and recent data
......
......@@ -250,6 +250,36 @@ build-for-compose () {
build-docker-images
}
## DEBIAN PACKAGE
build-debian-package () {
cd $CWD/debian
echo "(Re)creating a temporary directory for building..."
rm -rf build/
mkdir -p build/status-ctl/
echo "Copying .jar file, wrapper and scripts..."
cp status-ctl.sh build/status-ctl/
cp ../src/appsettings.production.yml build/status-ctl/
cp ../docker-compose.yml build/status-ctl/
cp ../.env.example build/status-ctl/.env
cp -r Makefile debian/ build/status-ctl
printf "\n\nDOTNET_TAG=master" >> build/status-ctl/.env
echo "Building debian package..."
cd build/status-ctl
debuild -us -uc
echo "Cleaning tmp files..."
cd ../..
rm -rf build/status-ctl
echo "Done!"
}
## APP BUILDERS
build-app () {
......
......@@ -9,7 +9,7 @@
"bootstrap": "^3.3.7",
"bootstrap-notify": "^3.1.3",
"bootstrap-select": "^1.12.2",
"chosen": "^1.6.2",
"chosen": "^0.0.2",
"datatables.net": "^1.10.13",
"datatables.net-bs": "^1.10.12",
"datatables.net-dt": "^1.10.12",
......@@ -18,7 +18,7 @@
"eonasdan-bootstrap-datetimepicker": "^4.17.47",
"flot": "^0.8.0-alpha",
"fullcalendar": "~3.0.0",
"install": "~1.0.4",
"install": "^0.10.1",
"jquery": "2.2.4",
"jquery-mask-plugin": "igorescobar/jQuery-Mask-Plugin#^1.14.0",
"jquery-placeholder": "^2.3.1",
......
This diff is collapsed.
install:
install -D -m 0755 status-ctl.sh $$(pwd)/debian/status-ctl/usr/bin/status-ctl
mkdir -p $$(pwd)/debian/status-ctl/etc/status-site/
cp --no-preserve=ownership appsettings.production.yml $$(pwd)/debian/status-ctl/etc/status-site/appsettings.yml
cp --no-preserve=ownership docker-compose.yml $$(pwd)/debian/status-ctl/etc/status-site/docker-compose.yml
cp --no-preserve=ownership .env $$(pwd)/debian/status-ctl/etc/status-site/.env
#!/bin/bash
# Abort if any command returns non-zero code
set -e
# Prints a message (required first parameter) in blue color
function echo_info {
COLOR="\033[0;36m"
NOCOLOR="\033[0m"
printf "${COLOR}${1}${NOCOLOR}\n"
}
# Prints a message (required first parameter) in red color
function echo_success {
COLOR="\033[0;32m"
NOCOLOR="\033[0m"
printf "${COLOR}${1}${NOCOLOR}\n"
}
# Prints the error message into the error stream and exists with non-zero code
# Requires first argumnent - error message
# Second argument is optional - exit code
function die {
[[ $1 ]] || {
printf >&2 -- 'Usage:\n\tdie <message> [return code]\n'
[[ $- == *i* ]] && return 1 || exit 1
}
COLOR="\033[0;31m"
NOCOLOR="\033[0m"
printf >&2 -- "${COLOR}${1}${NOCOLOR}\n"
usage
exit ${2:-1}
}
function usage {
NOCOLOR="\033[0m"
CYAN="\033[0;36m"
GREEN="\033[0;32m"
RED="\033[0;31m"
printf "Usage: ${RED}$0${NOCOLOR} -t ${GREEN}<string | gitlab-access-token>${NOCOLOR} [-b ${CYAN}<string | branch>${NOCOLOR}]\n"
printf "Example: ${RED}$0${NOCOLOR} -t ${GREEN}slfkSKDF-asdasas-879${NOCOLOR} -b ${CYAN}263-complete-bundling-process${NOCOLOR}\n"
printf "where:\n"
printf "\t-t ${GREEN}gitlab-access-token${NOCOLOR} is gitlab access token needed to access the mono repo.\n"
printf "\t-b ${CYAN}branch${NOCOLOR} is a branch name from whcih to download artifacts.\n"
exit 1
}
BRANCH="master"
# Process command line arguments
while getopts "t:b:" o; do
case "${o}" in
t)
TOKEN=$OPTARG
;;
b)
BRANCH=$OPTARG
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
[[ -n "$TOKEN" ]] || die "-t is required"
PROJECT_ID="47" # lookup in repo settings
JOB="release-debian" # change if necessary
echo_info "Downloading artifacts into temporary directory"
cd `mktemp -d`
curl \
--header "PRIVATE-TOKEN: $TOKEN" \
"https://git.dbogatov.org/api/v4/projects/$PROJECT_ID/jobs/artifacts/$BRANCH/download?job=$JOB" \
> artifacts.zip \
|| die "Could not download artifacts"
echo_info "Extracting files"
unzip artifacts.zip \
|| die "Could not extract files"
echo_info "Removing .deb"
reprepro -b /var/repositories/ remove trusty status-ctl \
|| die "Could not remove .deb from reprepro"
echo_info "Installing .deb"
reprepro -b /var/repositories includedeb trusty debian/build/*.deb \
|| die "Could not add .deb to reprepro"
echo_success "Added package to the repository"
status-ctl (1.1.0) unstable; urgency=medium
* Update man page.
-- Dmytro Bogatov <dmytro@dbogatov.org> Thu, 05 Aug 2017 04:35:38 +0000
status-ctl (1.0.0) unstable; urgency=medium
* First release.
-- Dmytro Bogatov <dmytro@dbogatov.org> Thu, 04 Aug 2017 04:35:38 +0000
status-ctl (0.1.0) unstable; urgency=medium
* First working prototype.
-- Dmytro Bogatov <dmytro@dbogatov.org> Thu, 04 Aug 2017 03:35:38 +0000
status-ctl (0.0.4) unstable; urgency=medium
* Prototype.
-- Dmytro Bogatov <dmytro@dbogatov.org> Thu, 04 Aug 2017 02:35:38 +0000
status-ctl (0.0.3) unstable; urgency=medium
* Updated main script.
-- Dmytro Bogatov <dmytro@dbogatov.org> Thu, 04 Aug 2017 01:35:38 +0000
status-ctl (0.0.2) unstable; urgency=medium
* Pipeline working.
-- Dmytro Bogatov <dmytro@dbogatov.org> Thu, 03 Aug 2017 01:35:38 +0000
status-ctl (0.0.1) unstable; urgency=low
* Initial release.
-- Dmytro Bogatov <dmytro@dbogatov.org> Tue, 01 Aug 2017 17:31:38 +0000
Source: status-ctl
Maintainer: Dmytro Bogatov <dmytro@dbogatov.org>
Build-Depends: debhelper (>= 9.0.0)
Standards-Version: 3.9.6
Section: utils
Package: status-ctl
Priority: extra
Architecture: any
Depends: ${misc:Depends}
Description: Tool to control status site
Long description here.
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Dmytro Bogatov
Upstream-Contact: Dmytro Bogatov <dmytro@dbogatov.org>
Files: *
Copyright: Copyright 2017 Files: *
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
debian/status-ctl.1
#!/usr/bin/make -f
%:
dh $@
override_dh_usrlocal:
.de URL
\\$2 \(laURL: \\$1 \(ra\\$3
..
.if \n[.g] .mso www.tmac
.TH ...
.
.\" Manpage for status-ctl.
.\" Contact dmytro@dbogatov.org to correct errors or typos.
.TH man 1 "4 August 2017" "0.1.1" "status-ctl man page"
.SH NAME
.B status-ctl
\- control tool for status site
.SH SYNOPSIS
.B status-ctl
[ \fIOPTIONS\fR ]
\fICOMMAND\fR
.SH DESCRIPTION
The \fBstatus-ctl\fR is a tool to control status site. It lets user easily start, stop, reconfigure and update the status site app. Status site itself is a docker composition, and \fBstatus-ctl\fR is merely a bash wrapper around docker-compose. For the docs on status site itself, please see
.URL "https://status.dbogatov.org/docs/" "Status Site docs" .
.SH OPTIONS
For a list of command-line options, run
.PP
.nf
.RS
status-ctl help
.RE
.fi
.PP
.SH EXAMPLES
The following command will deploy status site from dev branch preserving the database:
.PP
.nf
.RS
status-ctl -b dev upgrade
.RE
.fi
.PP
The following command will deploy status site from master branch recreating the database:
.PP
.nf
.RS
status-ctl upgrade-clean
.RE
.fi
.PP
.SH BUGS
Bug tracking is performed using
.URL "https://github.com/Dima4ka/status-site/issues" "GitHub issues" .
.SH COPYRIGHT
(C) Dmytro Bogatov 2017. Licensed under the terms of MIT.
.SH "SEE ALSO"
.URL "https://status.dbogatov.org" "Status site demo" .
.URL "https://status.dbogatov.org/docs/" "Status site docs" .
#!/bin/bash
# EXIT CODES
SUCCESS=0
GENERIC_ERROR=1
DEPENDENCY_MISSING=2
CONFIG_INVALID=3
BAD_PARAMETERS=4
# CONSTANTS
CONFIG_DIR=/etc/status-site
PROJECT="status-site"
VERSION="1.1.0"
BRANCH="master"
function usage {
printf "Usage: \t\t$0 [options] <command>\n\n"
printf "Example: \t$0 start\n"
printf "Example: \t$0 -b some-other-branch stop\n\n"
printf "options:\n"
printf "\t-b branch \t (development only) branch to use when deploying status site.\n\n"
printf "commands:\n"
printf "\tstart \t\truns the composition; pulls latest version if none is installed.\n"
printf "\tstop \t\tstops the composition if it is running.\n"
printf "\treconfigure \trestarts the app to apply config chnages.\n"
printf "\tcheck-config \tverifies that the config file is valid.\n"
printf "\tupgrade \tstops the composition, pulls latest version and starts the compostion.\n"
printf "\tupgrade-clean \tstops the composition, removes all containers (dataabse in particular), pulls latest version and starts the compostion.\n"
printf "\tlogs \t\tshows app's log messages.\n"
printf "\tinfo \t\tshows status-site's information (eq. path to config).\n"
printf "\tversion \tshows this tool's version.\n"
}
function check-dependencies {
command -v docker >/dev/null 2>&1 || {
echo >&2 "docker is required to run status-site."
echo >&2 "See https://docs.docker.com/engine/installation/"
echo >&2 "Aborting."
exit $DEPENDENCY_MISSING
}
command -v docker-compose >/dev/null 2>&1 || {
echo >&2 "docker-compose is required to run status-site."
echo >&2 "See https://docs.docker.com/compose/install/"
echo >&2 "Aborting."
exit $DEPENDENCY_MISSING
}
}
function start {
echo "STARTING STATUS-SITE"
docker-compose -p $PROJECT up -d --remove-orphans
}
function stop {
echo "STOPPING STATUS-SITE"
docker-compose -p $PROJECT stop
}
function reconfigure {
echo "RECONFIGURING STATUS-SITE"
check-config
stop
start
}
function check-config {
echo "Configuration check is not implemented yet."
echo "It always passes"
true || {
echo >&2 "CONFIGURATION CHECK FAILED."
echo >&2 "See log messages above."
echo >&2 "Aborting."
exit $CONFIG_INVALID
}
}
function upgrade {
echo "UPGRADING STATUS-SITE"
stop
docker-compose -p $PROJECT pull
start
}
function upgrade-clean {
echo "UPGRADING STATUS-SITE WITH CLEAN DATABASE"
stop
docker-compose -p $PROJECT rm -f
docker-compose -p $PROJECT pull
start
}
function logs {
echo "SHOWING LOG MESSAGES"
docker-compose -p $PROJECT logs
}
function info {
printf "Config path:\t$CONFIG_DIR/appsettings.yml\n"
printf "Env path:\t$CONFIG_DIR/.env\n"
printf "Compose path:\t$CONFIG_DIR/docker-compose.yml\n"
}
function help {
usage
}
function version {
echo "status-ctl $VERSION"
}
check-dependencies
cd $CONFIG_DIR
printf "\n\nDOTNET_TAG=$BRANCH" >> .env
while :; do
case "$1" in
-b)
[[ -n "$2" ]] || {
echo "$1 requires a non-empty option argument"
exit $BAD_PARAMETERS
}
BRANCH="$2"
printf "\n\nDOTNET_TAG=$BRANCH" >> .env
echo "Branch is set to $BRANCH"
shift
;;
start)
start
exit $SUCCESS
;;
stop)
stop
exit $SUCCESS
;;
reconfigure)
reconfigure
exit $SUCCESS
;;
check-config)
check-config
exit $SUCCESS
;;
upgrade)
upgrade
exit $SUCCESS
;;
upgrade-clean)
upgrade-clean
exit $SUCCESS
;;
logs)
logs
exit $SUCCESS
;;
info)
info
exit $SUCCESS
;;
help)
help
exit $SUCCESS
;;
version)
version
exit $SUCCESS
;;
*)
help
exit $GENERIC_ERROR
esac
shift
done
exit $GENERIC_ERROR
......@@ -79,7 +79,7 @@ done
shift $((OPTIND-1))
PROJECT="status-site" # lookup in repo settings
JOB="release-all" # change if necessary
JOB="release-app-docs" # change if necessary
echo_info "Downloading artifacts into temporary directory"
# for now, Gitlab does not allow downloading public artifacts through API without authentication
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment