This is an sample microservice written in Sinatra, intended to be used as part of 2hog's Docker trainings.
It implements a single endpoint (POST /
), which:
- Requires basic authentication
- Returns a JSON response with a greeting
paris@docker-training-samples-micro-sinatra:/mnt/project$ curl -X POST -d '' -u paris:kasidiaris localhost:4567
{"greeting":"Chào"}
The Sinatra Sample Microservice accepts configuration via environment variables:
AUTH_USER
: The username to use for Basic Authentication (default:paris
)AUTH_PASSWORD
: The password to use for Basic Authentication (default:kasidiaris
)
The Sinatra Sample Microservice also accepts and prefers configuration for AUTH_USER
and AUTH_PASSWORD
as secret files:
/run/secrets/auth_user
: The username to use for Basic Authentication/run/secrets/auth_password
: The password to use for Basic Authentication
docker run -d \
-e AUTH_USER=paris -e AUTH_PASSWORD=kasidiaris \
-p 4567 \
2hog/docker-training-samples-micro-sinatra
docker secret create micro-sinatra-auth-user -
docker secret create micro-sinatra-auth-password -
docker stack deploy -c docker-compose.yml docker-training-samples-micro-sinatra
kubectl create secret generic docker-training-samples-micro-sinatra-secret \
--from-literal=auth_user=paris \
--from-literal=auth_password=kasidiaris
kubectl apply -f kube/
To develop the Sinatra Sample Microservice, follow these steps:
- Install Docker (docs) and Docker Compose (docs)
- Clone this repository:
git clone https://github.com/2hog/docker-training-samples-micro-sinatra
- Launch the app with Docker Compose:
docker-compose up
- Open your repository with your editor and rock n' roll!
This software is MIT licensed.