Skip to content

Commit

Permalink
added AWS stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelvinrr committed Aug 8, 2024
1 parent 4ff2afb commit 49e84ca
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 13 deletions.
25 changes: 20 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ SHELL ["/bin/bash", "-c"]
# Clone SpiceQL repo instead of copying?
#git clone [email protected]:DOI-USGS/SpiceQL.git /repo

# RUN git clone https://github.com/DOI-USGS/SpiceQL.git /repo --recursive
# RUN echo $(ls /repo)
# RUN chmod -R 755 /repo

RUN mkdir /repo
COPY . /repo
RUN echo $(ls /repo)
Expand All @@ -18,20 +22,31 @@ ENV SSPICE_DEBUG=TRUE
ENV SPICEROOT=/mnt/isis_data
ENV SPICEQL_LOG_LEVEL=TRACE

RUN apt-get update && apt-get install build-essential -y

# CMD ["/bin/bash"]
# RUN /bin/bash -c "source activate spiceql"
RUN mamba env create -f ${SPICEQL_REPO_ROOT}/environment.yml -n spiceql && \
source /opt/conda/etc/profile.d/conda.sh && \
conda init && \
conda activate spiceql && \
conda install -c conda-forge spiceql && \
echo "source activate spiceql" > ~/.bashrc && \
cd ${SPICEQL_REPO_ROOT}/fastapi

# conda install -c conda-forge spiceql && \
echo "source activate spiceql" > ~/.bashrc && \
conda activate spiceql && \
cd $SPICEQL_REPO_ROOT && mkdir -p build && cd build && \
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DSPICEQL_BUILD_TESTS=OFF && \
make install

RUN cd ${SPICEQL_REPO_ROOT}/fastapi
ENV PATH /opt/conda/envs/spiceql/bin:$PATH

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install nginx curl -y
COPY fastapi/config/nginx.conf /etc/nginx/nginx.conf

WORKDIR ${SPICEQL_REPO_ROOT}/fastapi

EXPOSE 8080

ENTRYPOINT [ "uvicorn", "app.main:app", "--reload", "--port" , "8080" ]
CMD nginx && uvicorn app.main:app --reload --port 8080
7 changes: 1 addition & 6 deletions fastapi/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ class ResponseModel(BaseModel):
# Create FastAPI instance
app = FastAPI()

# General endpoints
@app.get("/", include_in_schema=False)
async def root():
return RedirectResponse(url="/docs")

