-
Notifications
You must be signed in to change notification settings - Fork 1
Feat: improve proof-of-concept app #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1f1b235
c47dcad
08567c3
9a7a26c
802c361
3dc0416
8569888
21dda96
34d3dfc
3578cfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
# | ||
# S3 bucket name is injected by Copilot as an environment variable | ||
# since it was created via copilot storage init --name pems-db, the variable is 'PEMSDB_NAME' | ||
S3_BUCKET_NAME="$PEMSDB_NAME" | ||
S3_FIXTURE_PATH="fixtures.json" | ||
LOCAL_FIXTURE_PATH="fixtures.json" | ||
|
||
echo "Downloading $S3_FIXTURE_PATH from bucket $S3_BUCKET_NAME" | ||
aws s3 cp "s3://${S3_BUCKET_NAME}/${S3_FIXTURE_PATH}" "${LOCAL_FIXTURE_PATH}" | ||
echo "Download complete" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a follow-up, let's look into mounting the bucket as a volume that presents as a readable directory in the container. I assume this is possible with our setup (we do something similar in Azure). This seems good for now 👍 |
||
|
||
# initialize Django | ||
|
||
bin/init.sh | ||
|
||
# effectively reset database by loading downloaded fixtures into the database | ||
echo "Loading data from ${LOCAL_FIXTURE_PATH}" | ||
python manage.py loaddata "${LOCAL_FIXTURE_PATH}" | ||
echo "Data loading complete" | ||
|
||
# start the web server | ||
|
||
nginx | ||
|
||
# start the application server | ||
|
||
python -m gunicorn -c $GUNICORN_CONF pems.wsgi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,21 @@ | |
|
||
# Your service name will be used in naming your resources like log groups, ECS services, etc. | ||
name: streamlit | ||
type: Backend Service | ||
type: Load Balanced Web Service | ||
|
||
# Your service is reachable at "http://streamlit.${COPILOT_SERVICE_DISCOVERY_ENDPOINT}:8501" but is not public. | ||
# Distribute traffic to your service. | ||
http: | ||
# Requests to this path will be forwarded to your service. | ||
# To match all requests you can use the "/" path. | ||
path: "/streamlit" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 😎 |
||
healthcheck: "/streamlit/_stcore/health" | ||
|
||
# Configuration for your containers and service. | ||
image: | ||
# Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/backend-service/#image-build | ||
build: | ||
dockerfile: streamlit_app/Dockerfile | ||
context: . | ||
dockerfile: ../streamlit_app/Dockerfile | ||
context: ../ | ||
# Port exposed through your container to route traffic to it. | ||
port: 8501 | ||
|
||
|
@@ -30,9 +35,8 @@ network: | |
|
||
# Optional fields for more advanced use-cases. | ||
# | ||
#variables: # Pass environment variables as key value pairs. | ||
# LOG_LEVEL: info | ||
|
||
variables: # Pass environment variables as key value pairs. | ||
STREAMLIT_BASE_URL: /streamlit | ||
#secrets: # Pass secrets from AWS Systems Manager (SSM) Parameter Store. | ||
# GITHUB_TOKEN: GITHUB_TOKEN # The key is the name of the environment variable, the value is the name of the SSM parameter. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
Parameters: | ||
App: | ||
Type: String | ||
Description: Your application's name. | ||
Env: | ||
Type: String | ||
Description: The environment name your service, job, or workflow is being deployed to. | ||
Name: | ||
Type: String | ||
Description: Your workload's name. | ||
Resources: | ||
pemsdbBucket: | ||
Metadata: | ||
"aws:copilot:description": "An Amazon S3 bucket to store and retrieve objects for pems-db" | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
VersioningConfiguration: | ||
Status: Enabled | ||
AccessControl: Private | ||
BucketEncryption: | ||
ServerSideEncryptionConfiguration: | ||
- ServerSideEncryptionByDefault: | ||
SSEAlgorithm: AES256 | ||
PublicAccessBlockConfiguration: | ||
BlockPublicAcls: true | ||
BlockPublicPolicy: true | ||
IgnorePublicAcls: true | ||
RestrictPublicBuckets: true | ||
OwnershipControls: | ||
Rules: | ||
- ObjectOwnership: BucketOwnerEnforced | ||
LifecycleConfiguration: | ||
Rules: | ||
- Id: ExpireNonCurrentObjects | ||
Status: Enabled | ||
NoncurrentVersionExpirationInDays: 30 | ||
AbortIncompleteMultipartUpload: | ||
DaysAfterInitiation: 1 | ||
|
||
pemsdbBucketPolicy: | ||
Metadata: | ||
"aws:copilot:description": "A bucket policy to deny unencrypted access to the bucket and its contents" | ||
Type: AWS::S3::BucketPolicy | ||
DeletionPolicy: Retain | ||
Properties: | ||
PolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Sid: ForceHTTPS | ||
Effect: Deny | ||
Principal: "*" | ||
Action: "s3:*" | ||
Resource: | ||
- !Sub ${ pemsdbBucket.Arn}/* | ||
- !Sub ${ pemsdbBucket.Arn} | ||
Condition: | ||
Bool: | ||
"aws:SecureTransport": false | ||
Bucket: !Ref pemsdbBucket | ||
|
||
pemsdbAccessPolicy: | ||
Metadata: | ||
"aws:copilot:description": "An IAM ManagedPolicy for your service to access the pems-db bucket" | ||
Type: AWS::IAM::ManagedPolicy | ||
Properties: | ||
Description: !Sub | ||
- Grants CRUD access to the S3 bucket ${Bucket} | ||
- { Bucket: !Ref pemsdbBucket } | ||
PolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Sid: S3ObjectActions | ||
Effect: Allow | ||
Action: | ||
- s3:GetObject | ||
- s3:PutObject | ||
- s3:PutObjectACL | ||
- s3:PutObjectTagging | ||
- s3:DeleteObject | ||
- s3:RestoreObject | ||
Resource: !Sub ${ pemsdbBucket.Arn}/* | ||
- Sid: S3ListAction | ||
Effect: Allow | ||
Action: s3:ListBucket | ||
Resource: !Sub ${ pemsdbBucket.Arn} | ||
|
||
Outputs: | ||
pemsdbName: | ||
Description: "The name of a user-defined bucket." | ||
Value: !Ref pemsdbBucket | ||
pemsdbAccessPolicy: | ||
Description: "The IAM::ManagedPolicy to attach to the task role" | ||
Value: !Ref pemsdbAccessPolicy |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,37 +10,38 @@ type: Load Balanced Web Service | |
http: | ||
# Requests to this path will be forwarded to your service. | ||
# To match all requests you can use the "/" path. | ||
path: '/' | ||
path: "/" | ||
# You can specify a custom health check path. The default is "/". | ||
healthcheck: '/healthcheck' | ||
healthcheck: "/healthcheck" | ||
|
||
# Configuration for your containers and service. | ||
image: | ||
# Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/#image-build | ||
build: | ||
dockerfile: appcontainer/Dockerfile | ||
context: . | ||
dockerfile: ../appcontainer/Dockerfile | ||
context: ../ | ||
# Port exposed through your container to route traffic to it. | ||
port: 8000 | ||
|
||
cpu: 256 # Number of CPU units for the task. | ||
memory: 512 # Amount of memory in MiB used by the task. | ||
platform: linux/x86_64 # See https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/#platform | ||
count: 1 # Number of tasks that should be running in your service. | ||
exec: true # Enable running commands in your container. | ||
cpu: 256 # Number of CPU units for the task. | ||
memory: 512 # Amount of memory in MiB used by the task. | ||
platform: linux/x86_64 # See https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/#platform | ||
count: 1 # Number of tasks that should be running in your service. | ||
exec: true # Enable running commands in your container. | ||
command: bin/start_aws.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see 👍 |
||
network: | ||
connect: true # Enable Service Connect for intra-environment traffic between services. | ||
|
||
# storage: | ||
# readonly_fs: true # Limit to read-only access to mounted root filesystems. | ||
# readonly_fs: true # Limit to read-only access to mounted root filesystems. | ||
|
||
# Optional fields for more advanced use-cases. | ||
# | ||
#variables: # Pass environment variables as key value pairs. | ||
# LOG_LEVEL: info | ||
variables: # Pass environment variables as key value pairs. | ||
STREAMLIT_URL: /streamlit | ||
|
||
secrets: # Pass secrets from AWS Systems Manager (SSM) Parameter Store. | ||
DJANGO_ALLOWED_HOSTS: /pems/web/DJANGO_ALLOWED_HOSTS # The key is the name of the environment variable, the value is the name of the SSM parameter. | ||
secrets: # Pass secrets from AWS Systems Manager (SSM) Parameter Store. | ||
DJANGO_ALLOWED_HOSTS: /pems/web/DJANGO_ALLOWED_HOSTS # The key is the name of the environment variable, the value is the name of the SSM parameter. | ||
|
||
# You can override any of the values defined above by environment. | ||
#environments: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,16 @@ | |
""" | ||
|
||
from pems import __version__ | ||
from django.conf import settings | ||
|
||
|
||
def pems_version(request): | ||
"""Context processor adds information about the PeMS application's version.""" | ||
|
||
return {"pems_version": __version__} | ||
|
||
|
||
def streamlit(request): | ||
"""Context processor adds Streamlit-related information.""" | ||
|
||
return {"streamlit": {"url": settings.STREAMLIT_URL}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,10 @@ ENV PYTHONPATH="$PYTHONPATH:/$USER/app" | |
|
||
EXPOSE 8501 | ||
|
||
COPY .streamlit .streamlit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this to before |
||
|
||
COPY streamlit_app streamlit_app | ||
|
||
RUN pip install -r streamlit_app/requirements.txt | ||
|
||
ENTRYPOINT ["streamlit", "run", "streamlit_app/main.py", "--server.port=8501", "--server.address=0.0.0.0"] | ||
ENTRYPOINT ["./streamlit_app/entrypoint.sh"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's take a follow-up to add the Buildkit cache mounting feature to these Dockerfiles, for
apt
,pip
, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, I was also thinking that I should add this feature soon 😄