diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-10-20 21:55:01 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-10-20 22:01:26 +0200 |
commit | 989edff55111db3b457c9e04f3abf296e6ac555c (patch) | |
tree | eb9bf0b99b7ed10a05c90a597d57e5c0e543c36d | |
parent | a6ad0dd211ba4a394d70dd13d3375118b6e5f27a (diff) | |
download | app.sh-989edff55111db3b457c9e04f3abf296e6ac555c.tar.gz app.sh-989edff55111db3b457c9e04f3abf296e6ac555c.tar.bz2 app.sh-989edff55111db3b457c9e04f3abf296e6ac555c.tar.xz app.sh-989edff55111db3b457c9e04f3abf296e6ac555c.zip |
o Getting "upgrade" to work with non-SNAPSHOT versions too.
o Removing maven.version.
o Documenting(!) the different configuration keys and what they mean.
-rwxr-xr-x | bin/app-init | 2 | ||||
-rwxr-xr-x | bin/app-upgrade | 20 | ||||
-rw-r--r-- | docs/app.txt | 83 | ||||
-rwxr-xr-x | libexec/app-resolver-maven | 8 | ||||
-rwxr-xr-x | libexec/app-set-version | 2 | ||||
-rwxr-xr-x | test/app-init.bats | 18 | ||||
-rwxr-xr-x | test/app-upgrade.bats | 27 | ||||
-rw-r--r-- | test/utils.bash | 5 |
8 files changed, 141 insertions, 24 deletions
diff --git a/bin/app-init b/bin/app-init index 8e571e8..7098cb3 100755 --- a/bin/app-init +++ b/bin/app-init @@ -66,7 +66,7 @@ resolved_version=`app-conf get app.resolved_version` if [[ $resolved_version == "" ]] then echo "Unable to resolve version" 2>&1 - exit + exit 1 fi echo "Resolved version to $resolved_version" diff --git a/bin/app-upgrade b/bin/app-upgrade index c6cd414..3c5f8dc 100755 --- a/bin/app-upgrade +++ b/bin/app-upgrade @@ -22,7 +22,7 @@ assert_is_app resolver_name=`app-conf get app.resolver` resolver=`find_resolver "$resolver_name"` -old_version=`app-conf get app.version` +old_version=`app-conf get app.resolved_version` echo "Resolving version $old_version" "$resolver" resolve-version new_version=`app-conf get app.resolved_version` @@ -35,6 +35,24 @@ fi echo "Resolved version to $new_version" +if [ "$new_version" = "" ] +then + new_version=`app-conf get app.resolved_version` +fi + +if [ "$new_version" = "" ] +then + fatal "app.resolved_version is not set." +fi + +installed_version=`app-conf get app.installed_version` + +if [ "$new_version" = "$installed_version" ] +then + echo "$new_version is already installed" + exit 0 +fi + "$resolver" download-version -v "$new_version" -f .app/latest.zip app-install-file -v "$new_version" -f .app/latest.zip diff --git a/docs/app.txt b/docs/app.txt new file mode 100644 index 0000000..4756ef2 --- /dev/null +++ b/docs/app.txt @@ -0,0 +1,83 @@ +app(1) +====== + +NAME +---- +app - your favorite application manager + + +SYNOPSIS +-------- +[verse] +'app' <options> + +INSTALLING AN APPLICATION +~~~~~~~~~~~~~~~~~~~~~~~~~ + +This resolved and downloads an appliaction from a Maven repository: + + $ app init -d my-app maven org.example:my-app:1.0-SNAPSHOT + +By default it will download from the central repository, but this is +not always what you want. To get it to use another repository give the +`-r` option: + + $ app init -d my-app maven -f http://repo.example.org/snapshots org.example:my-app:1.0-SNAPSHOT + +UPGRADING AN APPLICATION +~~~~~~~~~~~~~~~~~~~~~~~~ + +If your application is configured with the Maven resolver and the +version is a SNAPSHOT version, you can use this to upgrade your +application through a cron job: + + $ app upgrade + +With the resolver will try to resolve `app.version` to the latest +version. If it's change it will automatically download and install the +latest version. + +CHANGING VERSION OF AN APPLICATION +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + $ app conf set app.version 1.0 + $ app sync-version + +`app-sync-version` will first run the resolver to resolve the version +and if that has changed, it will download and install the new version. + +INTERNALS +--------- + +Concepts: + +resolver:: + Something that takes a version and resolves it to a specific + version. Makes it possible to depend on a development version + which is resolved later on. + +Configuration properties: + +`app.version`:: + The unresolved version of the application. Configured when the + application is installed. + +`app.resolved_version`:: + The resolved version of the application. Is updated by the + resolved configured for the project. + +`app.installed_version`:: + The installed version of the application. Is updated by + `app-set-version`. + +TODOs +----- + +* Consider renaming "upgrade" to "refresh". Upgrade is an overloaded + word, in particular since it might mean to download a catalog of + applications instead of actually upgrading it. I'm always confused + if I should use "upgrade" or "update". + +* Find a way to check if an application is running. + +// vim: set ft=asciidoc: diff --git a/libexec/app-resolver-maven b/libexec/app-resolver-maven index 5af7596..25f7242 100755 --- a/libexec/app-resolver-maven +++ b/libexec/app-resolver-maven @@ -84,7 +84,7 @@ download_artifact() { resolve_version() { local group_id=`app-conf get maven.group_id` local artifact_id=`app-conf get maven.artifact_id` - local version=`app-conf get maven.version` + local version=`app-conf get app.version` repo=`app-conf get maven.repo` @@ -131,7 +131,7 @@ resolve_snapshot() { exit 1 fi - app-conf set maven.snapshotVersion "$snapshot_version" + app-conf set maven.snapshot "$snapshot_version" app-conf set app.resolved_version "${version%-SNAPSHOT}-$snapshot_version" } @@ -161,7 +161,7 @@ download_version() { repo=`app-conf get maven.repo` group_id=`app-conf get maven.group_id` artifact_id=`app-conf get maven.artifact_id` - version=`app-conf get maven.version` + version=`app-conf get app.version` group_id_slash=`slash $group_id` base_path=$group_id_slash/$artifact_id/$version @@ -209,7 +209,7 @@ init() { app-conf set maven.group_id "$group_id" app-conf set maven.artifact_id "$artifact_id" - app-conf set maven.version "$version" + app-conf set app.version "$version" } command="$1"; shift diff --git a/libexec/app-set-version b/libexec/app-set-version index 0abb9b8..1b7fd16 100755 --- a/libexec/app-set-version +++ b/libexec/app-set-version @@ -54,4 +54,4 @@ else ln -s versions/$version/root current fi -app-conf set app.version "$version" +app-conf set app.installed_version "$version" diff --git a/test/app-init.bats b/test/app-init.bats index 3f58890..8ffe1b6 100755 --- a/test/app-init.bats +++ b/test/app-init.bats @@ -56,3 +56,21 @@ load utils # Created by post-install is_directory "my-app/logs" } + +@test "Install 1.0-SNAPSHOT, upgrade to 1.0" { + mkzip app-a + install_artifact + app conf -l user set maven.repo "file://$BATS_TMPDIR/repo" + app init -d my-app maven org.example:app-a:1.0-SNAPSHOT + + cd my-app + app conf set app.version 1.0 + + install_artifact 1.0 + app upgrade + cd current + run pwd -P + + match '${lines[0]}' ".*/versions/1.0/root$" + eq '${#lines[*]}' 1 +} diff --git a/test/app-upgrade.bats b/test/app-upgrade.bats index 5d79260..4eef351 100755 --- a/test/app-upgrade.bats +++ b/test/app-upgrade.bats @@ -7,35 +7,34 @@ load utils mkzip app-a install_artifact - app init -d my-app maven -r "$FIXED_REPO_URL" org.example:app-a:1.0-SNAPSHOT; echo_lines - eq '$status' 0 + app init -d my-app maven -r "$FIXED_REPO_URL" org.example:app-a:1.0-SNAPSHOT cd my-app - app conf get maven.version - match '${lines[0]}' "1.0-SNAPSHOT" - maven_version="${lines[0]}" app conf get app.version - match '${lines[0]}' "1.0-.*" + eq '${lines[0]}' "1.0-SNAPSHOT" app_version="${lines[0]}" + describe app_version = $app_version app conf get app.resolved_version match '${lines[0]}' "1.0-.*" - eq '${lines[0]}' "$app_version" resolved_version="${lines[0]}" + describe resolved_version = $resolved_version + + app conf get app.installed_version + match '${lines[0]}' "1.0-.*" + installed_version="${lines[0]}" + describe installed_version = $installed_version - describe maven_version=$maven_version - describe app_version=$app_version - describe resolved_version=$resolved_version + eq '$installed_version' "$resolved_version" install_artifact - app upgrade; echo_lines - eq '$status' 0 + app upgrade app conf get app.resolved_version match '${lines[0]}' "1.0-.*" new_resolved_version="${lines[0]}" - describe new_resolved_version=$new_resolved_version - neq $new_resolved_version $resolved_version + describe new_resolved_version = $new_resolved_version + neq $new_resolved_version $resolved_version } diff --git a/test/utils.bash b/test/utils.bash index 88dd889..f767d90 100644 --- a/test/utils.bash +++ b/test/utils.bash @@ -172,8 +172,7 @@ match() { return 0 fi - echo "Assertion failed: $ex =~ $a" - echo "Expected: $e" - echo "Actual: $a" + echo "Match failed: $ex =~ $regex" + echo "Value: $a" exit 1 } |