diff --git a/Makefile b/Makefile index e1beade..3db17f6 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,7 @@ install: uninstall cp tt /usr/local/bin/ && \ mkdir -p /usr/local/share/tarantino/templates && \ cp *.sh /usr/local/share/tarantino && \ - cp templates/docker-compose.yml /usr/local/share/tarantino/templates && \ - cp -R templates/grafana /usr/local/share/tarantino/templates && \ + cp -R templates /usr/local/share/tarantino && \ cp -f tt_completion /usr/local/share/tarantino && \ cp -f tt_completion_hook.bash /etc/bash_completion.d/ && \ ./tt install && \ diff --git a/dc.sh b/dc.sh index 632cb55..184c181 100644 --- a/dc.sh +++ b/dc.sh @@ -4,48 +4,90 @@ tt_dc() { dc $@ } -dc_file() { - echo $(get_workspace_dir)/docker-compose.yml +dc_projects_file() { + echo $(get_workspace_dir)/docker-compose-projects.yml +} + +dc_static_file() { + echo $(get_workspace_dir)/docker-compose-static.yml +} + +dc_static() { + TT_PROJECTS=$TT_PROJECTS docker-compose -f $(dc_static_file) $@ +} + +dc_projects() { + TT_PROJECTS=$TT_PROJECTS docker-compose -f $(dc_projects_file) $@ } dc() { - PROJECTS=$TT_PROJECTS TT_PROJECTS=$TT_PROJECTS docker-compose -f $(dc_file) $* + TT_PROJECTS=$TT_PROJECTS docker-compose -f $(dc_static_file) -f $(dc_projects_file) $@ } dc_get_links() { local key=services_"$1"_links local links=$key[@] - eval $(parse_yaml $(dc_file) | grep $key) + eval $(parse_yaml $(dc_projects_file) | grep $key) for link in ${!links}; do echo $link done } -dc_get_all_services() { - if [ "$TT_IS_GLOBAL" = true -a -f "$ALL_SERVICES_FILE" ]; then - cat "$ALL_SERVICES_FILE" - else - dc config --services +get_workspace_cache_dir() { + local cachedir=$(get_workspace_dir)/.cache + mkdir -p $cachedir + echo $cachedir +} + +generate_service_lists() { + local md5check=$(get_workspace_cache_dir)/dc_files.md5 + + if [ -f "$md5check" ]; then + if $(md5sum -c "$md5check" --quiet); then + return 0 + fi fi + + local projects_file=$(get_workspace_cache_dir)/projects + local static_file=$(get_workspace_cache_dir)/static + local all_services_file=$(get_workspace_cache_dir)/all + + dc_projects config --services > "$projects_file" + dc_static config --services > "$static_file" + dc config --services > "$all_services_file" + + md5sum "$(dc_projects_file)" "$(dc_static_file)" > "$md5check" +} + +dc_get_all_services() { + generate_service_lists + cat "$(get_workspace_cache_dir)/all" +} + +dc_get_projects() { + generate_service_lists + cat "$(get_workspace_cache_dir)/projects" } -dc_get_services() { - dc_get_all_services | grep -Ev $NOT_SERVICES_PATTERN +dc_get_static() { + generate_service_lists + cat "$(get_workspace_cache_dir)/static" } dc_get_repos() { if [[ $# -gt 0 ]]; then services= + ALL_INFRASTRUCTURE=$(dc_get_static | paste -sd '|' -) repos=$@ while [ "$services" != "$repos" ]; do services=$repos repos= for service in $services; do - self=$(echo $service | grep -Ev $NOT_SERVICES_PATTERN) - if [ ! -z "$self" ]; then - repos="$repos $self" + service=$(echo $service | grep -Ev $ALL_INFRASTRUCTURE) + if [ ! -z "$service" ]; then + repos="$repos $service" fi - links=$(dc_get_links $service | grep -Ev $NOT_SERVICES_PATTERN) + links=$(dc_get_links $service | grep -Ev $ALL_INFRASTRUCTURE) if [ ! -z "$links" ]; then repos="$repos $links" fi @@ -56,10 +98,6 @@ dc_get_repos() { echo "$repos" fi else - echo "$(tt_get_services)" + echo "$(dc_get_projects)" fi - #hard-coded repos that for now will always be a dependency - echo gogo-templates - echo grafana - echo butch } diff --git a/dynamo/Dockerfile b/dynamo/Dockerfile deleted file mode 100644 index cb08ee4..0000000 --- a/dynamo/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM java:8-jre - -RUN /usr/bin/curl -L http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest | /bin/tar xz - -ENTRYPOINT ["/usr/bin/java", "-Djava.library.path=./DynamoDBLocal_lib", "-jar", "DynamoDBLocal.jar"] - -CMD [] diff --git a/kibana/Dockerfile b/kibana/Dockerfile deleted file mode 100644 index ba73023..0000000 --- a/kibana/Dockerfile +++ /dev/null @@ -1,29 +0,0 @@ -# This is a 360 version of https://github.com/balsamiq/docker-kibana -FROM docker-registry.test.360incentives.io/service-base -MAINTAINER 360incentives - -RUN apt-get update && \ - apt-get -y install wget nginx-full apache2-utils && \ - rm -rf /var/lib/apt/lists/* - -WORKDIR /opt -RUN wget --no-check-certificate -O- https://download.elasticsearch.org/kibana/kibana/kibana-3.1.2.tar.gz | tar xvfz - -RUN mv /opt/kibana-3.1.2 /opt/kibana -RUN mkdir /etc/kibana # This is where the htpasswd file is placed by the run script - -ADD run /opt/run -ADD config/etc /etc - -RUN rm /etc/nginx/sites-enabled/* -RUN echo "daemon off;" >> /etc/nginx/nginx.conf - -# Add our Kibana configuration and our dashboards -ADD config/kibana /opt/kibana - -ENV KIBANA_SECURE true -ENV KIBANA_USER kibana -ENV KIBANA_PASSWORD kibana - -EXPOSE 80 - -CMD /opt/run diff --git a/kibana/LICENSE b/kibana/LICENSE deleted file mode 100644 index 4d6ac2f..0000000 --- a/kibana/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Luis Arias - -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. \ No newline at end of file diff --git a/kibana/VERSION b/kibana/VERSION deleted file mode 100644 index ef538c2..0000000 --- a/kibana/VERSION +++ /dev/null @@ -1 +0,0 @@ -3.1.2 diff --git a/kibana/config/etc/nginx/sites-available/kibana b/kibana/config/etc/nginx/sites-available/kibana deleted file mode 100644 index 1ab4618..0000000 --- a/kibana/config/etc/nginx/sites-available/kibana +++ /dev/null @@ -1,47 +0,0 @@ -server { - listen 80; ## listen for ipv4; this line is default and implied - listen [::]:80 default ipv6only=on; ## listen for ipv6 - - # Make site accessible from http://localhost/ - server_name localhost; - - location = /health { - return 200; - access_log off; - } - - location / { - root /opt/kibana; - index index.html index.htm; - } - - # Reverse proxy elasticsearch ajax calls - location ~ ^/_aliases$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/.*/_aliases$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/_nodes$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/.*/_search$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/.*/_mapping { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/kibana-int/dashboard/.*$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/kibana-int/temp.*$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } -} diff --git a/kibana/config/etc/nginx/sites-available/kibana-secure b/kibana/config/etc/nginx/sites-available/kibana-secure deleted file mode 100644 index 9c7bcc4..0000000 --- a/kibana/config/etc/nginx/sites-available/kibana-secure +++ /dev/null @@ -1,54 +0,0 @@ -server { - listen 80; ## listen for ipv4; this line is default and implied - listen [::]:80 default ipv6only=on; ## listen for ipv6 - - # Make site accessible from http://localhost/ - server_name localhost; - - location = /health { - return 200; - access_log off; - } - - location / { - root /opt/kibana; - index index.html index.htm; - - if ($http_x_forwarded_proto != "https") { - rewrite ^ https://$host$uri permanent; - } - - auth_basic "Restricted"; - auth_basic_user_file /etc/kibana/htpasswd; - } - - # Reverse proxy elasticsearch ajax calls - location ~ ^/_aliases$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/.*/_aliases$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/_nodes$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/.*/_search$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/.*/_mapping { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/kibana-int/dashboard/.*$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } - location ~ ^/kibana-int/temp.*$ { - proxy_pass http://elasticsearch:9200; - proxy_read_timeout 90; - } -} diff --git a/kibana/config/kibana/app/dashboards/platform.json b/kibana/config/kibana/app/dashboards/platform.json deleted file mode 100644 index bc63ccb..0000000 --- a/kibana/config/kibana/app/dashboards/platform.json +++ /dev/null @@ -1,302 +0,0 @@ -{ - "title": "PlatformAPI", - "services": { - "query": { - "list": { - "0": { - "query": "", - "alias": "", - "color": "#7EB26D", - "id": 0, - "pin": false, - "type": "lucene", - "enable": true - } - }, - "ids": [ - 0 - ] - }, - "filter": { - "list": { - "0": { - "type": "time", - "field": "time", - "from": "now-7d", - "to": "now", - "mandate": "must", - "active": true, - "alias": "", - "id": 0 - } - }, - "ids": [ - 0 - ] - } - }, - "rows": [ - { - "title": "Options", - "height": "50px", - "editable": true, - "collapse": false, - "collapsable": true, - "panels": [ - { - "error": false, - "span": 7, - "editable": true, - "group": [ - "default" - ], - "type": "text", - "status": "Stable", - "mode": "markdown", - "content": "If you have a field with a timestamp in it, you can set a time filter using the control in the navigation bar. You'll need to click the cog icon to configure the field that your timestamp is in.", - "style": {}, - "title": "Have a timestamp somewhere?" - }, - { - "error": false, - "span": 5, - "editable": true, - "group": [ - "default" - ], - "type": "text", - "status": "Stable", - "mode": "markdown", - "content": "See the *Filters* bar above? Click it to expand the filters panel. Right now there are none. click on one of the icons in the document types list to filter down to only that document type", - "style": {}, - "title": "About filters" - } - ], - "notice": false - }, - { - "title": "Graph", - "height": "250px", - "editable": true, - "collapse": false, - "collapsable": true, - "panels": [ - { - "error": false, - "span": 3, - "editable": true, - "group": [ - "default" - ], - "type": "terms", - "queries": { - "mode": "all", - "ids": [ - 0 - ] - }, - "field": "_type", - "exclude": [], - "missing": true, - "other": true, - "size": 100, - "order": "count", - "style": { - "font-size": "10pt" - }, - "donut": false, - "tilt": false, - "labels": true, - "arrangement": "horizontal", - "chart": "pie", - "counter_pos": "none", - "title": "Document types", - "spyable": true, - "tmode": "terms", - "tstat": "total", - "valuefield": "" - }, - { - "error": false, - "span": 3, - "editable": true, - "group": [ - "default" - ], - "type": "terms", - "queries": { - "mode": "all", - "ids": [ - 0 - ] - }, - "field": "_type", - "exclude": [], - "missing": true, - "other": true, - "size": 10, - "order": "count", - "style": { - "font-size": "10pt" - }, - "donut": false, - "tilt": false, - "labels": true, - "arrangement": "horizontal", - "chart": "table", - "counter_pos": "above", - "spyable": true, - "title": "Document Types", - "tmode": "terms", - "tstat": "total", - "valuefield": "" - } - ], - "notice": false - }, - { - "title": "Events", - "height": "650px", - "editable": true, - "collapse": false, - "collapsable": true, - "panels": [ - { - "error": false, - "span": 12, - "editable": true, - "group": [ - "default" - ], - "type": "table", - "size": 100, - "pages": 5, - "offset": 0, - "sort": [ - "time", - "desc" - ], - "style": { - "font-size": "9pt" - }, - "overflow": "min-height", - "fields": [ - "time", - "msg", - "level", - "name", - "err.message" - ], - "highlight": [], - "sortable": true, - "header": true, - "paging": true, - "spyable": true, - "queries": { - "mode": "all", - "ids": [ - 0 - ] - }, - "field_list": true, - "status": "Stable", - "trimFactor": 300, - "normTimes": true, - "title": "Documents", - "all_fields": false, - "localTime": true, - "timeField": "time" - } - ], - "notice": false - } - ], - "editable": true, - "index": { - "interval": "day", - "pattern": "[logstash-]YYYY.MM.DD", - "default": "_all", - "warm_fields": false - }, - "style": "dark", - "failover": false, - "panel_hints": true, - "loader": { - "save_gist": false, - "save_elasticsearch": true, - "save_local": true, - "save_default": true, - "save_temp": true, - "save_temp_ttl_enable": true, - "save_temp_ttl": "30d", - "load_gist": true, - "load_elasticsearch": true, - "load_elasticsearch_size": 20, - "load_local": true, - "hide": false - }, - "pulldowns": [ - { - "type": "query", - "collapse": false, - "notice": false, - "query": "*", - "pinned": true, - "history": [ - "", - "_type:*-test", - "_type:*-test AND -\"/health\"", - "_type:*-dev AND -\"/health\"", - "_type:*-prod AND -\"/health\"", - "_type:*-prod", - "_type:*-prod AND -\"/health\" AND validateAccount", - "_type:*-prod AND -\"/health\" AND \"sort\"", - "level > 30" - ], - "remember": 10, - "enable": true - }, - { - "type": "filtering", - "collapse": false, - "notice": true, - "enable": true - } - ], - "nav": [ - { - "type": "timepicker", - "collapse": false, - "notice": false, - "status": "Stable", - "time_options": [ - "5m", - "15m", - "1h", - "6h", - "12h", - "24h", - "2d", - "7d", - "30d" - ], - "refresh_intervals": [ - "5s", - "10s", - "30s", - "1m", - "5m", - "15m", - "30m", - "1h", - "2h", - "1d" - ], - "timefield": "time", - "enable": true, - "now": true, - "filter_id": 0 - } - ], - "refresh": false -} \ No newline at end of file diff --git a/kibana/config/kibana/config.js b/kibana/config/kibana/config.js deleted file mode 100644 index 1f38619..0000000 --- a/kibana/config/kibana/config.js +++ /dev/null @@ -1,80 +0,0 @@ -/** @scratch /configuration/config.js/1 - * - * == Configuration - * config.js is where you will find the core Kibana configuration. This file contains parameter that - * must be set before kibana is run for the first time. - */ -define(['settings'], -function (Settings) { - - - /** @scratch /configuration/config.js/2 - * - * === Parameters - */ - return new Settings({ - - /** @scratch /configuration/config.js/5 - * - * ==== elasticsearch - * - * The URL to your elasticsearch server. You almost certainly don't - * want +http://localhost:9200+ here. Even if Kibana and Elasticsearch are on - * the same host. By default this will attempt to reach ES at the same host you have - * kibana installed on. You probably want to set it to the FQDN of your - * elasticsearch host - * - * Note: this can also be an object if you want to pass options to the http client. For example: - * - * +elasticsearch: {server: "http://localhost:9200", withCredentials: true}+ - * - */ - elasticsearch: window.location.protocol+"//"+window.location.hostname, - - /** @scratch /configuration/config.js/5 - * - * ==== default_route - * - * This is the default landing page when you don't specify a dashboard to load. You can specify - * files, scripts or saved dashboards here. For example, if you had saved a dashboard called - * `WebLogs' to elasticsearch you might use: - * - * default_route: '/dashboard/elasticsearch/WebLogs', - */ - default_route : '/dashboard/file/platform.json', - - /** @scratch /configuration/config.js/5 - * - * ==== kibana-int - * - * The default ES index to use for storing Kibana specific object - * such as stored dashboards - */ - kibana_index: "kibana-int", - - /** @scratch /configuration/config.js/5 - * - * ==== panel_name - * - * An array of panel modules available. Panels will only be loaded when they are defined in the - * dashboard, but this list is used in the "add panel" interface. - */ - panel_names: [ - 'histogram', - 'map', - 'goal', - 'table', - 'filtering', - 'timepicker', - 'text', - 'hits', - 'column', - 'trends', - 'bettermap', - 'query', - 'terms', - 'stats', - 'sparklines' - ] - }); -}); diff --git a/kibana/run b/kibana/run deleted file mode 100755 index d52db1c..0000000 --- a/kibana/run +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -if [ "$KIBANA_SECURE" = "true" ] ; then - ln -s /etc/nginx/sites-available/kibana-secure /etc/nginx/sites-enabled/kibana - htpasswd -bc /etc/kibana/htpasswd ${KIBANA_USER} ${KIBANA_PASSWORD} -else - ln -s /etc/nginx/sites-available/kibana /etc/nginx/sites-enabled/kibana -fi - -nginx diff --git a/templates/docker-compose-projects.yml b/templates/docker-compose-projects.yml new file mode 100644 index 0000000..a2897e0 --- /dev/null +++ b/templates/docker-compose-projects.yml @@ -0,0 +1,26 @@ +version: '2' +services: + + ####### example projects (https://meet-tarantino.github.io/get-started) + + jackie: + image: mhart/alpine-node + command: node . + environment: + jackie_mongo__url: mongodb://mongo/jackie + links: + - mongo + volumes: + - ${TT_PROJECTS}/jackie:/app:ro + working_dir: /app + + jules: + image: mhart/alpine-node + command: node . + environment: + jules_jackie: http://jackie:8080 + links: + - jackie + volumes: + - ${TT_PROJECTS}/jules:/app:ro + working_dir: /app diff --git a/templates/docker-compose-static.yml b/templates/docker-compose-static.yml new file mode 100644 index 0000000..1ae1e55 --- /dev/null +++ b/templates/docker-compose-static.yml @@ -0,0 +1,9 @@ +version: '2' +services: + + ####### example static images (no git-backed volume mount) + ####### typically used for infrastructure-type such as databases, etc. + mongo: + image: mongo + ports: + - "27017:27017" diff --git a/templates/docker-compose.yml b/templates/docker-compose.yml deleted file mode 100644 index 79deb04..0000000 --- a/templates/docker-compose.yml +++ /dev/null @@ -1,75 +0,0 @@ -version: '2' -services: - - ####### infrastructure - - elasticsearch: - image: elasticsearch - - grafana: - build: ./grafana - ports: - - "3000:3000" - environment: - GF_AUTH_ANONYMOUS_ENABLED: 'true' - GF_AUTH_ANONYMOUS_ORG_NAME: 'Main Org.' - GF_AUTH_ANONYMOUS_ORG_ROLE: 'Admin' - GF_DASHBOARDS_JSON_ENABLED: 'true' - GF_DASHBOARDS_JSON_PATH: '/dashboards' - volumes: - - /etc/localtime:/etc/localtime:ro -# - ${TT_PROJECTS}/grafana/grafana/app/dashboards:/dashboards:ro - links: - - graphite - - elasticsearch - - graphite: - image: hopsoft/graphite-statsd - ports: - - "80:80" - - "2003:2003" - - "8125:8125/udp" - volumes: - - /etc/localtime:/etc/localtime:ro - -# kibana: -# build: ./kibana -# environment: -# KIBANA_SECURE: 'false' -# links: -# - elasticsearch:es - - mongo: - image: mongo - ports: - - "27017:27017" - - ####### services - - jackie: - image: mhart/alpine-node - command: node . - environment: - jackie_mongo__url: mongodb://mongo/jackie - jackie_stats__host: graphite - links: - - elasticsearch - - graphite - - mongo - volumes: - - ${TT_PROJECTS}/jackie:/app:ro - working_dir: /app - - jules: - image: mhart/alpine-node - command: node . - environment: - jules_jackie: http://jackie:8080 - jules_stats__host: graphite - links: - - elasticsearch - - graphite - - mongo - volumes: - - ${TT_PROJECTS}/jules:/app:ro - working_dir: /app diff --git a/templates/grafana/Dockerfile b/templates/grafana/Dockerfile deleted file mode 100644 index 0ab8dda..0000000 --- a/templates/grafana/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM grafana/grafana -MAINTAINER meet-tarantino - -RUN apt-get update && \ - apt-get install -y curl && \ - rm -rf /var/lib/apt/lists/* - -ADD ./run /usr/local/bin/run - -ENTRYPOINT run diff --git a/templates/grafana/run b/templates/grafana/run deleted file mode 100755 index 4203387..0000000 --- a/templates/grafana/run +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -add_datasource() { - until curl localhost:3000 &> /dev/null; do - sleep 0.25 - echo Waiting for grafana to start... - done - - echo Adding graphite data source. - curl localhost:3000/api/datasources -d '{ - "name": "graphite", - "type": "graphite", - "url": "http://graphite", - "isDefault": true, - "access": "proxy", - "basicAuth": false - }' -H "content-type: application/json" -} - -add_datasource & -exec /run.sh - diff --git a/templates/plugins/data.sh b/templates/plugins/data.sh deleted file mode 100644 index 268045a..0000000 --- a/templates/plugins/data.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env bash - -tt_data() { - local script=$1 - shift - - if [ -z "$script" ]; then - ttd_usage - return 1; - fi - - run_sample_data $script $@ -} - -ttd_usage() { - local sample_scripts=$(tt_sample_data_scripts) - - if ! hash jq; then - echo 'Warning: you do not appear to have `jq` installed, `tt data` usage commands will not be complete' - echo 'run `sudo apt-get install -y jq` to resolve this' - fi - - if [ ! -d "$TT_PROJECTS/$SAMPLE_DATA" ]; then - echo 'Warning: you do not have the sample-data repository, `tt data` usage will not list sample scripts' - echo 'run `tt clone sample-data` to resolve this' - fi - - tt_header - echo 'usage: tt data [args]' - echo - echo commands: - echo - echo ' - runs the sample-data project npm script of the same name' - if [ ! -z "$sample_scripts" ]; then - echo ' available commands:' - for script in $sample_scripts; do - echo " $script" - done - fi -} - -tt_sample_data_scripts() { - local sample_data_dir="$TT_PROJECTS/$SAMPLE_DATA" - if [ -d "$sample_data_dir" ]; then - cat "$sample_data_dir"/package.json | jq -r '.scripts | keys[]' | grep -vx test - fi -} - -run_sample_data() { - local sample_data_project="$TT_PROJECTS/$SAMPLE_DATA" - - local script=$1 - shift - - if [ ! -d $sample_data_project ]; then - echo "requires the $SAMPLE_DATA repository, cloning..." - tt_clone $SAMPLE_DATA - fi - - echo "running sample data script: $script" - - if [ $# -gt 0 ]; then - script="$script -- $@" # add any extra args - fi - - pushd $sample_data_project; - - npm run $script - result=$? - - popd &> /dev/null - return $result -} - diff --git a/templates/ttvars.sh b/templates/ttvars.sh new file mode 100644 index 0000000..fdde9cc --- /dev/null +++ b/templates/ttvars.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +## TT_PROJECTS - This is the root folder of your git-backed projects +TT_PROJECTS=~/tmp + +## TT_GIT_BASE - This is the base URL of your git projects (will be used like $TT_GIT_BASE/project.git) +TT_GIT_BASE=git@github.com:meet-tarantino diff --git a/tt b/tt index 57431a4..2d16cc6 100755 --- a/tt +++ b/tt @@ -1,15 +1,10 @@ #!/bin/bash # variables -TT_PROJECTS=${TT_PROJECTS:-~/projects} - TT_IS_GLOBAL=$([ "$0" = "/usr/local/bin/tt" ] && echo true || echo false) TT_SHARE=$([ $TT_IS_GLOBAL = true ] && echo /usr/local/share/tarantino || dirname $0) TT_HOME=${TT_HOME:-~/.tt} -NOT_SERVICES_PATTERN='mongo|redis|rabbit|graphite|elasticsearch|kibana|grafana|dynamo' -SAMPLE_DATA='sample-data' - source $TT_SHARE/dc.sh source $TT_SHARE/install.sh source $TT_SHARE/parse-yaml.sh @@ -23,6 +18,10 @@ tt_get_services() { dc_get_services } +tt_get_workspace() { + get_workspace +} + info() { echo INFO: $* } @@ -34,10 +33,10 @@ main() { >&2 echo fi - if [[ "$(pwd)" == *tarantino* && $TT_IS_GLOBAL = true && "$1" != "ip" ]]; then - >&2 echo WARNING: You\'re running global tarantino while working on tarantino locally. - >&2 echo - fi +# if [[ "$(pwd)" == *tarantino* && $TT_IS_GLOBAL = true && "$1" != "ip" ]]; then +# >&2 echo WARNING: You\'re running global tarantino while working on tarantino locally. +# >&2 echo +# fi if [[ -z "$(get_workspace_dir)" && ! -z "$1" ]]; then case "$1" in @@ -56,6 +55,10 @@ main() { esac fi + TT_PROJECTS=${TT_PROJECTS:-~/tmp} + TT_GIT_BASE=${TT_GIT_BASE:-git@github.com:meet-tarantino} + apply_workspace_vars # this may override the above defaults + run_sub_command tt $@ } @@ -93,7 +96,6 @@ tt_usage() { echo ' destroy [container] - destroy all [or named] containers' echo ' install - prepare environment for tarantino' echo ' ip - retrieve ip address of a specific container' - echo ' npm_reinstall - remove and reinstall all npm module dependences' echo ' pull [service] - pull sources for all [or named] projects without changes' echo ' recreate [container] - recreate all [or named] containers' echo ' restart - restart all containers' @@ -167,7 +169,7 @@ tt_clone() { for repo in $repos; do if [ ! -d "$projects/$repo" ]; then echo $repo not found in projects directory $projects, cloning it. - git clone git@github.com:360incentives/$repo.git $projects/$repo || return 1; + git clone $TT_GIT_BASE/$repo.git $projects/$repo || return 1; # run npm install for any npm packages (the service, or its components) find "$projects/$repo" -name 'package.json' -not -path "**/bower_components/*" | xargs --no-run-if-empty dirname | grep -v 'node_modules' | while read module; do @@ -180,11 +182,6 @@ tt_clone() { popd &> /dev/null } -tt_npm_reinstall() { - tt_module_exec rm -rf node_modules - tt_module_exec npm install -} - tt_pull() { local projects=$TT_PROJECTS local repos=$(dc_get_repos $*) @@ -238,10 +235,6 @@ tt_module_exec() { popd } -tt_npm() { - tt_module_exec npm $1 -} - tt_create() { if ! tt_check $@; then echo "NOTE: You must clone service repositories before creating containers; otherwise, empty root-privilege directories would be created and that's poop." @@ -282,7 +275,7 @@ tt_restart() { tt_upgrade() { local tmpdir=$(mktemp -d) git clone git@github.com:meet-tarantino/tarantino.git $tmpdir || return 1 - sudo echo About to launch installation. Please wait for confirmation that install is complete. + sudo echo "About to launch installation. Please wait for confirmation that install is complete." sudo bash -c "cd $tmpdir; sleep 1s; make install" & } diff --git a/tt_completion b/tt_completion index 4d3c4bc..84b2568 100755 --- a/tt_completion +++ b/tt_completion @@ -1,9 +1,12 @@ #!/usr/bin/env bash -COMMANDS="api browse check clone create data destroy grafana kue install ip logs manage npm_reinstall pull rabbit recreate restart upgrade usage" -DATA_COMMANDS="aray ongoing" +BASE_COMMANDS="browse check clone create dc destroy install ip manage pull recreate restart upgrade usage workspace" MANAGE_COMMANDS="build pull push usage" -SAMPLE_DATA=${TT_PROJECTS:-~/projects}/sample-data +WORKSPACE_COMMANDS="init add rm ls use current upgrade" + +tarantino() { + tt $@ +} tt_complete() { local word='' @@ -39,33 +42,26 @@ tt_complete() { case "$cmd" in tt|"") completion_base $word ;; - data) - completion_data $word ;; manage) completion_manage $word ;; - create) + create|browse) completion_all_services $word ;; - destroy|recreate|ip|browse) + destroy|recreate|ip) completion_running_services $word ;; pull|clone|check) completion_services $word ;; + workspace) + completion_workspace $word;; esac fi } completion_base() { - echo "$COMMANDS" + echo "$BASE_COMMANDS" } -completion_data() { - echo "$DATA_COMMANDS" - if ! hash jq; then - return 0 - fi - if [ ! -d "$SAMPLE_DATA" ]; then - return 0 - fi - tt sample_data_scripts 2> /dev/null +completion_workspace() { + echo "$WORKSPACE_COMMANDS" } completion_manage() { @@ -73,11 +69,11 @@ completion_manage() { } completion_all_services() { - tt get_all_services 2> /dev/null + tarantino get_all_services 2> /dev/null } completion_services() { - tt get_services 2> /dev/null + tarantino get_services 2> /dev/null } completion_running_services() { @@ -85,7 +81,7 @@ completion_running_services() { if [ ! -z "$running_ids" ]; then docker inspect --format \ '{{index .Config.Labels "com.docker.compose.project"}} {{index .Config.Labels "com.docker.compose.service"}}' \ - $running_ids | sed -n 's/^tarantino //p' + $running_ids | sed -n "s/^$(tarantino get_workspace) //p" fi } diff --git a/workspace.sh b/workspace.sh index df6cb87..bbffeba 100755 --- a/workspace.sh +++ b/workspace.sh @@ -10,13 +10,13 @@ ws_usage() { echo echo commands: echo - echo ' init - initialize a new workspace in the current directory' + echo ' init [alias (default is directory name)] - initialize a new workspace in the current directory' echo ' add - register an existing workspace with your user account' echo ' rm - unregister a workspace from your user account' echo ' ls - list registered workspaces ' echo ' use - switch to a different workspace' echo ' current - display the current workspace and directory' - echo ' upgrade [workspace] - fetch latest workspace definition, update docker images' + echo ' upgrade [workspace] - NOT YET IMPLEMENTED: fetch latest workspace definition, update docker images' } ws_add() { @@ -45,6 +45,7 @@ ws_add() { mkdir -p $workspace_root ln -sr $workspace_dir $symlink + echo $alias workspace added } ws_rm() { @@ -83,32 +84,53 @@ ws_use() { return 1 fi ln -snf $TT_HOME/workspaces/$alias $TT_HOME/current + ws_current } ws_current() { - echo $(get_workspace) '->' $(readlink -f "$(get_workspace_dir)") + echo Current Workspace: $(get_workspace) '->' $(readlink -f "$(get_workspace_dir)") } ws_init() { if is_workspace_dir $(pwd); then - local warning='Directory is already a workspace, are you sure you wish to reinitialize? (y/N)? ' - read -n 1 -p "$warning" CONFIRM - if [ "$CONFIRM" = 'y' ]; then - echo - init - fi + echo 'Directory already contains a workspace!' + echo 'to reinitialize: ' + echo ' - remove this first using `tt workspace rm `' + echo ' - delete the contents of the folder' + return 1 else - init + init $@ fi } +ws_upgrade() { + echo workspace upgrade not yet implemented. +} + init() { + alias=$(basename `pwd`) + if [ ! -z $1 ]; then + alias=$1 + fi + + if $(is_workspace $alias); then + echo "Error: a workspace with the name $alias already exists." + return 1 + fi + git init - cp $TT_SHARE/templates/docker-compose.yml . - echo sample docker-compose.yml file created + cp $TT_SHARE/templates/docker-compose-projects.yml . + echo sample docker-compose-projects.yml file created + + cp $TT_SHARE/templates/docker-compose-static.yml . + echo sample docker-compose-static.yml file created + + cp $TT_SHARE/templates/ttvars.sh . + echo sample ttvars.sh created - cp -R $TT_SHARE/templates/grafana . + ws_add $alias `pwd` + ws_use $alias } is_workspace() { @@ -116,7 +138,7 @@ is_workspace() { } is_workspace_dir() { - if [ ! -f $1/docker-compose.yml ]; then + if [ ! -f $1/docker-compose-projects.yml ]; then return 1 fi } @@ -128,3 +150,11 @@ get_workspace_dir() { get_workspace() { basename "$(get_workspace_dir)" } + +apply_workspace_vars() { + varsFile="$(get_workspace_dir)/ttvars.sh" + if [ ! -f $varsFile ]; then + return 0; + fi + source $varsFile +} \ No newline at end of file