Skip to content

Commit

Permalink
this commit introduces 1.0 of sampo.
Browse files Browse the repository at this point in the history
There are considerable changes from what the MVP had (in order of impact/size of
the change):

- more of a plug-and-play experience for the end user.  sampo now requires a
  folder somewhere that contains: `sampo.sh`, `sampo.conf` and `scripts/`.  This
drastically simplifies deployments in both containers and local instances and
provides a nice workflow:
  - `mkdir -p sampo/scripts`
  - `cp yourscripts/*.sh sampo/scripts`
  - `cp sampo.sh sampo/`
  - `cp sampo.conf sampo/`
- this allows nice portability and a faster deployment.  The user dumps their
  scripts in `scripts/` then updates `sampo.conf` to set their endpoints and the
scripts that they call.  for containers, this can be done by adding them to the
dockerfile, using a volume mount, or config maps in k8s.  This should provide a
lot of flexibility for someone with a lot of scripts to dump them in one spot,
configure them, and test them
- more versatile container deployement on both docker and kubernetes with better
  logging and parity with local deployment
- `build.sh` now deploys local, docker, or k8s variants (`-l`, `-d`, `-k`)
- `build.sh` now cleans up previous deployments `-c`, and runs tests `./build
  -i`
- added debug logging
- more comments in the code
- enhanced some functions
- better portability of some commands like stat

since making this three years ago, I have seen the stars on the repo slowly
increase.  It is surpising to me, but nonetheless, it shows some interest, so I
decided to push the mvp to a better state.

If you are using sampo for something, I would like to hear from you on how you
are using it and what you would like to see from it.

thank you for using sampo.

Signed-off-by: Jacob Salmela <[email protected]>
  • Loading branch information
jacobsalmela committed Mar 11, 2023
1 parent ce4515b commit cf89444
Show file tree
Hide file tree
Showing 468 changed files with 1,152 additions and 709 deletions.
63 changes: 16 additions & 47 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,44 @@
name: Docker
name: build and publish container image

on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master

# Publish `v1.2.3` tags as releases.
tags:
- v*

# Run tests for any PRs.
pull_request:
release:
types:
- published

env:
IMAGE_NAME: sampo
REGISTRY: ghcr.io
IMAGE_NAME: sampo/sampo

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build docker/sampo --file docker/sampo/Dockerfile
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test

runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
packages: write
contents: read

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Build image
run: docker build docker/sampo --file docker/sampo/Dockerfile --tag $IMAGE_NAME
run: docker build ./docker -f ./docker/Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log into GitHub Container Registry
run: echo "${{ secrets.CR_PAT }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Log in to registry
# This is where you will update the personal access token to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Push image to GitHub Container Registry
- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.log
.dockerignore
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[submodule "bats-core"]
path = test/bats-core
path = test/test_helper/bats-core
url = https://github.com/bats-core/bats-core.git
[submodule "bats-file"]
path = test/bats-file
path = test/test_helper/bats-file
url = https://github.com/bats-core/bats-file.git
[submodule "bats-assert"]
path = test/bats-assert
path = test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
[submodule "bats-support"]
path = test/bats-support
path = test/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,30 @@ Content-Type: text/plain
rusty-fork
```

# How It Works

The `sampo` Kubernetes Deployment runs a `sampo` container, which is running a shell script that processes your API calls. Each endpoint can call any arbitrary shell code.
# Running Locally With `socat`

You can run `sampo` directly in your shell, but it works best in Kubernetes.
```bash
./build.sh -l
```

# Details
# Running in Docker

Details can be found on [this blog post](https://jacobsalmela.com/2020/09/15/introducing-sampo-a-bash-api-server-that-runs-your-shell-scripts/).
```bash
./build.sh -d
```

# Developing/testing
# Running in Kubernetes

If you want to test this out yourself, you can. I run it on Kubernetes in Docker for Mac, but the instructions should basically be the same:
```
git clone https://github.com/jacobsalmela/sampo.git
cd sampo/
kubectl create -f sampo/
```bash
./build.sh -k
```

## Testing changes
I use a simple build script to delete my current deployment, re-deploy it, and set up port forwarding (this all assumes local development on Docker for Mac). Then I just run:
```
./build.sh
```
I currently use [`bats-core`](https://github.com/bats-core/bats-core) in the script. It doesn't work all that well, but it's a nice indicator if something is immediately wrong.
# How It Works

- `sampo.sh` listens for incoming requests
- `sampo.conf` is configured to user-defined endpoint that run user-defined shell scripts
- `scripts/` contains all of the user-defined scripts

# Details

Details can be found on [this blog post](https://jacobsalmela.com/2020/09/15/introducing-sampo-a-bash-api-server-that-runs-your-shell-scripts/).
Loading

0 comments on commit cf89444

Please sign in to comment.