Skip to content

Commit

Permalink
Merge pull request #40 from bento-platform/image-perms
Browse files Browse the repository at this point in the history
Image permissions
  • Loading branch information
davidlougheed authored Feb 27, 2023
2 parents beb1453 + 38bbfcf commit 3787ee3
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v3

- name: Run Bento build action
uses: bento-platform/bento_build_action@v0.10.1
uses: bento-platform/bento_build_action@v0.11.0
with:
registry: ghcr.io
registry-username: ${{ github.actor }}
Expand Down
20 changes: 9 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.02.09
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.02.27

# TODO: change USER
USER root
RUN apt-get update -y && \
apt-get install gcc libffi-dev -y && \
rm -rf /var/lib/apt/lists/*

RUN apt install gcc libffi-dev -y

RUN echo "Building DRS in Production Mode";
WORKDIR /drs
RUN mkdir /wes && \
mkdir -p /drs/data/obj && \
mkdir -p /drs/data/db
RUN mkdir /wes

# Install dependencies
COPY requirements.txt requirements.txt
RUN ["pip", "install", "-r", "requirements.txt"]
COPY requirements.txt .
RUN pip install --no-cache-dir gunicorn==20.1.0 -r requirements.txt

# Copy only what's required for a production instance
COPY chord_drs chord_drs
COPY entrypoint.bash .
COPY run.bash .

ENTRYPOINT ["/bin/bash", "./entrypoint.bash"]
CMD ["/bin/bash", "./run.bash"]
4 changes: 0 additions & 4 deletions chord_drs/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import subprocess

from bento_lib.responses import flask_errors
from flask import Flask
Expand Down Expand Up @@ -46,9 +45,6 @@
if not application.config["CHORD_URL"]:
metrics.init_app(application)

if application.config["BENTO_DEBUG"]:
subprocess.run(["git", "config", "--global", "--add", "safe.directory", str(APP_DIR)])

# # debugger section
# Ensure 'debugpy' is installed (via requirements.txt or manually)
DEBUG = os.environ.get("FLASK_DEBUG", "false").strip().lower() in ("true", "1")
Expand Down
2 changes: 1 addition & 1 deletion chord_drs/package.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = chord_drs
version = 0.9.0
version = 0.9.1
authors = Simon Chénard, David Lougheed
author_emails = [email protected], [email protected]
27 changes: 14 additions & 13 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.02.09
FROM ghcr.io/bento-platform/bento_base_image:python-debian-2023.02.27

# TODO: change USER
USER root
RUN apt-get update -y && \
apt-get install libffi-dev -y && \
rm -rf /var/lib/apt/lists/*

RUN apt install libffi-dev -y

RUN echo "Building DRS in Development Mode";
WORKDIR /drs
RUN mkdir /wes && \
mkdir -p /drs/data/obj && \
mkdir -p /drs/data/db;
RUN mkdir /wes

# Install requirements
# Install dependencies
COPY requirements.txt .
RUN pip install debugpy -r requirements.txt
RUN pip install --no-cache-dir debugpy -r requirements.txt

# Copy in just the entrypoint + runner so we have somewhere to start
COPY entrypoint.bash .
COPY run.dev.bash .

# Don't copy anything in - the dev compose file will mount the repo
# Don't copy any code in - the dev compose file will mount the repo

ENTRYPOINT ["/bin/bash", "./entrypoint.dev.bash"]
ENTRYPOINT ["/bin/bash", "./entrypoint.bash"]
CMD ["/bin/bash", "./run.dev.bash"]
21 changes: 10 additions & 11 deletions entrypoint.bash
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/bin/bash

# CWD: /drs
cd /drs || exit

# Create bento_user + home
source /create_service_user.bash

# Make data directories if needed
# TODO: Don't hardcode these; this should be determined by an environment variable
mkdir -p /drs/data/db
mkdir -p /drs/data/obj

export FLASK_APP="chord_drs.app:application"
if [ -z "${INTERNAL_PORT}" ]; then
# Set default internal port to 5000
export INTERNAL_PORT=5000
fi

flask db upgrade
# Fix permissions on /drs
chown -R bento_user:bento_user /drs

# using 1 worker, multiple threads
# see https://stackoverflow.com/questions/38425620/gunicorn-workers-and-threads
gunicorn "${FLASK_APP}" -w 1 --threads $(expr 2 \* $(nproc --all) + 1) -b "0.0.0.0:${INTERNAL_PORT}"
# Drop into bento_user from root and execute the CMD specified for the image
exec gosu bento_user "$@"
18 changes: 18 additions & 0 deletions run.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# CWD: /drs

export FLASK_APP="chord_drs.app:application"
if [[ -z "${INTERNAL_PORT}" ]]; then
# Set default internal port to 5000
export INTERNAL_PORT=5000
fi

flask db upgrade

# using 1 worker, multiple threads
# see https://stackoverflow.com/questions/38425620/gunicorn-workers-and-threads
gunicorn "${FLASK_APP}" \
-w 1 \
--threads $(( 2 * $(nproc --all) + 1)) \
-b "0.0.0.0:${INTERNAL_PORT}"
4 changes: 3 additions & 1 deletion entrypoint.dev.bash → run.dev.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

# CWD: /drs

# Set .gitconfig for development
/set_gitconfig.bash

Expand All @@ -11,7 +13,7 @@ if [ -z "${INTERNAL_PORT}" ]; then
export INTERNAL_PORT=5000
fi

python -m pip install -r requirements.txt
python -m pip install --user -r requirements.txt

flask db upgrade

Expand Down

0 comments on commit 3787ee3

Please sign in to comment.