Skip to content

Commit

Permalink
Add example and more README contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Michionlion committed Jun 20, 2023
1 parent 6fdd61c commit 4ffa1aa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ MicroWrap functions as an executable wrapper, abstracting the complexities of ne

The base container image MicroWrap defines should be used as the base image for a further Dockerfile build, which can specify mounting locations, compile or upload the executable to be wrapped, and configure MicroWrap. An example container image using MicroWrap to run a version service is defined in this repository at `example/Dockerfile`.

## Usage

To make your application a containerized service, you will need to write a Dockerfile that builds an image. This image can then be used in many different containerized environments, such as Docker, OpenShift, Kubernetes, and others. The Dockerfile for your application needs to accomplish two tasks: allow execution of your program, and configure MicroWrap. To allow your program to execute, the Dockerfile should install dependencies that your program needs, compile your program, and configure the runtime environment so that your program can execute. Additionally, you may want to prepare mount points for any folders that may need to be accessed by your program for external reading/writing, in the case that such input/output is needed.

## Configuration

1. **Executable Path** This is the location of the executable file that will be executed per request. It should be an executable file in your image.
2. **Max Active Requests** This is the number of wrapped-executable invocations to allow at one time; any requests beyond this number will be queued for future invocation. Specify `-1` for no limit.
3. **Allowed Parameters** This is a list of URL parameters that will be passed through as command-line options to the wrapped executable. Any other parameters will be ignored.
4. **Default Parameters** This is an object which is mapped to `--attribute value` strings passed to the wrapped executable that can be overridden by URL parameters. values that are `true` and `false` will not map to `"true"` or `"false"`, but instead value-less `--flag` and `--no-flag` (for an attribute named `flag`) strings; values that are `null` or the empty string `""` will cause the parameter to be ignored.
4. **Default Parameters** This is an object which is mapped to `--attribute value` strings passed to the wrapped executable that can be overridden by URL parameters. Values that are `true` and `false` will not map to `"true"` or `"false"`, but instead value-less `--flag` and `--no-flag` (for an attribute named `flag`) strings; values that are `null` or the empty string `""` will cause the parameter to be ignored.

These configuration parameters should be specified in the `/microwrap.json` configuration file in your image:

Expand Down
15 changes: 15 additions & 0 deletions example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Build the service executable in a "development" container
FROM alpine:3.18 as build

RUN apk add --no-cache openjdk11
COPY Version.java /Version.java
RUN javac Version.java

# Create a new image with microwrap as the base to serve as our runtime image
FROM michionlion/microwrap:0.1
# Install runtime dependency
RUN apk add --no-cache openjre11
# Configure microwrap
COPY microwrap.json /microwrap.json
# Copy the executable from the build image
COPY --from=build /Version.class /Version.class
11 changes: 11 additions & 0 deletions example/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package example;

public class Version {
public static void main(String[] args) {
var VERSION = "1.0.0";
if (String.join(" ", args).contains("--include-build")) {
VERSION += "-b4";
}
System.out.println(VERSION);
}
}
16 changes: 11 additions & 5 deletions example/version.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/sh

VERSION="1.0.0"
USE_JAVA=true

if [ "$1" == "--include-build" ]; then
VERSION="$VERSION-b4"
fi
if [ "$USE_JAVA" == "true" ]; then
java Version.class
else
VERSION="1.0.0"

if [ "$1" == "--include-build" ]; then
VERSION="$VERSION-b4"
fi

echo "$VERSION"
echo "$VERSION"
fi

0 comments on commit 4ffa1aa

Please sign in to comment.