#
# Easiest way to work with this file, from an updated Ubuntu 16.04 LTS image
# 1.   create a non-root user with sudo priv and perform following steps as non-root
# 2.  `sudo apt-get update`
# 3.  `sudo apt-get install snapcraft python build-essential`
# 4.  `snapcraft stage`
# 5.  `snapcraft snap`

name: rocketchat-server
version: 3.10.0
summary: Rocket.Chat server
description: Have your own Slack like online chat, built with Meteor. https://rocket.chat/
confinement: strict
assumes: [snapd2.21]
apps:
    rocketchat-server:
        command: startRocketChat
        daemon: simple
        plugs: [network, network-bind, removable-media]
    rocketchat-mongo:
        command: startmongo
        daemon: simple
        plugs: [network, network-bind]
    rocketchat-caddy:
        command: env LC_ALL=C caddy -conf=$SNAP_DATA/Caddyfile
        daemon: simple
        plugs: [network, network-bind]
    mongo:
        command: env LC_ALL=C mongo
        plugs: [network]
    restoredb:
        command: env LC_ALL=C restoredb
        plugs: [network]
    backupdb:
        command: env LC_ALL=C backupdb
        plugs: [network]
    initcaddy:
        command: env LC_ALL=C initcaddy
hooks:
    configure:
        plugs: [network]
    pre-refresh:
        plugs: [network]
parts:
    node:
        plugin: dump
        prepare: ./resources/preparenode
        build-packages:
            # For fibers
            - python
            - build-essential
            - nodejs
    rocketchat-server:
        build-packages:
            - curl
        plugin: dump
        prepare: ./resources/prepareRocketChat
        after: [node]
        source: .
        stage-packages:
            - execstack
            - fontconfig-config
        stage:
            - programs
            - main.js
            - .node_version.txt
            - etc
            - usr
            - star.json
    mongodb:
        build-packages:
            - wget
        source: ./
        prepare: ./resources/preparemongo
        plugin: dump
        stage-packages:
            - libssl1.0.0
        prime:
            - usr
            - bin
            - lib
    scripts:
        plugin: dump
        source: resources/
        organize:
            backupdb: bin/backupdb
            restoredb: bin/restoredb
            startmongo: bin/startmongo
            startRocketChat: bin/startRocketChat
            initreplset.js: bin/initreplset.js
            Caddyfile: bin/Caddyfile
            initcaddy: bin/initcaddy
        prime:
            - bin
    caddy:
        prepare: ./resources/preparecaddy
        plugin: dump
        source: ./
        prime:
            - bin
        organize:
            caddy: bin/caddy
        after: [mongodb]
    hooks:
        plugin: nil
        stage-packages:
            - dnsutils
            - curl
        prime:
            - usr
            - lib

