Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker support #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__
venv/
.idea/
ssh_unlocker.egg-info/
*~
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3-slim

LABEL maintainer [email protected]

WORKDIR /usr/src/app
VOLUME /usr/src/conf
ENV SSH_UNLOCK_VERBOSE ""

COPY . .
RUN pip3 install .
CMD [ "python", "./unlock.py", "--config", "/usr/src/conf/config.ini"]
19 changes: 19 additions & 0 deletions README.Dockerfile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Building a Docker image
Simply run `./build_docker.sh` with no parameters. It'll create an image called `ssh-unlock:VERSION`
where VERSION is based on specified version of unlocker library.

If first arg is set it will create `$1:ssh-unlock:VERSION` so you can upload it easier to DockerHub if you want to.

# Running a container
At this time this Dockerfile is capable of using file configuration only as `config.ini`, which should be mounted in container's `/usr/src/config` directory.

All private keys or configuration must be in this directory and properly referenced in configuration file `config.ini`. Mind that inside container all these files would be in `/usr/src/config/your_expeted_file`. This means that using `ConfigMap` object it could run easily on Kubernetes.

## Docker run example
`docker run -ti --rm -v $HOME/ssh-unlock/config/:/usr/src/config/ ssh-unlock:0.2`

## Docker run example as daemon
`docker run -d --name ssh-unlock -v $HOME/ssh-unlock/config/:/usr/src/config/ ssh-unlock:0.2`

## See daemon logs
`docker logs -f ssh-unlock`
16 changes: 16 additions & 0 deletions build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

UNLOCK_VERSION=${UNLOCK_VERSION:-$(awk -F \' '{if($1="__version__ ="){print $2;exit}}' unlocker/__init__.py)}

if [ ! -z ${UNLOCK_VERSION} ]
then
echo "[$0] No image version specified not obtained from source. Set UNLOCK_VERSION env var to build this"
exit 1
fi

if [ ! -z $1 ]
then
docker build . -t $1/ssh-unlock:${UNLOCK_VERSION}
else
docker build . -t ssh-unlock:${UNLOCK_VERSION}
fi