Skip to content

Commit

Permalink
feat:add automation
Browse files Browse the repository at this point in the history
  • Loading branch information
kamgastephane committed Sep 25, 2021
1 parent 218bef0 commit e7982bb
Show file tree
Hide file tree
Showing 11 changed files with 633 additions and 25 deletions.
148 changes: 148 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
dist

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

#dump file
dev/

# dotenv environment variables file
.env
.env.development
.env.test
.env.prod

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/
.DS_Store
.idea
19 changes: 15 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:10.11-alpine
LABEL maintainer="Nicholas Amorim <nicholas@pagefreezer.com>"
FROM node:12.16.1-alpine
LABEL maintainer="Stephane Kamga <stepos01@gmail.com>"

ARG CRONICLE_VERSION='0.8.45'

Expand All @@ -12,7 +12,19 @@ ENV CRONICLE_server_comm_use_hostnames 1
ENV CRONICLE_web_direct_connect 0

RUN apk add --no-cache git curl wget perl bash perl-pathtools tar \
procps tini
procps tini mongodb-tools unzip sudo

# install aws cli
RUN apk add --no-cache python3 py3-pip \
&& pip3 install --upgrade pip \
&& pip3 install \
awscli \
&& rm -rf /var/cache/apk/*

RUN mkdir -p /cronicle
COPY plugins /cronicle/plugins
COPY jobs /cronicle/jobs
COPY setup.json /cronicle/setup.json

RUN adduser cronicle -D -h /opt/cronicle

Expand All @@ -29,7 +41,6 @@ RUN curl -L "https://github.com/jhuckaby/Cronicle/archive/v${CRONICLE_VER
ADD entrypoint.sh /entrypoint.sh

EXPOSE 3012

# data volume is also configured in entrypoint.sh
VOLUME ["/opt/cronicle/data", "/opt/cronicle/logs", "/opt/cronicle/plugins"]

Expand Down
9 changes: 0 additions & 9 deletions Dockerfile.s3

This file was deleted.

94 changes: 83 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,46 @@ This image fixes a known issue with the intelliops/belsander image: https://gith

# Supported tags

* `latest`, `0.8.45`, [Dockerfile](https://raw.githubusercontent.com/belsander/docker-cronicle/master/Dockerfile)
* `latest-s3` , `0.8.45-s3`,[Dockerfile.s3](https://raw.githubusercontent.com/belsander/docker-cronicle/master/Dockerfile.s3)
* `latest`, `0.1.0`, [Dockerfile](https://raw.githubusercontent.com/stepos01/docker-cronicle/master/Dockerfile)

* `0.8.28` [Dockerfile](https://raw.githubusercontent.com/belsander/docker-cronicle/master/Dockerfile)
* `0.8.28-s3` [Dockerfile.s3](https://raw.githubusercontent.com/belsander/docker-cronicle/master/Dockerfile.s3)

## latest
Latest version of Cronicle server based upon nodejs Docker image.

## s3
Same as the `latest` Docker image, but with support for Amazon S3 storage. If
there is no need for S3, again, just go for `latest`.
This repo is entirely based on the work from [nicholasamorim](https://github.com/nicholasamorim/docker-cronicle)

Some useful features were included in order to facile automation
* automatic creation of account, plugins and apiKeys during initial setup
* default plugin for a mongo db backup with S3 upload
* automatic creation of events during initial setup
* aws-ci installed by default

# Usage

## Install
```sh
docker pull nicholasamorim/cronicle:latest
docker pull stepos01/cronicle:latest
```

## Running
```sh
docker run --name cronicle --hostname localhost -p 3012:3012 nicholasamorim/cronicle:latest
docker run --name cronicle --hostname localhost -p 3012:3012 stepos01/cronicle:latest
```

Alternatively with persistent data and logs:
```sh
docker run --name cronicle \
-v /path-to-cronicle-storage/data:/opt/cronicle/data:rw \
-v /path-to-cronicle-storage/logs:/opt/cronicle/logs:rw \
--hostname localhost -p 3012:3012 nicholasamorim/cronicle:latest
--hostname localhost -p 3012:3012 stepos01/cronicle:latest
```

The web UI will be available at: http://localhost:3012

> NOTE: please replace the hostname `localhost`, this is only for testing
> purposes! If you rename the hostname also consider setting the environmental
> variable `CRONICLE_base_app_url`.
> e.g `docker run --name cronicle --hostname cronicle-host -p 3012:3012 -e CRONICLE_base_app_url='http://cronicle-host:3012' nicholasamorim/cronicle:latest`
> e.g `docker run --name cronicle --hostname cronicle-host -p 3012:3012 -e CRONICLE_base_app_url='http://cronicle-host:3012' stepos01/cronicle:latest`
## Volumes
Cronicle process runs under the `cronicle` user with `ID 1001` and `GUID `1001`. If you are using Docker bind mounts set permissions accordingly.
Expand Down Expand Up @@ -84,9 +85,80 @@ and restart the Docker container:
```sh
/path-to-cronicle-storage/data/.setup_done
```
A sample config can be found [here](https://github.com/jhuckaby/Cronicle/blob/master/sample_conf/config.json)

### Custom setup file
As mentioned earlier, one of the additional feature is related to automating the creation of users, groups, apiKeys...
We simply need to modify the `setup.json` provided in this repository

A more exhaustive explanation can be found in the following thread:
[Thread on automating cronicle by the author](https://github.com/jhuckaby/Cronicle/issues/12)

#### User
In the `setup.json` file, we can see the creation of an user with username
`stephane` and password `admin`. This is achieved by updating the
following JSON with

Details about values to be used can be found here

#### Plugins
In the `setup.json` file, we can see the creation of a plugin called
`mongobackup`. We just need to define the parameters as well as the command line script which should be run.
We can also define a piece of code to be run instead.
A great definition of plugin can be found [here](https://github.com/jhuckaby/Cronicle#plugins)

Our events created from the mongo plugin expects a few parameters

| Parameter name | Description |
|--------|--------|
|name| the name of the backup
|uri| the mongo url of the database ( tested with srv format). The utility used for backup is mongorestore.
|aws_access_key_id*| AWS secret key
|aws_secret_access_key*| AWS secret key
|aws_default_region*| AWS default region
|s3_destination| the destination on S3(Could be any bucket or path. e.g: **mybucket/cronicle/mybackups**

*: those parameters are set as **hidden**. So they are added attached to the plugin directly and are assigned a value,
and they cannot be seen nor modified afterwards without rebuilding and redeploying the container.
This is done to avoid exposing private keys on the Cronicle user interface.]

#### Category
In the `setup.json` file, we can see the creation of a category
called `mongo`. This is achieved by updating the
following JSON with

#### ApiKey
In the `setup.json` file, we can see the creation of an API Key.
This API key is used to create events automatically through API.
If we decide to change the value of the `adminKey`, we should update it as well
in the [plugins/create-jobs.sh]()

#### Others
Much more can be achieved by modifying the `setup.json` file.
A good starting point can be found there:
* [Default setup.json](https://github.com/jhuckaby/Cronicle/blob/master/sample_conf/setup.json)
* [Thread on automating cronicle by the author](https://github.com/jhuckaby/Cronicle/issues/12)


## Event creation
Event can be created automatically during the initial setup.
You just need to create the proper JSON file and add it into the `jobs` folder.
This project contains two sample jobs.
* one for running a mongo backup, once a day at 4 AM
* one for running a POST http call every 5 minute to a dummy endpoint

A hack for quickly prototyping event, is to create them from the UI, then observe the traffic and capture the payload of the request made by the browser ruding the creation of the event.
Once you have the payload, you can modify it and add it to the jobs folder.

The creation of jobs is done through API using a plugin.
The script in charge of creating the jobs can be found [here]().
The script is launched 90s after starting the server.
We will notice the presence of the ApiKey which was created earlier in the `setup.json`


## Web UI credentials
The default credentials for the web interface are: `admin` / `admin`

# Reference
https://github.com/nicholasamorim/docker-cronicle
https://github.com/jhuckaby/Cronicle
17 changes: 16 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
export CRONICLE_echo=1
export CRONICLE_foreground=1


# Only run setup when setup needs to be done
if [ ! -f $DATA_DIR/.setup_done ]
then
cp $CONF_DIR/setup.json $CONF_DIR/setup.json.origin
cp $CONF_DIR/config.json $CONF_DIR/config.json.origin
cp /cronicle/setup.json $CONF_DIR/setup.json

$BIN_DIR/control.sh setup

cp $CONF_DIR/config.json $CONF_DIR/config.json.origin

if [ -f $DATA_DIR/config.json.import ]
then
Expand All @@ -30,10 +34,21 @@ then

# Create plugins directory
mkdir -p $PLUGINS_DIR
cp -v /cronicle/plugins/*.sh $PLUGINS_DIR

chmod -R 0755 $PLUGINS_DIR/*.sh

# run job creation script
$PLUGINS_DIR/create-jobs.sh . &

# Marking setup done
touch $DATA_DIR/.setup_done
fi


# Run cronicle
/usr/local/bin/node "$LIB_DIR/main.js"




Loading

0 comments on commit e7982bb

Please sign in to comment.