added docker deployment to app w/ burnettk
This commit is contained in:
parent
05e356e06e
commit
22c44aef8f
|
@ -0,0 +1,22 @@
|
|||
FROM ghcr.io/sartography/python:3.10
|
||||
|
||||
RUN pip install poetry
|
||||
RUN useradd _gunicorn --no-create-home --user-group
|
||||
|
||||
WORKDIR /app
|
||||
COPY pyproject.toml poetry.lock /app/
|
||||
RUN poetry install
|
||||
|
||||
RUN set -xe \
|
||||
&& apt-get remove -y gcc python3-dev libssl-dev \
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean -y \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY . /app/
|
||||
|
||||
# run poetry install again AFTER copying the app into the image
|
||||
# otherwise it does not know what the main app module is
|
||||
RUN poetry install
|
||||
|
||||
CMD ./bin/boot_server_in_docker
|
4
app.py
4
app.py
|
@ -8,6 +8,10 @@ app = Flask(__name__)
|
|||
def load_plugins():
|
||||
print('load the plugins once here?')
|
||||
|
||||
@app.route('/liveness')
|
||||
def status():
|
||||
return Response(json.dumps({"ok": True}), status=200, mimetype='application/json')
|
||||
|
||||
@app.route('/v1/commands')
|
||||
def list_commands():
|
||||
def describe_command(plugin_name, command_name, command):
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function error_handler() {
|
||||
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
||||
exit "$2"
|
||||
}
|
||||
trap 'error_handler ${LINENO} $?' ERR
|
||||
set -o errtrace -o errexit -o nounset -o pipefail
|
||||
|
||||
port="${CONNECTOR_PROXY_STATUS_IM_PORT:-}"
|
||||
if [[ -z "$port" ]]; then
|
||||
port=7003
|
||||
fi
|
||||
|
||||
workers=3
|
||||
|
||||
# THIS MUST BE THE LAST COMMAND!
|
||||
exec poetry run gunicorn --bind "0.0.0.0:$port" --workers="$workers" --timeout 90 --capture-output --access-logfile '-' --log-level debug app:app
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function error_handler() {
|
||||
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
||||
exit "$2"
|
||||
}
|
||||
trap 'error_handler ${LINENO} $?' ERR
|
||||
set -o errtrace -o errexit -o nounset -o pipefail
|
||||
|
||||
if [[ -z "${CONNECTOR_PROXY_STATUS_IM_DOCKER_COMPOSE_PROFILE:-}" ]]; then
|
||||
export CONNECTOR_PROXY_STATUS_IM_DOCKER_COMPOSE_PROFILE=run
|
||||
fi
|
||||
|
||||
additional_args=""
|
||||
if [[ "${RUN_WITH_DAEMON:-}" != "false" ]]; then
|
||||
additional_args="${additional_args} -d"
|
||||
fi
|
||||
|
||||
docker compose --profile "$CONNECTOR_PROXY_STATUS_IM_DOCKER_COMPOSE_PROFILE" build
|
||||
docker compose --profile "$CONNECTOR_PROXY_STATUS_IM_DOCKER_COMPOSE_PROFILE" stop
|
||||
docker compose --profile "$CONNECTOR_PROXY_STATUS_IM_DOCKER_COMPOSE_PROFILE" up --wait $additional_args
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function error_handler() {
|
||||
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
||||
exit "$2"
|
||||
}
|
||||
trap 'error_handler ${LINENO} $?' ERR
|
||||
set -o errtrace -o errexit -o nounset -o pipefail
|
||||
|
||||
if [[ -z "${FLASK_ENV:-}" ]]; then
|
||||
export FLASK_ENV=staging
|
||||
fi
|
||||
|
||||
if [[ -z "${FLASK_SESSION_SECRET_KEY:-}" ]]; then
|
||||
export FLASK_SESSION_SECRET_KEY=staging_super_secret_key_dont_tell_anyone
|
||||
fi
|
||||
|
||||
if [[ -z "${CONNECTOR_PROXY_STATUS_IM_DOCKER_COMPOSE_PROFILE:-}" ]]; then
|
||||
export CONNECTOR_PROXY_STATUS_IMSPIFFWORKFLOW_BACKEND_DOCKER_COMPOSE_PROFILE=run
|
||||
fi
|
||||
|
||||
git pull
|
||||
./bin/build_and_run_with_docker_compose
|
||||
./bin/wait_for_server_to_be_up
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
function error_handler() {
|
||||
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
||||
exit "$2"
|
||||
}
|
||||
trap 'error_handler ${LINENO} $?' ERR
|
||||
set -o errtrace -o errexit -o nounset -o pipefail
|
||||
|
||||
max_attempts="${1:-}"
|
||||
if [[ -z "$max_attempts" ]]; then
|
||||
max_attempts=100
|
||||
fi
|
||||
|
||||
echo "waiting for backend to come up..."
|
||||
attempts=0
|
||||
while [[ "$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:7003/v1.0/status")" != "200" ]]; do
|
||||
if [[ "$attempts" -gt "$max_attempts" ]]; then
|
||||
>&2 echo "ERROR: Server not up after $max_attempts attempts. There is probably a problem"
|
||||
exit 1
|
||||
fi
|
||||
attempts=$(( attempts + 1 ))
|
||||
sleep 1
|
||||
done
|
|
@ -0,0 +1,20 @@
|
|||
version: "3.8"
|
||||
services:
|
||||
connector-proxy-status-im: &connector-proxy-status-im
|
||||
container_name: connector-proxy-status-im
|
||||
profiles:
|
||||
- run
|
||||
build:
|
||||
context: .
|
||||
environment:
|
||||
- FLASK_ENV=${FLASK_ENV:-development}
|
||||
- FLASK_DEBUG=0
|
||||
- FLASK_SESSION_SECRET_KEY=${FLASK_SESSION_SECRET_KEY:-super_secret_key}
|
||||
ports:
|
||||
- "7003:7003"
|
||||
network_mode: host
|
||||
healthcheck:
|
||||
test: curl localhost:7003/liveness --fail
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 20
|
|
@ -90,6 +90,20 @@ Werkzeug = ">=2.2.2"
|
|||
async = ["asgiref (>=3.2)"]
|
||||
dotenv = ["python-dotenv"]
|
||||
|
||||
[[package]]
|
||||
name = "gunicorn"
|
||||
version = "20.1.0"
|
||||
description = "WSGI HTTP Server for UNIX"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.5"
|
||||
|
||||
[package.extras]
|
||||
eventlet = ["eventlet (>=0.24.1)"]
|
||||
gevent = ["gevent (>=1.4.0)"]
|
||||
setproctitle = ["setproctitle"]
|
||||
tornado = ["tornado (>=0.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "3.4"
|
||||
|
@ -208,7 +222,7 @@ urllib3 = "*"
|
|||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "ded9e44a1043bbd1fdb5424ab65ba440d4c457559c54d337075a589e5d96caf1"
|
||||
content-hash = "2e83707e8bd2dc5fa76bbe5f3394f4e6e181c04acb5976e09e8a4898d6761101"
|
||||
|
||||
[metadata.files]
|
||||
certifi = []
|
||||
|
@ -224,6 +238,10 @@ colorama = [
|
|||
connector-bamboohr = []
|
||||
connector-xero = []
|
||||
flask = []
|
||||
gunicorn = [
|
||||
{file = "gunicorn-20.1.0-py3-none-any.whl", hash = "sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e"},
|
||||
{file = "gunicorn-20.1.0.tar.gz", hash = "sha256:e0a968b5ba15f8a328fdfd7ab1fcb5af4470c28aaf7e55df02a99bc13138e6e8"},
|
||||
]
|
||||
idna = []
|
||||
itsdangerous = [
|
||||
{file = "itsdangerous-2.1.2-py3-none-any.whl", hash = "sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44"},
|
||||
|
|
|
@ -10,6 +10,7 @@ Flask = "*"
|
|||
|
||||
connector-xero = {git = "https://github.com/jbirddog/connector-xero", rev = "main"}
|
||||
connector-bamboohr = {git = "https://github.com/jbirddog/connector-bamboohr", rev = "main"}
|
||||
gunicorn = "^20.1.0"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
||||
|
|
Loading…
Reference in New Issue