Skip to content

Commit

Permalink
Merge pull request #40 from cwerner/dockerfile
Browse files Browse the repository at this point in the history
Add a dockerfile for running the streamlit app

Former-commit-id: 397ccd9
  • Loading branch information
cwerner authored Feb 9, 2022
2 parents 820441d + 3a38362 commit bd68f90
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tests
.remove
.vscode
assets

19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# syntax=docker/dockerfile:1.3
FROM ubuntu:latest
EXPOSE 8501
WORKDIR /app
RUN mkdir /usr/src/app
COPY requirements.txt /usr/src/app/
RUN apt-get update && \
apt-get install software-properties-common -y && \
apt-add-repository ppa:ubuntugis/ubuntugis-unstable && \
apt-get update && \
apt-get install git curl python3 python3-pip gdal-bin libgdal-dev -y && \
python3 -m pip install --upgrade pip && \
python3 -m pip install GDAL==3.4.1 && \
python3 -m pip install -r /usr/src/app/requirements.txt
COPY . /usr/src/app
RUN python3 -m pip install -e /usr/src/app
WORKDIR /usr/src/app
ENV PYTHONPATH "/usr/src/app:${PYTHONPATH}"
CMD ["dlsc", "--gui"]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
NAME := cwerner/ldndctools
TAG := $$(git log -1 --pretty=%h)
IMG := ${NAME}:${TAG}
LATEST := ${NAME}:latest

export DOCKER_BUILDKIT := 1
export $(xargs < .env)

build:
@echo ${TAG}
@docker build -t ${IMG} .
@docker tag ${IMG} ${LATEST}

push:
@docker push ${NAME}

run:
@docker run --rm -p 8501:8501 --env-file .env ${LATEST}

login:
@docker log -u ${DOCKER_USER} -p ${DOCKER_PASS}
27 changes: 21 additions & 6 deletions ldndctools/misc/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import boto3
import netCDF4
import xarray as xr
from dotenv import load_dotenv

load_dotenv()

AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")


# from: https://stackoverflow.com/a/54487188/5300574
Expand Down Expand Up @@ -46,9 +52,18 @@ def get_s3_link(
bucket_name: str,
endpoint_url: str = "https://s3.imk-ifu.kit.edu:8082",
) -> str:
session = boto3.Session(profile_name="ifu-s3")
session = boto3.Session(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)

client = session.client(
"s3",
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
endpoint_url=endpoint_url,
)

client = session.client("s3", endpoint_url=endpoint_url)
client.put_object(
Body=buffer,
Bucket=bucket_name,
Expand All @@ -57,8 +72,8 @@ def get_s3_link(
Key=filename,
)

# NOTE: currently not available for NetApp
# download_url = client.presigned_get_object(
# bucket_name, filename)
download_url = f"{endpoint_url}/{bucket_name}/{filename}"
download_url = client.generate_presigned_url(
"get_object", Params={"Bucket": bucket_name, "Key": filename}, ExpiresIn=300
)

return download_url
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ numpy >= 1.21.5
pandas >= 1.3.5
pydantic >= 1.9.0
pygeos >= 0.12.0
python-dotenv >= 0.19.2
questionary >= 1.10.0
rioxarray >= 0.9.1
s3fs >= 0.4.2
Expand Down

0 comments on commit bd68f90

Please sign in to comment.