Skip to content

Commit

Permalink
Add docker to getting started (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-treebeard authored Jun 10, 2021
1 parent a957cf5 commit 9bc3eaf
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 176 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ jobs:
password = ${{ secrets.TEST_PYPI_TOKEN }}
EOM
- run: poetry run twine upload --repository pypi dist/*

docker:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- run: docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }}
- run: docker build . -t "hlambdas/human-lambdas:${GITHUB_REF:10}"
- run: docker push "hlambdas/human-lambdas:${GITHUB_REF:10}"
- run: docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }}
- run: docker tag "hlambdas/human-lambdas:latest" "hlambdas/human-lambdas:${GITHUB_REF:10}" # e.g. :v1.0.44
- run: docker tag "hlambdas/human-lambdas:latest" "hlambdas/human-lambdas:${GITHUB_REF:10:12}" # e.g. :v1
- run: docker push -a "hlambdas/human-lambdas"
17 changes: 6 additions & 11 deletions .github/workflows/test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
- run: |
export LDFLAGS='-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib'
make
- run: |
export LDFLAGS='-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib'
pip install dist/*whl
- run: hl initdb # check package installs and run
- uses: pre-commit/action@v2.0.0
with:
extra_args: --verbose --all-files
Expand All @@ -28,15 +32,6 @@ jobs:
password = ${{ secrets.TEST_PYPI_TOKEN }}
EOM
- run: poetry run twine upload --repository testpypi dist/*
- run: |
export LDFLAGS='-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib'
pip install dist/*whl
- run: hl initdb # check package installs and run

docker:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- run: docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }}
- run: docker build . -t "hlambdas/human-lambdas:$GITHUB_SHA"
- run: docker push "hlambdas/human-lambdas:$GITHUB_SHA"
- run: docker tag "hlambdas/human-lambdas:latest" "hlambdas/human-lambdas:$GITHUB_SHA"
- run: docker push "hlambdas/human-lambdas:$GITHUB_SHA"
18 changes: 5 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
FROM python:3

ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code
COPY pyproject.toml /code/
COPY poetry.lock /code/
RUN pip install poetry && poetry config virtualenvs.create false
RUN poetry install

COPY . /code/
RUN poetry install
FROM python:3.8

# requires poetry build before docker build
COPY dist/human_lambdas*whl human-lambdas-0.0.0-py3-none-any.whl
RUN pip install human-lambdas-0.0.0-py3-none-any.whl
EXPOSE 8000
ENTRYPOINT [ "human-lambdas" ]
ENTRYPOINT "bash"
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
buildimg: buildpy
docker build . -t hlambdas/human-lambdas:latest
buildpy: buildweb
poetry install
poetry build
Expand Down
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ It is designed to provide an **all-in-one solution to build, operate and monitor

We are going to run Human Lambdas on a developer device.

Please ensure you have Python 3 installed on a Mac or Linux environment then run the following.
Please ensure you have Docker installed.

```sh
export LDFLAGS='-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib' # for psycopg2 on OS X
pip install human-lambdas
mkdir .human_lambdas # create data directory

docker run \
-p 8000:8000 \
-it \
--rm \
-v $(pwd)/.human_lambdas:/.human_lambdas \
hlambdas/human-lambdas:v1
```

Now initialize a sqlite database in a local `.human_lambdas` directory.
A shell should eventually start inside the container.

Now initialize a sqlite database in your .human_lambdas dir

```sh
human-lambdas initdb
Expand Down Expand Up @@ -86,12 +94,7 @@ export POSTGRES_PASSWORD=some_password

docker run \
-p 8000:8000 \
-e "POSTGRES_HOST=$POSTGRES_HOST" \
-e "POSTGRES_PORT=$POSTGRES_PORT" \
-e "POSTGRES_USER=$POSTGRES_USER" \
-e "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" \
-e "POSTGRES_DB=$POSTGRES_DB" \
--entrypoint=bash \
-v $(pwd)/.human_lambdas:/.human_lambdas \
hlambdas/human-lambdas:latest \
-c 'hl initdb && hl up'
```
Expand All @@ -101,4 +104,12 @@ Human Lambdas is now available on localhost:8000.
This approach lets you use Human Lambdas in stateless environments such as Google Cloud Run as long as

1. You do not run `initdb` on startup, as it is not thread-safe
2. You set a single `SECRET_KEY` environment variable so that all Django Invite/Session tokens work
2. You set a single `SECRET_KEY` environment variable so that all Django Invite/Session tokens work

## Directly install Python Package

Requires Python 3.

```sh
pip install human-lambdas
```
Loading

0 comments on commit 9bc3eaf

Please sign in to comment.