Add Docker support #48

This commit is contained in:
Daniel Grams 2020-12-22 15:09:13 +01:00
parent 0200249fdc
commit 6fad6534de
8 changed files with 128 additions and 2 deletions

25
.dockerignore Normal file
View File

@ -0,0 +1,25 @@
**/__pycache__
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md

32
.github/workflows/docker.yml vendored Normal file
View File

@ -0,0 +1,32 @@
name: Docker
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
main:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: danielgrams/gsevpt:latest
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

16
Dockerfile Normal file
View File

@ -0,0 +1,16 @@
FROM python:3.7-slim-buster
EXPOSE 5000
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
COPY . /app
RUN chmod u+x ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.com/DanielGrams/gsevpt.svg?branch=master)](https://travis-ci.com/DanielGrams/gsevpt) [![Coverage Status](https://coveralls.io/repos/github/DanielGrams/gsevpt/badge.svg?branch=master)](https://coveralls.io/github/DanielGrams/gsevpt?branch=master) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Updates](https://pyup.io/repos/github/DanielGrams/gsevpt/shield.svg)](https://pyup.io/repos/github/DanielGrams/gsevpt/)
Website prototype using Python, Flask and Postgres running on Heroku.
Website prototype using Python, Flask and Postgres.
## Automatic Deployment
@ -28,7 +28,7 @@ psql -c 'create database gsevpt;' -U postgres
export DATABASE_URL="postgresql://postgres@localhost/gsevpt"
pip install -r requirements.txt
flask db upgrade
flask run --host 0.0.0.0
gunicorn --bind 0.0.0.0:5000 project:app
```
## Scheduled/Cron jobs

View File

@ -56,3 +56,23 @@ pybabel extract -F babel.cfg -o messages.pot . && pybabel extract -F babel.cfg -
```sh
pybabel compile -d project/translations
```
## Docker
### Build image
```sh
docker build -t gsevpt:latest .
```
### Run container with existing postgres server
```sh
docker run -p 5000:5000 -e "FLASK_APP=main.py" -e "DATABASE_URL=postgresql://postgres@localhost/gsevpt" "gsevpt:latest"
```
### Compose (including Postgres server)
```sh
docker-compose build && docker-compose up
```

23
docker-compose.yml Normal file
View File

@ -0,0 +1,23 @@
version: "3.9"
services:
db:
image: mdillon/postgis
environment:
- POSTGRES_DB=gsevpt
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pass
web:
build: .
environment:
FLASK_APP: main.py
DATABASE_URL: postgresql://user:pass@db/gsevpt
ports:
- "5000:5000"
environment:
FLASK_APP: main.py
DATABASE_URL: postgresql://user:pass@db/gsevpt
depends_on:
- db

9
entrypoint.sh Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
until flask db upgrade
do
echo "Waiting for postgres server to become available..."
sleep 2
done
gunicorn --bind 0.0.0.0:5000 project:app

1
main.py Normal file
View File

@ -0,0 +1 @@
from project import app # noqa: F401