Skip to content

Commit

Permalink
update workflow and readme
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Salmela <me@jacobsalmela.com>
  • Loading branch information
jacobsalmela committed Mar 11, 2023
1 parent cf89444 commit b46574f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
IMAGE_NAME: sampo/sampo

jobs:
push:
build_and_publish_container_image:
runs-on: ubuntu-latest
permissions:
packages: write
Expand All @@ -36,8 +36,12 @@ jobs:
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
# also tag as latest
VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
Expand Down
59 changes: 56 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,72 @@ Content-Type: text/plain
rusty-fork
```

# Running Locally With `socat`
# Running The Pre-built Image

This is a quick way to see how sampo works. Bundled into the image is an example config and several example scripts.

```bash
docker pull ghcr.io/jacobsalmela/sampo/sampo:1.0.0 # get the sampo image
docker run --rm -d --name sampo -p 1042:1042 ghcr.io/jacobsalmela/sampo/sampo:1.0.0 # run a detached container
curl http://localhost:1042/example # see an example shell script being executed from the API call
curl http://localhost:1042 # see a list of endpoints and the functions they call
```
## Customizing

If you are looking into this software, it quickly becomes apparent that you need to be able to drop in your own scripts and make your own endpoints. You can do this by mounting a directory with `sampo.sh`, `sampo.conf`, and a directory named `scripts`, that holds all of the shell scripts you want to use.

```bash
docker pull ghcr.io/jacobsalmela/sampo/sampo:1.0.0
mkdir -p sampo/scripts
# get a copy of the script
curl -o sampo/sampo.sh https://raw.githubusercontent.com/jacobsalmela/sampo/main/docker/sampo/sampo.sh
chmod 755 sampo/sampo.sh
curl -o sampo/sampo.conf https://raw.githubusercontent.com/jacobsalmela/sampo/main/docker/sampo/sampo.conf
chmod 644 sampo/sampo.conf
curl -o sampo/scripts/example.sh https://raw.githubusercontent.com/jacobsalmela/sampo/main/docker/sampo/scripts/example.sh
vim sampo/scripts/example.sh # make changes to the script as you desire
chmod 755 sampo/scripts/example.sh
docker run --rm -d --name sampo -p 1042:1042 -v ${PWD}/sampo:/sampo ghcr.io/jacobsalmela/sampo/sampo:1.0.0 # run a detached container mounting your local files over the example ones bundled in the container image
# make your own scripts/*.sh and add them to sampo.conf for endless possibilities
```

# Running Locally

Sampo also can run directly in your shell with the help of a listener like `socat` or `nc`:

```bash
mkdir -p sampo/scripts
# get a copy of the script
curl -o sampo/sampo.sh https://raw.githubusercontent.com/jacobsalmela/sampo/main/docker/sampo/sampo.sh
chmod 755 sampo/sampo.sh
curl -o sampo/sampo.conf https://raw.githubusercontent.com/jacobsalmela/sampo/main/docker/sampo/sampo.conf
chmod 644 sampo/sampo.conf
curl -o sampo/scripts/example.sh https://raw.githubusercontent.com/jacobsalmela/sampo/main/docker/sampo/scripts/example.sh
vim sampo/scripts/example.sh # make changes to the script as you desire
chmod 755 sampo/scripts/example.sh
# choose one
socat TCP-LISTEN:1042,reuseaddr,pf=ip4,bind=127.0.0.1,fork system:sampo/sampo.sh # socat preferred
netcat -lp 1042 -e sampo/sampo.sh # version that supports '-e, --exec'
# make your own scripts/*.sh and add them to sampo.conf for endless possibilities
```

# Building And Running

You can also create your own image with the scripts bundled in. Clone this repo and use the build script to see how it works.

## Running Locally With `socat`

```bash
./build.sh -l
```

# Running in Docker
## Running in Docker

```bash
./build.sh -d
```

# Running in Kubernetes
## Running in Kubernetes

```bash
./build.sh -k
Expand Down

0 comments on commit b46574f

Please sign in to comment.