@app.get("/healthCheck")
@app.get("/")
async def message():
try:
data_dir_exists = os.path.exists(pyspiceql.getDataDirectory())
Expand Down
156 changes: 156 additions & 0 deletions fastapi/aws/aws-stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
AWSTemplateFormatVersion: 2010-09-09
Description: spiceql
Resources:
SpiceQLECSLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
DependsOn: ECSCluster
Properties:
LaunchTemplateData:
ImageId: /aws/service/ecs/optimized-ami/amazon-linux-2/kernel-5.10/recommended/image_id
KeyName: AscEc2DevKey
IamInstanceProfile:
Arn: !Ref 'IamRoleInstanceProfile'
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: '5000'
UserData: !Base64
Fn::Sub:
- "#!/bin/bash \necho ECS_CLUSTER=${ClusterName} >> /etc/ecs/ecs.config;"
- ClusterName: !Ref 'ECSClusterName'
SpiceQLProdLogGroupSlot1:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: spiceql_prod_slot1_log_group
Metadata:
'AWS::CloudFormation::Designer':
id: e9e7c015-1dda-480c-98e4-c4795d48e148
SpiceQLProdTaskDefSlot1:
Type: 'AWS::ECS::TaskDefinition'
Properties:
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: 'arn:aws:iam::950438895271:role/csr-EcsTask-Role'
Cpu: 4096
Memory: 8192
NetworkMode: awsvpc
ContainerDefinitions:
- Name: spiceql_prod_slot1_container
Image: '950438895271.dkr.ecr.us-west-2.amazonaws.com/spiceql:dev'
PortMappings:
- ContainerPort: 80
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: !Ref 'AWS::Region'
awslogs-group: !Ref SpiceQLProdLogGroupSlot1
awslogs-stream-prefix: ecs
Environment:
- Name: SPICEROOT
Value: /isis_data
- Name: SPICEQL_LOG_LEVEL
Value: DEBUG
- Name: SSPICE_DEBUG
Value: TRUE
SpiceQLProdECSClusterSlot1:
Type: 'AWS::ECS::Cluster'
Properties:
ClusterName: spiceqlProdCluster_slot1
ClusterSettings:
- Name: containerInsights
Value: enabled
SpiceQLProdLBSlot1:
Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
Properties:
Name: spiceql-prod-slot1-LB
Scheme: internal
Subnets:
- subnet-0567fccf47f9b29a0
- subnet-0326c18b7c38caa73
Type: application
SecurityGroups:
- !GetAtt SpiceQLProdLBSGSlot1.GroupId
SpiceQLProdTGSlot1:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
Name: spiceql-prod-slot1-TG
VpcId: vpc-004f1e36134bcaa04
Protocol: HTTP
Port: 80
TargetType: ip
HealthCheckPath: /
SpiceQLProdListenerSlot1:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
DefaultActions:
- TargetGroupArn: !Ref SpiceQLProdTGSlot1
Type: forward
LoadBalancerArn: !Ref SpiceQLProdLBSlot1
Port: 443
Protocol: HTTPS
SslPolicy: ELBSecurityPolicy-FS-1-2-Res-2020-10
Certificates:
- CertificateArn: >-
arn:aws:acm:us-west-2:950438895271:certificate/6aa50410-fb5a-4300-888f-55aae14463df
SpiceQLProdLBSGSlot1:
Type: 'AWS::EC2::SecurityGroup'
Properties:
VpcId: vpc-004f1e36134bcaa04
GroupDescription: SG for the Fargate ALB
GroupName: spiceql-prod-slot1-LBSG
SecurityGroupIngress:
- CidrIpv6: '::/0'
FromPort: 80
ToPort: 443
IpProtocol: TCP
Description: Inbound rule for IPv6 traffic
- CidrIp: 0.0.0.0/0
FromPort: 80
ToPort: 443
IpProtocol: TCP
Description: Inbound rule for IPv4 traffic
SpiceQLProdContainerSGSlot1:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupName: spiceql_prod_slot1_sg
GroupDescription: Security group for NGINX container
VpcId: vpc-004f1e36134bcaa04
SecurityGroupIngress:
- IpProtocol: -1
SourceSecurityGroupId: !GetAtt SpiceQLProdLBSGSlot1.GroupId
Description: Inbound rule for all traffic
SpiceQLProdDNSSlot1:
Type: 'AWS::Route53::RecordSet'
Properties:
HostedZoneName: prod-asc.chs.usgs.gov.
Name: spiceql-slot1.prod-asc.chs.usgs.gov
Type: A
AliasTarget:
HostedZoneId: !GetAtt SpiceQLProdLBSlot1.CanonicalHostedZoneID
DNSName: !GetAtt SpiceQLProdLBSlot1.DNSName
SpiceQLProdECSServiceSlot1:
Type: 'AWS::ECS::Service'
DependsOn:
- SpiceQLProdListenerSlot1
Properties:
LaunchType: FARGATE
Cluster:
Ref: SpiceQLProdECSClusterSlot1
DesiredCount: 20
TaskDefinition:
Ref: SpiceQLProdTaskDefSlot1
DeploymentConfiguration:
MaximumPercent: 100
MinimumHealthyPercent: 0
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: DISABLED
SecurityGroups:
- !GetAtt SpiceQLProdContainerSGSlot1.GroupId
Subnets:
- subnet-0326c18b7c38caa73
LoadBalancers:
- TargetGroupArn:
Ref: SpiceQLProdTGSlot1
ContainerPort: 80
ContainerName: spiceql_prod_slot1_container
4 changes: 2 additions & 2 deletions fastapi/config/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# [NOTE!] This file should be located at /etc/nginx/

user nginx;
# user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
Expand Down Expand Up @@ -39,7 +39,7 @@ http {
server {
listen 80;
listen [::]:80;
server_name 10.12.69.192; #IP Address of EC2 instance
server_name 127.0.0.1; #IP Address of EC2 instance
root /usr/share/nginx/html;

# Load configuration files for the default server block.
Expand Down

0 comments on commit 49e84ca

Please sign in to comment.