Skip to content

Instantly share code, notes, and snippets.

@tmehlinger
Last active March 16, 2017 19:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmehlinger/2bc89dbd63a286aad23bc2f644955932 to your computer and use it in GitHub Desktop.
Save tmehlinger/2bc89dbd63a286aad23bc2f644955932 to your computer and use it in GitHub Desktop.
Salt deployment for DynamoDB local development server
#!/bin/bash
URL=$1
DYNAMODB_PATH=$2
FULL_URL=$(curl -sI $1 | awk '/Location/{gsub(/Location: /, ""); print}')
LATEST_VERSION=$(echo $FULL_URL | cut -d _ -f 3 | sed 's/\..*//')
VERSION_FILE=$2/VERSION
INSTALLED_VERSION=$([[ -f $VERSION_FILE ]] && cat $VERSION_FILE || echo "NOT INSTALLED")
# if we couldn't extract location from headers (i.e., there's a problem with
# the http request) to get the latest version, bail out without producing
# output so we don't indicate there are changes
[[ $LATEST_VERSION = "" ]] && exit 0
# check the versions and if they're different, produce output to satisfy the
# stateful behavior of cmd.run
[[ $INSTALLED_VERSION = $LATEST_VERSION ]] || echo "changed=true comment='new version is available'"
server {
server_name _;
listen 80;
location / {
proxy_pass http://localhost:{{ port }};
}
}
start on (local-filesystems and runlevel [2345])
stop on runlevel [016]
chdir {{ dynamodb_path }}
setuid {{ user }}
setgid {{ group }}
exec java -Djava.library.path=. -jar DynamoDBLocal.jar -port {{ port }}
{% set dynamodb_path = '/opt/dynamodb' %}
{% set url = 'http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.tar.gz' %}
{% set user = 'nobody' %}
{% set group = 'nogroup' %}
{% set port = 8088 %}
java_is_installed:
pkg.installed:
- name: openjdk-7-jre-headless
installed_dynamodb_is_latest:
cmd.script:
- source: salt://dynamodb/files/check_version.sh
- args: {{ url }} {{ dynamodb_path }}
- stateful: True
dynamodb_path_exists:
file.directory:
- name: {{ dynamodb_path }}
- user: {{ user }}
- group: {{ group }}
dynamodb_is_installed:
cmd.wait_script:
- source: salt://dynamodb/files/install.sh
- args: {{ url }} {{ dynamodb_path }}
- cwd: {{ dynamodb_path }}
- require:
- file: dynamodb_path_exists
- pkg: java_is_installed
- watch:
- cmd: installed_dynamodb_is_latest
dynamodb_service_is_configured:
file.managed:
- name: /etc/init/dynamodb.conf
- source: salt://dynamodb/templates/dynamodb.service.jinja
- template: jinja
- context:
dynamodb_path: {{ dynamodb_path }}
user: {{ user }}
group: {{ group }}
port: {{ port }}
- require:
- cmd: dynamodb_is_installed
dynamodb_nginx_vhost_is_configured:
file.managed:
- name: /etc/nginx/conf.d/dynamodb.conf
- source: salt://dynamodb/templates/dynamodb-vhost.conf.jinja
- template: jinja
- context:
port: {{ port }}
- require:
- file: dynamodb_service_is_configured
- pkg: nginx
- watch_in:
- service: nginx
dynamodb_is_running:
service.running:
- name: dynamodb
- enable: true
- watch:
- cmd: dynamodb_is_installed
#!/bin/bash
cd $2
FULL_URL=$(curl -sI $1 | awk '/Location/{gsub(/Location: /, ""); print}')
LATEST_VERSION=$(echo $FULL_URL | cut -d _ -f 3 | sed 's/\..*//')
curl -LO $1
tar xzf dynamodb_local_latest.tar.gz && echo $LATEST_VERSION > VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment