Skip to content

Commit a64928d

Browse files
Version already working with actions included
0 parents  commit a64928d

File tree

18 files changed

+451
-0
lines changed

18 files changed

+451
-0
lines changed

.github/workflows/dockerBuild.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Docker image build
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
9+
push_to_registry:
10+
name: Build Docker image and push it to ghcr.io
11+
runs-on: ubuntu-latest
12+
permissions:
13+
packages: write
14+
contents: read
15+
steps:
16+
- name: Check out the repo
17+
uses: actions/checkout@v3
18+
19+
- name: Log in to the Container registry
20+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Build and push
27+
uses: docker/build-push-action@v3
28+
with:
29+
file: app/Dockerfile
30+
context: ./app
31+
push: true
32+
tags: ghcr.io/${{ github.repository }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release Helm chart
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
release_helm_chart:
9+
name: Release Helm Chart
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- name: Check out the repo
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Configure Git
20+
run: |
21+
git config user.name "$GITHUB_ACTOR"
22+
git config user.email "[email protected]"
23+
24+
- name: Install Helm
25+
uses: azure/setup-helm@v1
26+
with:
27+
version: v3.8.1
28+
29+
- name: Run chart-releaser
30+
uses: helm/[email protected]
31+
env:
32+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# webapp-python
2+
![webapp-python](https://github.com/matandomuertos/webapp-python/actions/workflows/dockerBuild.yaml/badge.svg)
3+
![webapp-python-helm](https://github.com/matandomuertos/webapp-python/actions/workflows/helmChartRelease.yaml/badge.svg)
4+
5+
Basic web app made in Python using flask as web framework and psutil and uuid libraries to get system information.
6+
7+
## Running the app
8+
### Setting up locally
9+
1. Clone the repository: `git clone https://github.com/matandomuertos/webapp-python.git`
10+
2. Navigate to the main folder and install requirements: `cd webapp-python/app && pip install -r requirements.txt`
11+
3. Run the app `python main.py`
12+
4. Go to `http://127.0.0.1:8080` in your prefered browser to use the app
13+
14+
### Run the app on Docker
15+
1. [Install Docker](https://docs.docker.com/engine/install/)
16+
2. Run `docker run -p 8080:8080 -d ghcr.io/matandomuertos/webapp-python` in your terminal
17+
3. Go to `http://127.0.0.1:8080` in your prefered browser to use the app
18+
19+
### Run the app on Kubernetes (using helm)
20+
The helm chart is released to [ghcr.io](ghcr.io) automatically by [Github actions](https://github.com/matandomuertos/webapp-python/actions).
21+
22+
1. Add the repo to helm `helm repo add webapp-python https://matandomuertos.github.io/webapp-python`
23+
2. Update the repos `helm repo update`
24+
3. Deploy to k8s `helm install webapp webapp-python/helm`
25+
If you want to customize the deployment, please check the [values file](./charts/webapp/values.yaml).
26+
27+
## Docker image build
28+
The Docker image is build and pushed to [ghcr.io](ghcr.io) automatically by [Github actions](https://github.com/matandomuertos/webapp-python/actions).
29+
30+
### Build image manually
31+
1. Clone the repository: `git clone https://github.com/matandomuertos/webapp-python.git`
32+
2. Navigate to the main folder: `cd webapp-python/app`
33+
3. Build the image: `docker build -t webapp-python .`
34+
35+
## Usage
36+
- `http://127.0.0.1:8080/-/health` shows system information.
37+
#### Example
38+
```
39+
{"architecture":"aarch64","health":"healthy","hostname":"webapp-python","mac-address":"01:41:wx:14:00:03","platform":"Linux","platform-release":"5.10.104-linuxkit","platform-version":"#1 SMP PREEMPT Thu Mar 17 17:05:54 UTC 2022","processor":"","ram":"12 GB"}
40+
```
41+
- `http://127.0.0.1:8080/api/echo?text=hello` shows the input text as key.
42+
#### Example
43+
```
44+
{"key":"hello"}
45+
```

app/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.10-alpine
2+
3+
COPY ./requirements.txt /app/requirements.txt
4+
5+
WORKDIR /app
6+
7+
RUN apk add build-base linux-headers
8+
9+
RUN pip install -r requirements.txt
10+
11+
COPY . /app
12+
13+
ENTRYPOINT [ "python" ]
14+
15+
CMD ["main.py" ]

app/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from website import create_app
2+
3+
app = create_app()
4+
5+
if __name__ == '__main__':
6+
app.run(host='0.0.0.0', port=8080)

app/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flask==2.2.2
2+
psutil==5.9.1
3+
uuid==1.30

app/website/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from flask import Flask
2+
3+
def create_app():
4+
app = Flask(__name__)
5+
app.config['SECRET_KEY'] = '\x11\xa0\x96\xb3\xc7U/\x87\xbc\xc3'
6+
7+
from .pages import pages
8+
9+
app.register_blueprint(pages, url_prefix='/')
10+
11+
return app
481 Bytes
Binary file not shown.
1.35 KB
Binary file not shown.
1.35 KB
Binary file not shown.

0 commit comments

Comments
 (0)