Skip to content

Commit ee62460

Browse files
added gunicorn dep and delpy gh action
1 parent 4246a19 commit ee62460

10 files changed

Lines changed: 120 additions & 66 deletions

File tree

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
**/__pycache__/
22
**/venv/
3-
**/*.example**
3+
**/*.example**
4+
**/*.log**
5+
**/*.zip**

.github/workflows/camo-purge.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/deploy.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy to Lightsail
2+
3+
permissions:
4+
id-token: write
5+
contents: read
6+
7+
on:
8+
push:
9+
branches:
10+
- master
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Build Docker image
20+
run: docker build -t hawaii-climate-data-api:latest .
21+
22+
- name: Upgrade AWS CLI version and setup lightsailctl
23+
run: |
24+
aws --version
25+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
26+
unzip awscliv2.zip
27+
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update
28+
which aws
29+
aws --version
30+
sudo curl "https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl" -o "/usr/local/bin/lightsailctl"
31+
sudo chmod +x /usr/local/bin/lightsailctl
32+
33+
- name: Configure AWS credentials using OIDC
34+
uses: aws-actions/configure-aws-credentials@v4
35+
with:
36+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_NAME }}
37+
aws-region: ${{ secrets.AWS_REGION }}
38+
39+
- name: Push to Lightsail
40+
run: |
41+
aws lightsail push-container-image \
42+
--service-name hawaii-climate-data-api-container-service \
43+
--label hawaii-climate-data-api \
44+
--image hawaii-climate-data-api:latest
45+
46+
- name: Deploy container to Lightsail
47+
run: |
48+
aws lightsail create-container-service-deployment \
49+
--service-name hawaii-climate-data-api-container-service \
50+
--containers file://containers.json \
51+
--public-endpoint file://endpoint.json \
52+
--region ${{ secrets.AWS_REGION }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ WORKDIR /application
55
COPY application/ ./
66
RUN pip install -r requirements.txt
77

8-
CMD [ "python", "application.py" ]
8+
CMD ["gunicorn", "--chdir", "/application", "application:application", "--bind", "0.0.0.0:5000"]

README.md

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,34 @@ _This project was for an assignment at Washington University's Data Analytics Bo
88

99
## Table of contents
1010

11-
- [Technologies Used](#technologies-used)
12-
- [How to run locally](#how-to-run-locally)
13-
- [Run on Windows](#run-on-windows)
14-
- [Run on Docker](#run-on-docker)
15-
- [Screenshots](#screenshots)
16-
- [API](#Climate-API)
17-
- [Desktop](#desktop)
18-
- [Mobile](#mobile)
19-
- [Analysis](#Analysis)
11+
- [Technologies Used](#technologies-used)
12+
- [How to run locally](#how-to-run-locally)
13+
- [Run on Windows](#run-on-windows)
14+
- [Run on Docker](#run-on-docker)
15+
- [Screenshots](#screenshots)
16+
- [API](#climate-api)
17+
- [Desktop](#desktop)
18+
- [Mobile](#mobile)
19+
- [Analysis](#analysis)
2020

2121
## Technologies used
2222

23-
- Python
24-
- HTML
25-
- CSS
26-
- Jupyter Notebook
27-
- Matplotlib
28-
- Pandas
29-
- Flask
30-
- Black
31-
- VS Code
32-
- Docker
23+
- Python
24+
- HTML
25+
- CSS
26+
- Jupyter Notebook
27+
- Matplotlib
28+
- Pandas
29+
- Flask
30+
- Black
31+
- gunicorn
32+
- VS Code
33+
- Docker
3334

3435
## How to run locally
3536

36-
- If you are trying to run this application directly on a Windows OS, you will need to install `Python 3.11`.
37-
- Otherwise, you will need to install Docker so you can run the application through Docker.
37+
- If you are trying to run this application directly on a Windows OS, you will need to install `Python 3.11`. You will also likely have to install Visual Studio and Microsoft C++ Build Tools.
38+
- Alternatively, the recommended way is to install Docker so you can run the application through Docker.
3839

3940
### Run on Windows
4041

@@ -44,55 +45,49 @@ Assumes you are using a modern Windows client OS such as Windows 11 or Windows 1
4445

4546
Open terminal at root of this project then move into application/ directory:
4647

47-
```
48+
```bash
4849
cd application/
4950
```
5051

5152
Create venv folder in application folder using Python 3.11:
5253

53-
```
54+
```bash
5455
python3.11 -m venv venv
5556
```
5657

5758
Activate venv:
5859

59-
```
60+
```bash
6061
source venv/Scripts/activate
6162
```
6263

6364
Install python packages to venv:
6465

65-
```
66+
```bash
6667
pip install -r requirements.txt
6768
```
6869

6970
Start application:
7071

71-
```
72+
```bash
7273
python application.py
7374
```
7475

7576
### Run on Docker
7677

77-
Firstly, confirm that Docker is installed and running. Next confirm that no other application is using port `5000` as port `5000` is needed for the Flask server. If you need to run Flask on an alternative port, you can modify the last line in the `application/application.py` file and the ports in the `docker/docker-compose.yml` file.
78+
Firstly, confirm that Docker is installed and running. Next confirm that no other application is using port `5000` as port `5000` is needed for the Flask server. If you need to run Flask on an alternative port, you can modify the last line in the `application/application.py` file and the ports in the `docker-compose.yml` file.
7879

7980
**It is assumed the user is at the root of this project and is using a UNIX style command line environment when referencing the CLI commands below.**
8081

81-
Open terminal at root of this project then move into docker/ directory:
82-
83-
```
84-
cd docker/
85-
```
86-
8782
Build Docker image and start Docker container:
8883

89-
```
84+
```bash
9085
docker compose up --build
9186
```
9287

93-
Visit: http://localhost:5000 to use the application.
88+
Visit: <http://localhost:5000> to use the application.
9489

95-
# Screenshots
90+
## Screenshots
9691

9792
## Climate API
9893

@@ -174,15 +169,15 @@ Visit: http://localhost:5000 to use the application.
174169

175170
---
176171

177-
## Analysis
172+
### Analysis
178173

179-
### Precipitation summary statistics (within 12 month range)
174+
#### Precipitation summary statistics (within 12 month range)
180175

181176
<img src="presentation/plot1.png" width="900">
182177

183178
<img src="presentation/stats.PNG" width="200">
184179

185-
### Last 12 months of temperature observation data (tobs)
180+
#### Last 12 months of temperature observation data (tobs)
186181

187182
<img src="presentation/plot2.png" width="900">
188183

application/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ blinker==1.6.2
33
click==8.1.7
44
Flask==3.0.0
55
greenlet==3.0.0
6+
gunicorn==23.0.0
67
itsdangerous==2.1.2
78
Jinja2==3.1.6
89
MarkupSafe==2.1.3

containers.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"hawaii-climate-data-api": {
3+
"image": ":hawaii-climate-data-api-container-service.hawaii-climate-data-api.latest",
4+
"ports": {
5+
"5000": "HTTP"
6+
}
7+
}
8+
}

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "3"
2+
3+
services:
4+
hawaii-climate-data-api--container-service:
5+
container_name: hawaii-climate-data-api
6+
build:
7+
context: .
8+
dockerfile: ./Dockerfile
9+
ports:
10+
- 5000:5000

docker/docker-compose.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

endpoint.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"containerName": "hawaii-climate-data-api",
3+
"containerPort": 5000,
4+
"healthCheck": {
5+
"path": "/",
6+
"intervalSeconds": 5,
7+
"timeoutSeconds": 2,
8+
"healthyThreshold": 2,
9+
"unhealthyThreshold": 2
10+
}
11+
}

0 commit comments

Comments
 (0)